File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed
Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,27 @@ void simulateOTABinaryReception(OTALogic & ota_logic, ota::OTAData const & ota_t
4949 TEST CODE
5050 **************************************************************************************/
5151
52+ TEST_CASE (" No OTA Storage configured" , " [OTALogic-01]" )
53+ {
54+ /* Perform test */
55+ OTALogic ota_logic;
56+
57+ WHEN (" OTALogic::update() is called" )
58+ {
59+ ota_logic.update ();
60+ THEN (" The OTA logic should be in the 'Error' state" )
61+ {
62+ REQUIRE (ota_logic.state () == OTAState::Error);
63+ }
64+ THEN (" The OTA error should be set to OTAError::NoOTAStorageConfigured" )
65+ {
66+ REQUIRE (ota_logic.error () == OTAError::NoOTAStorageConfigured);
67+ }
68+ }
69+ }
70+
71+ /* *************************************************************************************/
72+
5273TEST_CASE (" OTAStorage initialisation fails" , " [OTAStorage::init() -> returns false]" )
5374{
5475 Mock<OTAStorage> ota_storage;
Original file line number Diff line number Diff line change 4242 ******************************************************************************/
4343
4444OTALogic::OTALogic ()
45- : _ota_storage{nullptr }
45+ : _is_configured{false }
46+ , _ota_storage{nullptr }
4647, _ota_state{OTAState::Init}
4748, _ota_error{OTAError::None}
4849{
@@ -54,8 +55,24 @@ OTALogic::OTALogic()
5455 * PUBLIC MEMBER FUNCTIONS
5556 ******************************************************************************/
5657
58+ void OTALogic::setOTAStorage (OTAStorage & ota_storage)
59+ {
60+ _ota_storage = &ota_storage;
61+ _is_configured = true ;
62+ }
63+
5764OTAError OTALogic::update ()
5865{
66+ /* This if clause should never happen. None the less we
67+ * should insure ourselves against this scenario because
68+ * otherwise we'll have a nullptr dereferencing.
69+ */
70+ if (!_is_configured) {
71+ _ota_state = OTAState::Error;
72+ _ota_error = OTAError::NoOTAStorageConfigured;
73+ return _ota_error;
74+ }
75+
5976 OTAState prev_ota_state;
6077 /* The purpose of this loop is to allow the transition of
6178 * more than one state per a singular call of 'update'. If
Original file line number Diff line number Diff line change @@ -56,7 +56,8 @@ enum class OTAError : int
5656 StorageWriteFailed = 3 ,
5757 ChecksumMismatch = 4 ,
5858 ReceivedDataOverrun = 5 ,
59- RenameOfTempFileFailed = 6
59+ RenameOfTempFileFailed = 6 ,
60+ NoOTAStorageConfigured = 7
6061};
6162
6263/* *****************************************************************************
@@ -71,7 +72,7 @@ class OTALogic
7172 OTALogic ();
7273
7374
74- inline void setOTAStorage (OTAStorage & ota_storage) { _ota_storage = &ota_storage; }
75+ void setOTAStorage (OTAStorage & ota_storage);
7576
7677
7778 OTAError update ();
@@ -99,6 +100,7 @@ class OTALogic
99100 crc_t crc32;
100101 } sOTABinaryData ;
101102
103+ bool _is_configured;
102104 OTAStorage * _ota_storage;
103105 OTAState _ota_state;
104106 OTAError _ota_error;
You can’t perform that action at this time.
0 commit comments