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