@@ -79,7 +79,7 @@ _Static_assert(sizeof(app_storage_data_t) <= APP_STORAGE_SIZE,
79
79
80
80
// app_storage.h private
81
81
extern app_storage_t app_storage_real ;
82
- bool app_storage_is_initalized (void );
82
+ int32_t app_storage_is_initalized (void );
83
83
84
84
/* Local prototypes */
85
85
static void test_write_read_from_empty (void * * state __attribute__((unused )));
@@ -88,7 +88,7 @@ static void test_app_style_from_empty(void **state __attribute__((unused)));
88
88
/* Functions */
89
89
static int setup_from_empty (void * * state )
90
90
{
91
- app_storage_init ();
91
+ assert_int_equal ( app_storage_init (), APP_STORAGE_SUCCESS );
92
92
return 0 ;
93
93
}
94
94
@@ -101,23 +101,23 @@ static int teardown(void **state)
101
101
static int setup_from_prepared (void * * state )
102
102
{
103
103
/* Prepare storage */
104
- app_storage_init ();
104
+ assert_int_equal ( app_storage_init (), APP_STORAGE_SUCCESS );
105
105
test_write_read_from_empty (state );
106
106
107
107
/* Reinit storage */
108
- app_storage_init ();
108
+ assert_int_equal ( app_storage_init (), APP_STORAGE_SUCCESS );
109
109
110
110
return 0 ;
111
111
}
112
112
113
113
static int setup_from_prepared_app_style (void * * state )
114
114
{
115
115
/* Prepare storage */
116
- app_storage_init ();
116
+ assert_int_equal ( app_storage_init (), APP_STORAGE_SUCCESS );
117
117
test_app_style_from_empty (state );
118
118
119
119
/* Reinit storage */
120
- app_storage_init ();
120
+ assert_int_equal ( app_storage_init (), APP_STORAGE_SUCCESS );
121
121
return 0 ;
122
122
}
123
123
@@ -135,50 +135,46 @@ static void test_getters_from_empty(void **state __attribute__((unused)))
135
135
/* Test that corruption from empty storage is detected */
136
136
static void test_corrupted_storage_from_empty (void * * state __attribute__((unused )))
137
137
{
138
- assert_true (app_storage_is_initalized ());
139
138
// --- Simulate corrupted header
140
139
app_storage_header_t header = app_storage_real .header ;
141
140
header .data_version += 1 ;
142
141
// Change header with no CRC update
143
142
nvm_write ((void * ) & app_storage_real .header , & header , sizeof (header ));
144
143
// Ensure invalid CRC
145
- assert_false (app_storage_is_initalized ());
144
+ assert_int_equal (app_storage_is_initalized (), APP_STORAGE_ERR_CORRUPTED );
146
145
147
146
// --- Simulate corrupted data
148
147
setup_from_empty (NULL );
149
- assert_true (app_storage_is_initalized ());
150
148
uint8_t buf [20 ] = {0 };
151
149
memset (buf , 0xAA , sizeof (buf ));
152
150
assert_int_equal (app_storage_write (buf , sizeof (buf ), 0 ), sizeof (buf ));
153
151
// Change data with no CRC update
154
152
buf [sizeof (buf ) - 1 ] = 0xAB ;
155
153
nvm_write ((void * ) & app_storage_real .data , buf , sizeof (buf ));
156
154
// Ensure invalid CRC
157
- assert_false (app_storage_is_initalized ());
155
+ assert_int_equal (app_storage_is_initalized (), APP_STORAGE_ERR_CORRUPTED );
158
156
}
159
157
160
158
/* Test that corruption from prepared storage is detected */
161
159
static void test_corrupted_storage_from_prepared (void * * state __attribute__((unused )))
162
160
{
163
- assert_true (app_storage_is_initalized ());
164
161
// --- Simulate corrupted header
165
162
app_storage_header_t header = app_storage_real .header ;
166
163
header .data_version += 1 ;
167
164
// Change header with no CRC update
168
165
nvm_write ((void * ) & app_storage_real .header , & header , sizeof (header ));
169
166
// Ensure invalid CRC
170
- assert_false (app_storage_is_initalized ());
167
+ assert_int_equal (app_storage_is_initalized (), APP_STORAGE_ERR_CORRUPTED );
171
168
172
169
// --- Simulate corrupted data
173
170
setup_from_prepared (NULL );
174
- assert_true (app_storage_is_initalized ());
175
171
uint8_t data [INITIAL_SIZE + ADDITIONALL_SIZE ] = {0 };
176
172
app_storage_read (data , INITIAL_SIZE + ADDITIONALL_SIZE , 0 );
177
173
// Change data with no CRC update
178
174
data [INITIAL_SIZE + ADDITIONALL_SIZE - 1 ]++ ;
179
175
nvm_write ((void * ) & app_storage_real .data , data , INITIAL_SIZE + ADDITIONALL_SIZE );
180
176
// Ensure invalid CRC
181
- assert_false (app_storage_is_initalized ());
177
+ assert_int_equal (app_storage_is_initalized (), APP_STORAGE_ERR_CORRUPTED );
182
178
}
183
179
184
180
/* Read error cases with initially empty storage */
0 commit comments