- struct bt_argpar_parse_ret parse_ret;
- gchar **argv = g_strsplit(cmdline, " ", 0);
-
- parse_ret = bt_argpar_parse(g_strv_length(argv),
- (const char * const *) argv, descrs, true);
- ok(!parse_ret.items,
- "bt_argpar_parse() fails for command line `%s`", cmdline);
- ok(parse_ret.error,
- "bt_argpar_parse() writes an error string for command line `%s`",
- cmdline);
- if (parse_ret.items) {
- fail("bt_argpar_parse() writes the expected error string");
- goto end;
- }
+ struct argpar_iter *iter = NULL;
+ const struct argpar_item *item = NULL;
+ gchar ** const argv = g_strsplit(cmdline, " ", 0);
+ unsigned int i;
+ const struct argpar_error *error = NULL;
+
+ iter = argpar_iter_create(g_strv_length(argv),
+ (const char * const *) argv, descrs);
+ assert(iter);
+
+ for (i = 0; ; i++) {
+ enum argpar_iter_next_status status;
+
+ ARGPAR_ITEM_DESTROY_AND_RESET(item);
+ status = argpar_iter_next(iter, &item, &error);
+ ok(status == ARGPAR_ITER_NEXT_STATUS_OK ||
+ (status == ARGPAR_ITER_NEXT_STATUS_ERROR &&
+ argpar_error_type(error) == expected_error_type),
+ "argpar_iter_next() returns the expected status "
+ "and error type (%d) for command line `%s` (call %u)",
+ expected_error_type, cmdline, i + 1);
+
+ if (status != ARGPAR_ITER_NEXT_STATUS_OK) {
+ ok(!item,
+ "argpar_iter_next() doesn't set an item "
+ "for other status than "
+ "`ARGPAR_ITER_NEXT_STATUS_OK` "
+ "and command line `%s` (call %u)",
+ cmdline, i + 1);
+ ok(error,
+ "argpar_iter_next() sets an error for "
+ "other status than "
+ " `ARGPAR_ITER_NEXT_STATUS_OK` "
+ "and command line `%s` (call %u)",
+ cmdline, i + 1);
+ ok(argpar_error_orig_index(error) ==
+ expected_orig_index,
+ "argpar_iter_next() sets an error with "
+ "the expected original argument index "
+ "for command line `%s` (call %u)",
+ cmdline, i + 1);
+
+ if (argpar_error_type(error) == ARGPAR_ERROR_TYPE_UNKNOWN_OPT) {
+ ok(strcmp(argpar_error_unknown_opt_name(error),
+ expected_unknown_opt_name) == 0,
+ "argpar_iter_next() sets an error with "
+ "the expected unknown option name "
+ "for command line `%s` (call %u)",
+ cmdline, i + 1);
+ } else {
+ bool is_short;
+
+ ok(argpar_error_opt_descr(error, &is_short) ==
+ &descrs[expected_opt_descr_index],
+ "argpar_iter_next() sets an error with "
+ "the expected option descriptor "
+ "for command line `%s` (call %u)",
+ cmdline, i + 1);
+ ok(is_short == expected_is_short,
+ "argpar_iter_next() sets an error with "
+ "the expected option type "
+ "for command line `%s` (call %u)",
+ cmdline, i + 1);
+ }
+ break;
+ }