MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_parse_string_valid

Function test_parse_string_valid

dpdk/app/test/test_cmdline_string.c:282–370  ·  view source on GitHub ↗

test valid parameters and data */

Source from the content-addressed store, hash-verified

280
281/* test valid parameters and data */
282int
283test_parse_string_valid(void)
284{
285 cmdline_parse_token_string_t token;
286 cmdline_parse_token_string_t help_token;
287 char buf[CMDLINE_TEST_BUFSIZE];
288 char help_str[CMDLINE_TEST_BUFSIZE];
289 unsigned i;
290
291 /* test parsing strings */
292 for (i = 0; i < RTE_DIM(string_parse_strs); i++) {
293 memset(&token, 0, sizeof(token));
294 memset(buf, 0, sizeof(buf));
295
296 token.string_data.str = string_parse_strs[i].fixed_str;
297
298 if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token,
299 string_parse_strs[i].str, (void*)buf,
300 sizeof(buf)) < 0) {
301
302 /* clean help data */
303 memset(&help_token, 0, sizeof(help_token));
304 memset(help_str, 0, sizeof(help_str));
305
306 /* prepare help token */
307 help_token.string_data.str = string_parse_strs[i].fixed_str;
308
309 /* get help string so that we get an informative error message */
310 cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str,
311 sizeof(help_str));
312
313 printf("Error: parsing %s as %s failed!\n",
314 string_parse_strs[i].str, help_str);
315 return -1;
316 }
317 if (strcmp(buf, string_parse_strs[i].result) != 0) {
318 printf("Error: result mismatch!\n");
319 return -1;
320 }
321 }
322
323 /* get number of string tokens and verify it's correct */
324 for (i = 0; i < RTE_DIM(string_nb_strs); i++) {
325 memset(&token, 0, sizeof(token));
326
327 token.string_data.str = string_nb_strs[i].str;
328
329 if (cmdline_complete_get_nb_string(
330 (cmdline_parse_token_hdr_t*)&token) <
331 string_nb_strs[i].nb_strs) {
332 printf("Error: strings count mismatch!\n");
333 return -1;
334 }
335 }
336
337 /* get token at specified position and verify it's correct */
338 for (i = 0; i < RTE_DIM(string_elt_strs); i++) {
339 memset(&token, 0, sizeof(token));

Callers 1

test_cmdlineFunction · 0.85

Calls 8

memsetFunction · 0.85
cmdline_parse_stringFunction · 0.85
cmdline_get_help_stringFunction · 0.85
strcmpFunction · 0.85
strncmpFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected