|
| 1 | +#include "services/ble/GapPeripheralIntervalDecorator.hpp" |
| 2 | +#include "services/ble/test_doubles/GapPeripheralMock.hpp" |
| 3 | +#include "services/ble/test_doubles/GapPeripheralObserverMock.hpp" |
| 4 | +#include "gmock/gmock.h" |
| 5 | + |
| 6 | +class GapPeripheralIntervalDecoratorTest |
| 7 | + : public testing::Test |
| 8 | +{ |
| 9 | +public: |
| 10 | + testing::StrictMock<services::GapPeripheralMock> gap; |
| 11 | + services::GapPeripheralIntervalDecorator gapPeripheralIntervalDecorator{ gap }; |
| 12 | + testing::StrictMock<services::GapPeripheralObserverMock> gapObserver{ gapPeripheralIntervalDecorator }; |
| 13 | +}; |
| 14 | + |
| 15 | +TEST_F(GapPeripheralIntervalDecoratorTest, use_user_adv_interval) |
| 16 | +{ |
| 17 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 10)); |
| 18 | + gapPeripheralIntervalDecorator.Advertise(services::GapAdvertisementType::advInd, 10); |
| 19 | +} |
| 20 | + |
| 21 | +TEST_F(GapPeripheralIntervalDecoratorTest, use_long_adv_interval) |
| 22 | +{ |
| 23 | + gapPeripheralIntervalDecorator.SwitchToLongInterval(); |
| 24 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 50)); |
| 25 | + gapPeripheralIntervalDecorator.Advertise(services::GapAdvertisementType::advInd, 10); |
| 26 | +} |
| 27 | + |
| 28 | +TEST_F(GapPeripheralIntervalDecoratorTest, switch_to_long_and_back_interval_while_advertise) |
| 29 | +{ |
| 30 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 10)); |
| 31 | + gapPeripheralIntervalDecorator.Advertise(services::GapAdvertisementType::advInd, 10); |
| 32 | + |
| 33 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::advertising)); |
| 34 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::advertising); |
| 35 | + |
| 36 | + EXPECT_CALL(gap, Standby()); |
| 37 | + gapPeripheralIntervalDecorator.SwitchToLongInterval(); |
| 38 | + |
| 39 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::standby)); |
| 40 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 50)); |
| 41 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::standby); |
| 42 | + |
| 43 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::advertising)); |
| 44 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::advertising); |
| 45 | + |
| 46 | + EXPECT_CALL(gap, Standby()); |
| 47 | + gapPeripheralIntervalDecorator.SwitchToUserInterval(); |
| 48 | + |
| 49 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::standby)); |
| 50 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 10)); |
| 51 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::standby); |
| 52 | +} |
| 53 | + |
| 54 | +TEST_F(GapPeripheralIntervalDecoratorTest, requested_standby_will_overwrite_pending_adv) |
| 55 | +{ |
| 56 | + EXPECT_CALL(gap, Advertise(services::GapAdvertisementType::advInd, 10)); |
| 57 | + gapPeripheralIntervalDecorator.Advertise(services::GapAdvertisementType::advInd, 10); |
| 58 | + |
| 59 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::advertising)); |
| 60 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::advertising); |
| 61 | + |
| 62 | + EXPECT_CALL(gap, Standby()); |
| 63 | + gapPeripheralIntervalDecorator.Standby(); |
| 64 | + |
| 65 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::standby)); |
| 66 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::standby); |
| 67 | +} |
| 68 | + |
| 69 | +TEST_F(GapPeripheralIntervalDecoratorTest, use_default_connection_parameter_when_connect) |
| 70 | +{ |
| 71 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::connected)); |
| 72 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 73 | + { |
| 74 | + EXPECT_EQ(connParam.minConnIntMultiplier, 6); |
| 75 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 6); |
| 76 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 77 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 78 | + })); |
| 79 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::connected); |
| 80 | +} |
| 81 | + |
| 82 | +TEST_F(GapPeripheralIntervalDecoratorTest, use_user_connection_parameter_when_connect) |
| 83 | +{ |
| 84 | + services::GapConnectionParameters connParam{ 10, 10, 0, 500 }; |
| 85 | + gapPeripheralIntervalDecorator.SetConnectionParameters(connParam); |
| 86 | + |
| 87 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::connected)); |
| 88 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 89 | + { |
| 90 | + EXPECT_EQ(connParam.minConnIntMultiplier, 10); |
| 91 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 10); |
| 92 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 93 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 94 | + })); |
| 95 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::connected); |
| 96 | +} |
| 97 | + |
| 98 | +TEST_F(GapPeripheralIntervalDecoratorTest, use_long_connection_parameter_when_connect) |
| 99 | +{ |
| 100 | + gapPeripheralIntervalDecorator.SwitchToLongInterval(); |
| 101 | + |
| 102 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::connected)); |
| 103 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 104 | + { |
| 105 | + EXPECT_EQ(connParam.minConnIntMultiplier, 50); |
| 106 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 50); |
| 107 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 108 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 109 | + })); |
| 110 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::connected); |
| 111 | +} |
| 112 | + |
| 113 | +TEST_F(GapPeripheralIntervalDecoratorTest, switch_to_long_connection_interval_and_back) |
| 114 | +{ |
| 115 | + EXPECT_CALL(gapObserver, StateChanged(services::GapState::connected)); |
| 116 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 117 | + { |
| 118 | + EXPECT_EQ(connParam.minConnIntMultiplier, 6); |
| 119 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 6); |
| 120 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 121 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 122 | + })); |
| 123 | + gapPeripheralIntervalDecorator.StateChanged(services::GapState::connected); |
| 124 | + |
| 125 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 126 | + { |
| 127 | + EXPECT_EQ(connParam.minConnIntMultiplier, 50); |
| 128 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 50); |
| 129 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 130 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 131 | + })); |
| 132 | + gapPeripheralIntervalDecorator.SwitchToLongInterval(); |
| 133 | + |
| 134 | + EXPECT_CALL(gap, SetConnectionParameters(testing::_)).WillOnce(testing::Invoke([](const services::GapConnectionParameters& connParam) |
| 135 | + { |
| 136 | + EXPECT_EQ(connParam.minConnIntMultiplier, 6); |
| 137 | + EXPECT_EQ(connParam.maxConnIntMultiplier, 6); |
| 138 | + EXPECT_EQ(connParam.slaveLatency, 0); |
| 139 | + EXPECT_EQ(connParam.supervisorTimeoutMs, 500); |
| 140 | + })); |
| 141 | + gapPeripheralIntervalDecorator.SwitchToUserInterval(); |
| 142 | +} |
0 commit comments