chiark / gitweb /
Infrastructure: Switch testing over to Autotest.
[mLib] / struct / t / sym-test.c
similarity index 85%
rename from struct/sym-test.c
rename to struct/t/sym-test.c
index 18e984167d6d1329b5e4ac4bafbb48104d6c6b6e..264d6a957f25e73db6eaac27a8a2eb3b4343f137 100644 (file)
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -21,13 +22,13 @@ int main(void)
   char buf[256];
   char *p;
   sym_table t;
-  size_t n = 0;
+  size_t n = 0, j;
 
   sym_create(&t);
 
   while (fgets(buf, sizeof(buf), stdin)) {
+/*     printf("+++ %s", buf); */
     buf[strlen(buf) - 1] = 0;
-/*     printf("# %s\n", buf); */
     p = strtok(buf, " ");
 
     if (strcmp(p, "set") == 0) {
@@ -68,17 +69,23 @@ int main(void)
          puts("*NOMEM*");
          continue;
        }
-       for (vv = v, sym_mkiter(&i, &t); (w = sym_next(&i)) != 0; vv++)
+       for (vv = v, sym_mkiter(&i, &t), j = 0;
+            (w = sym_next(&i)) != 0;
+            vv++, j++) {
+         assert(j < n);
          *vv = w;
+       }
+       assert(j == n);
        qsort(v, n, sizeof(*v), cmp);
        printf("%s:%i", SYM_NAME(*v), (*v)->i);
-       for (vv = v + 1; --n; vv++)
+       for (vv = v + 1; --j; vv++)
          printf(" %s:%i", SYM_NAME(*vv), (*vv)->i);
        free(v);
        putchar('\n');
       }
     } else
       puts("*BAD*");
+/*     printf("--- %d\n", n); */
   }
 
   sym_destroy(&t);