Tag
Hash :
a0d14d15
Author :
Date :
2011-07-06T16:47:25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#include <ccan/tap/tap.h>
#include <stdarg.h>
#include <setjmp.h>
#include <stdlib.h>
#include <stdarg.h>
#include "utils.h"
#include <ccan/opt/opt.c>
#include <ccan/opt/usage.c>
#include <ccan/opt/helpers.c>
#include <ccan/opt/parse.c>
static void reset_options(void)
{
free(opt_table);
opt_table = NULL;
opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0;
}
/* Test iterators. */
int main(int argc, char *argv[])
{
unsigned j, i, len = 0;
const char *p;
plan_tests(37 * 2);
for (j = 0; j < 2; j ++) {
reset_options();
/* Giving subtable a title makes an extra entry! */
opt_register_table(subtables, j == 0 ? NULL : "subtable");
p = first_lopt(&i, &len);
ok1(i == j + 0);
ok1(len == 3);
ok1(strncmp(p, "jjj", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 0);
ok1(len == 3);
ok1(strncmp(p, "lll", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 1);
ok1(len == 3);
ok1(strncmp(p, "mmm", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 5);
ok1(len == 3);
ok1(strncmp(p, "ddd", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 6);
ok1(len == 3);
ok1(strncmp(p, "eee", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 7);
ok1(len == 3);
ok1(strncmp(p, "ggg", len) == 0);
p = next_lopt(p, &i, &len);
ok1(i == j + 8);
ok1(len == 3);
ok1(strncmp(p, "hhh", len) == 0);
p = next_lopt(p, &i, &len);
ok1(!p);
p = first_sopt(&i);
ok1(i == j + 0);
ok1(*p == 'j');
p = next_sopt(p, &i);
ok1(i == j + 0);
ok1(*p == 'l');
p = next_sopt(p, &i);
ok1(i == j + 1);
ok1(*p == 'm');
p = next_sopt(p, &i);
ok1(i == j + 2);
ok1(*p == 'a');
p = next_sopt(p, &i);
ok1(i == j + 3);
ok1(*p == 'b');
p = next_sopt(p, &i);
ok1(i == j + 7);
ok1(*p == 'g');
p = next_sopt(p, &i);
ok1(i == j + 8);
ok1(*p == 'h');
p = next_sopt(p, &i);
ok1(!p);
}
return exit_status();
}