@@ -59,6 +59,7 @@ TEST_CASE("OTAStorage initialisation fails", "[OTAStorage::init() -> returns fal
59
59
Fake (Method (ota_storage, write ));
60
60
Fake (Method (ota_storage, close ));
61
61
Fake (Method (ota_storage, remove ));
62
+ Fake (Method (ota_storage, rename ));
62
63
Fake (Method (ota_storage, deinit));
63
64
64
65
@@ -92,6 +93,7 @@ TEST_CASE("OTAStorage opening of storage file fails", "[OTAStorage::open() -> re
92
93
Fake (Method (ota_storage, write ));
93
94
Fake (Method (ota_storage, close ));
94
95
Fake (Method (ota_storage, remove ));
96
+ Fake (Method (ota_storage, rename ));
95
97
Fake (Method (ota_storage, deinit));
96
98
97
99
@@ -129,6 +131,7 @@ TEST_CASE("OTAStorage writing to storage file fails", "[OTAStorage::write() -> f
129
131
When (Method (ota_storage, write )).AlwaysDo ([](uint8_t const * const /* buf */ , size_t const /* num_bytes */ ) -> size_t { return 0 /* should return num_bytes in case of success */ ;});
130
132
Fake (Method (ota_storage, close ));
131
133
Fake (Method (ota_storage, remove ));
134
+ Fake (Method (ota_storage, rename ));
132
135
Fake (Method (ota_storage, deinit));
133
136
134
137
@@ -165,6 +168,7 @@ TEST_CASE("Data overrun due to receiving too much data", "[OTALogic - Data Overr
165
168
When (Method (ota_storage, write )).AlwaysDo ([](uint8_t const * const /* buf */ , size_t const num_bytes) -> size_t { return num_bytes; });
166
169
Fake (Method (ota_storage, close ));
167
170
Fake (Method (ota_storage, remove ));
171
+ Fake (Method (ota_storage, rename ));
168
172
Fake (Method (ota_storage, deinit));
169
173
170
174
@@ -206,9 +210,10 @@ TEST_CASE("Valid OTA data is received ", "[OTALogic]")
206
210
std::copy (buf, buf + num_bytes, std::back_inserter (ota_binary_data));
207
211
return num_bytes;
208
212
});
209
- Fake (Method (ota_storage, close ));
210
- Fake (Method (ota_storage, remove ));
211
- Fake (Method (ota_storage, deinit));
213
+ Fake (Method (ota_storage, close ));
214
+ Fake (Method (ota_storage, remove ));
215
+ When (Method (ota_storage, rename )).Return (true );
216
+ Fake (Method (ota_storage, deinit));
212
217
213
218
214
219
/* Generate test data */
@@ -231,6 +236,11 @@ TEST_CASE("Valid OTA data is received ", "[OTALogic]")
231
236
valid_ota_test_data.data .bin ));
232
237
}
233
238
239
+ THEN (" The temporary file UPDATE.BIN.TMP should have been renamed to UPDATE.BIN" )
240
+ {
241
+ Verify (Method (ota_storage, rename )).Once ();
242
+ }
243
+
234
244
THEN (" The OTA logic should be in the 'Reset' state" )
235
245
{
236
246
REQUIRE (ota_logic.state () == OTAState::Reset);
@@ -244,6 +254,45 @@ TEST_CASE("Valid OTA data is received ", "[OTALogic]")
244
254
245
255
/* *************************************************************************************/
246
256
257
+ TEST_CASE (" Valid OTA data is received but the rename step failed (identical too device being turned off during writing of file)" , " [OTALogic - Rename fail]" )
258
+ {
259
+ Mock<OTAStorage> ota_storage;
260
+
261
+ /* Configure mock object */
262
+ When (Method (ota_storage, init)).Return (true );
263
+ When (Method (ota_storage, open )).Return (true );
264
+ When (Method (ota_storage, write )).AlwaysDo ([](uint8_t const * const /* buf */ , size_t const num_bytes) -> size_t { return num_bytes; });
265
+ Fake (Method (ota_storage, close ));
266
+ Fake (Method (ota_storage, remove ));
267
+ When (Method (ota_storage, rename )).Return (false );
268
+ Fake (Method (ota_storage, deinit));
269
+
270
+
271
+ /* Generate test data */
272
+ ota::OTAData valid_ota_test_data;
273
+ ota::generate_valid_ota_data (valid_ota_test_data);
274
+
275
+
276
+ /* Perform test */
277
+ OTALogic ota_logic;
278
+ ota_logic.setOTAStorage (ota_storage.get ());
279
+ simulateOTABinaryReception (ota_logic, valid_ota_test_data);
280
+
281
+
282
+ /* Perform checks */
283
+ THEN (" The OTA logic should be in the 'Error' state" )
284
+ {
285
+ REQUIRE (ota_logic.state () == OTAState::Error);
286
+ }
287
+
288
+ THEN (" The OTA error should be set to OTAError::RenameOfTempFileFailed" )
289
+ {
290
+ REQUIRE (ota_logic.error () == OTAError::RenameOfTempFileFailed);
291
+ }
292
+ }
293
+
294
+ /* *************************************************************************************/
295
+
247
296
TEST_CASE (" Invalid OTA data is received " , " [OTALogic - CRC wrong]" )
248
297
{
249
298
Mock<OTAStorage> ota_storage;
@@ -255,6 +304,7 @@ TEST_CASE("Invalid OTA data is received ", "[OTALogic - CRC wrong]")
255
304
When (Method (ota_storage, write )).AlwaysDo ([](uint8_t const * const /* buf */ , size_t const num_bytes) -> size_t { return num_bytes; });
256
305
Fake (Method (ota_storage, close ));
257
306
Fake (Method (ota_storage, remove ));
307
+ Fake (Method (ota_storage, rename ));
258
308
Fake (Method (ota_storage, deinit));
259
309
260
310
@@ -268,7 +318,7 @@ TEST_CASE("Invalid OTA data is received ", "[OTALogic - CRC wrong]")
268
318
ota_logic.setOTAStorage (ota_storage.get ());
269
319
simulateOTABinaryReception (ota_logic, invalid_valid_ota_test_data_crc_wrong);
270
320
271
-
321
+
272
322
/* Perform checks */
273
323
THEN (" there should be no binary file be stored on the OTA storage" )
274
324
{
0 commit comments