@@ -24,6 +24,10 @@ static void init_test_buf(uint8_t *buf, size_t len, uint8_t offset)
24
24
}
25
25
}
26
26
27
+ static void reset_history (void * fixture )
28
+ {
29
+ z_shell_history_purge (& history );
30
+ }
27
31
/**
28
32
* Function tests getting line from history and compares it against expected
29
33
* result.
@@ -54,7 +58,6 @@ static void test_get(bool ok, bool up, uint8_t *exp_buf, uint16_t exp_len)
54
58
/* Test put line to history and get it.
55
59
*
56
60
* Test steps:
57
- * - initialize history.
58
61
* - put line to the history.
59
62
* - read line and verify that it is the one that was put.
60
63
*/
@@ -64,15 +67,11 @@ ZTEST(shell_test, test_history_add_get)
64
67
65
68
init_test_buf (exp_buf , sizeof (exp_buf ), 0 );
66
69
67
- z_shell_history_init (& history );
68
-
69
70
test_get (false, true, NULL , 0 );
70
71
71
72
z_shell_history_put (& history , exp_buf , 20 );
72
73
73
74
test_get (true, true, exp_buf , 20 );
74
-
75
- z_shell_history_purge (& history );
76
75
}
77
76
78
77
/* Test verifies that after purging there is no line in the history. */
@@ -82,19 +81,16 @@ ZTEST(shell_test, test_history_purge)
82
81
83
82
init_test_buf (exp_buf , sizeof (exp_buf ), 0 );
84
83
85
- z_shell_history_init (& history );
86
84
z_shell_history_put (& history , exp_buf , 20 );
87
85
z_shell_history_put (& history , exp_buf , 20 );
88
86
89
87
z_shell_history_purge (& history );
90
-
91
88
test_get (false, true, NULL , 0 );
92
89
}
93
90
94
91
/* Test browsing history.
95
92
*
96
93
* Test steps:
97
- * - initialize history.
98
94
* - put lines 1,2,3 to history.
99
95
* - get in up direction a line and verify that it's the last one added (3).
100
96
* - get next line in up direction and verify that it's line 2.
@@ -116,7 +112,6 @@ ZTEST(shell_test, test_history_get_up_and_down)
116
112
init_test_buf (exp2_buf , sizeof (exp2_buf ), 10 );
117
113
init_test_buf (exp3_buf , sizeof (exp3_buf ), 20 );
118
114
119
- z_shell_history_init (& history );
120
115
z_shell_history_put (& history , exp1_buf , 20 );
121
116
z_shell_history_put (& history , exp2_buf , 15 );
122
117
z_shell_history_put (& history , exp3_buf , 20 );
@@ -129,8 +124,6 @@ ZTEST(shell_test, test_history_get_up_and_down)
129
124
test_get (true, false, exp2_buf , 15 ); /* down - 2 */
130
125
test_get (true, false, exp3_buf , 20 ); /* down - 3 */
131
126
test_get (false, false, NULL , 0 ); /* down - nothing */
132
-
133
- z_shell_history_purge (& history );
134
127
}
135
128
136
129
/* Function for getting maximal buffer size that can be stored in the history */
@@ -141,7 +134,6 @@ static int get_max_buffer_len(void)
141
134
int len = sizeof (buf );
142
135
uint16_t out_len ;
143
136
144
- z_shell_history_init (& history );
145
137
do {
146
138
z_shell_history_put (& history , buf , len );
147
139
out_len = sizeof (out_buf );
@@ -157,7 +149,6 @@ static int get_max_buffer_len(void)
157
149
/* Test verifies that line that cannot fit into history buffer is not stored.
158
150
*
159
151
* Test steps:
160
- * - initialize history.
161
152
* - put buffer that is bigger than history overall capacity.
162
153
* - verify that history is empty.
163
154
* - put short line followed by line that is close to max.
@@ -169,7 +160,6 @@ ZTEST(shell_test, test_too_long_line_not_stored)
169
160
int max_len = get_max_buffer_len ();
170
161
171
162
init_test_buf (exp1_buf , sizeof (exp1_buf ), 0 );
172
- z_shell_history_init (& history );
173
163
174
164
z_shell_history_put (& history , exp1_buf , max_len + 1 );
175
165
@@ -182,15 +172,12 @@ ZTEST(shell_test, test_too_long_line_not_stored)
182
172
/* Test that long entry evicts older entry. */
183
173
test_get (true, true, exp1_buf , max_len - 10 );
184
174
test_get (false, true, NULL , 0 ); /* only one entry */
185
-
186
- z_shell_history_purge (& history );
187
175
}
188
176
189
177
/* Test verifies that same line as the previous one is not stored in the
190
178
* history.
191
179
*
192
180
* Test steps:
193
- * - initialize history.
194
181
* - put same line twice.
195
182
* - verify that only one line is in the history.
196
183
*/
@@ -199,22 +186,18 @@ ZTEST(shell_test, test_no_duplicates_in_a_row)
199
186
uint8_t exp1_buf [HIST_BUF_SIZE ];
200
187
201
188
init_test_buf (exp1_buf , sizeof (exp1_buf ), 0 );
202
- z_shell_history_init (& history );
203
189
204
190
z_shell_history_put (& history , exp1_buf , 20 );
205
191
z_shell_history_put (& history , exp1_buf , 20 );
206
192
207
193
test_get (true, true, exp1_buf , 20 );
208
194
/* only one line stored. */
209
195
test_get (false, true, NULL , 0 );
210
-
211
- z_shell_history_purge (& history );
212
196
}
213
197
214
198
/* Test storing long lines in the history.
215
199
*
216
200
* * Test steps:
217
- * - initialize history.
218
201
* - Put max length line 1 in history.
219
202
* - Verify that it is present.
220
203
* - Put max length line 2 in history.
@@ -233,8 +216,6 @@ ZTEST(shell_test, test_storing_long_buffers)
233
216
init_test_buf (exp2_buf , sizeof (exp2_buf ), 10 );
234
217
init_test_buf (exp3_buf , sizeof (exp3_buf ), 20 );
235
218
236
- z_shell_history_init (& history );
237
-
238
219
z_shell_history_put (& history , exp1_buf , max_len );
239
220
test_get (true, true, exp1_buf , max_len );
240
221
test_get (false, true, NULL , 0 ); /* only one entry */
@@ -246,8 +227,6 @@ ZTEST(shell_test, test_storing_long_buffers)
246
227
z_shell_history_put (& history , exp3_buf , max_len );
247
228
test_get (true, true, exp3_buf , max_len );
248
229
test_get (false, true, NULL , 0 ); /* only one entry */
249
-
250
- z_shell_history_purge (& history );
251
230
}
252
231
253
232
ZTEST (shell_test , test_circle_through_history )
@@ -256,8 +235,6 @@ ZTEST(shell_test, test_circle_through_history)
256
235
uint8_t exp2_buf [HIST_BUF_SIZE ];
257
236
uint8_t exp3_buf [HIST_BUF_SIZE ];
258
237
259
- z_shell_history_init (& history );
260
-
261
238
init_test_buf (exp1_buf , sizeof (exp1_buf ), 0 );
262
239
init_test_buf (exp2_buf , sizeof (exp2_buf ), 10 );
263
240
init_test_buf (exp3_buf , sizeof (exp3_buf ), 20 );
@@ -273,8 +250,6 @@ ZTEST(shell_test, test_circle_through_history)
273
250
test_get (true, true, exp3_buf , 20 ); /* up - 3*/
274
251
test_get (true, true, exp2_buf , 15 ); /* up - 2*/
275
252
test_get (true, true, exp1_buf , 20 ); /* up - 1*/
276
-
277
- z_shell_history_purge (& history );
278
253
}
279
254
280
- ZTEST_SUITE (shell_test , NULL , NULL , NULL , NULL , NULL );
255
+ ZTEST_SUITE (shell_test , NULL , NULL , NULL , reset_history , NULL );
0 commit comments