run-iter.c 1.9 KB

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