File tree 3 files changed +43
-3
lines changed
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
49
49
TEST CODE
50
50
**************************************************************************************/
51
51
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
+
52
73
TEST_CASE (" OTAStorage initialisation fails" , " [OTAStorage::init() -> returns false]" )
53
74
{
54
75
Mock<OTAStorage> ota_storage;
Original file line number Diff line number Diff line change 42
42
******************************************************************************/
43
43
44
44
OTALogic::OTALogic ()
45
- : _ota_storage{nullptr }
45
+ : _is_configured{false }
46
+ , _ota_storage{nullptr }
46
47
, _ota_state{OTAState::Init}
47
48
, _ota_error{OTAError::None}
48
49
{
@@ -54,8 +55,24 @@ OTALogic::OTALogic()
54
55
* PUBLIC MEMBER FUNCTIONS
55
56
******************************************************************************/
56
57
58
+ void OTALogic::setOTAStorage (OTAStorage & ota_storage)
59
+ {
60
+ _ota_storage = &ota_storage;
61
+ _is_configured = true ;
62
+ }
63
+
57
64
OTAError OTALogic::update ()
58
65
{
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
+
59
76
OTAState prev_ota_state;
60
77
/* The purpose of this loop is to allow the transition of
61
78
* 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
56
56
StorageWriteFailed = 3 ,
57
57
ChecksumMismatch = 4 ,
58
58
ReceivedDataOverrun = 5 ,
59
- RenameOfTempFileFailed = 6
59
+ RenameOfTempFileFailed = 6 ,
60
+ NoOTAStorageConfigured = 7
60
61
};
61
62
62
63
/* *****************************************************************************
@@ -71,7 +72,7 @@ class OTALogic
71
72
OTALogic ();
72
73
73
74
74
- inline void setOTAStorage (OTAStorage & ota_storage) { _ota_storage = &ota_storage; }
75
+ void setOTAStorage (OTAStorage & ota_storage);
75
76
76
77
77
78
OTAError update ();
@@ -99,6 +100,7 @@ class OTALogic
99
100
crc_t crc32;
100
101
} sOTABinaryData ;
101
102
103
+ bool _is_configured;
102
104
OTAStorage * _ota_storage;
103
105
OTAState _ota_state;
104
106
OTAError _ota_error;
You can’t perform that action at this time.
0 commit comments