@@ -49,7 +49,7 @@ void simulateOTABinaryReception(OTALogic & ota_logic, OTAData const & ota_test_d
49
49
TEST CODE
50
50
**************************************************************************************/
51
51
52
- TEST_CASE (" OTAStorage initialisation fails " , " [OTAStorage::init() -> returns false]" )
52
+ TEST_CASE (" OTAStorage initialisation fails" , " [OTAStorage::init() -> returns false]" )
53
53
{
54
54
Mock<OTAStorage> ota_storage;
55
55
@@ -81,7 +81,7 @@ TEST_CASE("OTAStorage initialisation fails ", "[OTAStorage::init() -> returns fa
81
81
82
82
/* *************************************************************************************/
83
83
84
- TEST_CASE (" OTAStorage opening of storage file fails " , " [OTAStorage::open() -> returns false]" )
84
+ TEST_CASE (" OTAStorage opening of storage file fails" , " [OTAStorage::open() -> returns false]" )
85
85
{
86
86
Mock<OTAStorage> ota_storage;
87
87
@@ -117,7 +117,7 @@ TEST_CASE("OTAStorage opening of storage file fails ", "[OTAStorage::open() -> r
117
117
118
118
/* *************************************************************************************/
119
119
120
- TEST_CASE (" OTAStorage writing to storage file fails " , " [OTAStorage::write() -> fails]" )
120
+ TEST_CASE (" OTAStorage writing to storage file fails" , " [OTAStorage::write() -> fails]" )
121
121
{
122
122
Mock<OTAStorage> ota_storage;
123
123
@@ -152,6 +152,42 @@ TEST_CASE("OTAStorage writing to storage file fails ", "[OTAStorage::write() ->
152
152
153
153
/* *************************************************************************************/
154
154
155
+ TEST_CASE (" Data overrun due to receiving too much data" , " [OTALogic - Data Overrun]" )
156
+ {
157
+ Mock<OTAStorage> ota_storage;
158
+
159
+ /* Configure mock object */
160
+ When (Method (ota_storage, init)).Return (true );
161
+ When (Method (ota_storage, open )).Return (true );
162
+ When (Method (ota_storage, write )).AlwaysDo ([](uint8_t const * const /* buf */ , size_t const num_bytes) -> size_t { return num_bytes; });
163
+ Fake (Method (ota_storage, close ));
164
+ Fake (Method (ota_storage, remove ));
165
+ Fake (Method (ota_storage, deinit));
166
+
167
+
168
+ /* Perform test */
169
+ OTALogic ota_logic (ota_storage.get ());
170
+
171
+ WHEN (" Too much data is received before OTALogic::update() is called again to process the incoming data" )
172
+ {
173
+ uint8_t const SOME_FAKE_DATA[MQTT_OTA_BUF_SIZE] = {0 };
174
+ ota_logic.onOTADataReceived (SOME_FAKE_DATA, MQTT_OTA_BUF_SIZE);
175
+ ota_logic.onOTADataReceived (SOME_FAKE_DATA, MQTT_OTA_BUF_SIZE);
176
+ ota_logic.update ();
177
+
178
+ THEN (" The OTA logic should be in the 'Error' state" )
179
+ {
180
+ REQUIRE (ota_logic.state () == OTAState::Error);
181
+ }
182
+ THEN (" The OTA error should be set to OTAError::ReceivedDataOverrun" )
183
+ {
184
+ REQUIRE (ota_logic.error () == OTAError::ReceivedDataOverrun);
185
+ }
186
+ }
187
+ }
188
+
189
+ /* *************************************************************************************/
190
+
155
191
TEST_CASE (" Valid OTA data is received " , " [OTALogic]" )
156
192
{
157
193
Mock<OTAStorage> ota_storage;
0 commit comments