@@ -222,6 +222,102 @@ void test_fota_module_should_fail_on_cancellation(void)
222222 event_expect (FOTA_DOWNLOAD_CANCELED );
223223}
224224
225+ void test_fota_module_should_fail_on_rejection (void )
226+ {
227+ /* Given */
228+ nrf_cloud_fota_poll_process_fake .return_val = 0 ;
229+
230+ /* 1. Poll for update */
231+ event_send (FOTA_POLL_REQUEST );
232+ event_expect (FOTA_POLL_REQUEST );
233+
234+ /* 2. Downloading update */
235+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_DOWNLOADING );
236+ event_expect (FOTA_DOWNLOADING_UPDATE );
237+
238+ /* 3. Download rejected */
239+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_REJECTED );
240+ event_expect (FOTA_DOWNLOAD_REJECTED );
241+ }
242+
243+ void test_fota_module_should_restart_after_cancellation (void )
244+ {
245+ /* Given */
246+ nrf_cloud_fota_poll_process_fake .return_val = 0 ;
247+ nrf_cloud_fota_poll_update_apply_fake .return_val = 0 ;
248+
249+ /* 1. Poll for first update */
250+ event_send (FOTA_POLL_REQUEST );
251+ event_expect (FOTA_POLL_REQUEST );
252+
253+ /* 2. Downloading update */
254+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_DOWNLOADING );
255+ event_expect (FOTA_DOWNLOADING_UPDATE );
256+
257+ /* 3. Download canceled */
258+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_CANCELED );
259+ event_expect (FOTA_DOWNLOAD_CANCELED );
260+
261+ /* 4. Poll for second update - should work after cancellation */
262+ event_send (FOTA_POLL_REQUEST );
263+ event_expect (FOTA_POLL_REQUEST );
264+
265+ /* 5. Downloading second update */
266+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_DOWNLOADING );
267+ event_expect (FOTA_DOWNLOADING_UPDATE );
268+
269+ /* 6. Download succeeded, validation needed */
270+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_FMFU_VALIDATION_NEEDED );
271+ event_expect (FOTA_IMAGE_APPLY_NEEDED );
272+
273+ /* 7. Apply image */
274+ event_send (FOTA_IMAGE_APPLY );
275+ event_expect (FOTA_IMAGE_APPLY );
276+
277+ /* 8. Reboot needed */
278+ invoke_nrf_cloud_fota_callback_stub_reboot (FOTA_REBOOT_SUCCESS );
279+ event_expect (FOTA_SUCCESS_REBOOT_NEEDED );
280+ }
281+
282+ void test_fota_module_should_restart_after_rejection (void )
283+ {
284+ /* Given */
285+ nrf_cloud_fota_poll_process_fake .return_val = 0 ;
286+ nrf_cloud_fota_poll_update_apply_fake .return_val = 0 ;
287+
288+ /* 1. Poll for first update */
289+ event_send (FOTA_POLL_REQUEST );
290+ event_expect (FOTA_POLL_REQUEST );
291+
292+ /* 2. Downloading update */
293+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_DOWNLOADING );
294+ event_expect (FOTA_DOWNLOADING_UPDATE );
295+
296+ /* 3. Download rejected */
297+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_REJECTED );
298+ event_expect (FOTA_DOWNLOAD_REJECTED );
299+
300+ /* 4. Poll for second update - should work after rejection */
301+ event_send (FOTA_POLL_REQUEST );
302+ event_expect (FOTA_POLL_REQUEST );
303+
304+ /* 5. Downloading second update */
305+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_DOWNLOADING );
306+ event_expect (FOTA_DOWNLOADING_UPDATE );
307+
308+ /* 6. Download succeeded, validation needed */
309+ invoke_nrf_cloud_fota_callback_stub_status (NRF_CLOUD_FOTA_FMFU_VALIDATION_NEEDED );
310+ event_expect (FOTA_IMAGE_APPLY_NEEDED );
311+
312+ /* 7. Apply image */
313+ event_send (FOTA_IMAGE_APPLY );
314+ event_expect (FOTA_IMAGE_APPLY );
315+
316+ /* 8. Reboot needed */
317+ invoke_nrf_cloud_fota_callback_stub_reboot (FOTA_REBOOT_SUCCESS );
318+ event_expect (FOTA_SUCCESS_REBOOT_NEEDED );
319+ }
320+
225321/* This is required to be added to each test. That is because unity's
226322 * main may return nonzero, while zephyr's main currently must
227323 * return 0 in all cases (other values are reserved).
0 commit comments