/* Wee testing program from the gap code, this is very similar to the hash * testing code. * Instead of pointers, we use integers * * script language: * a 5 12 # adds value 12 at index 5 * d 512 42 # remove value 42, 512 is the length of the array * h 16 0 # set hard limit to 16 (value is not used) */ #include #include #include #include #include "../gap.h" static void gtest_next_line(FILE* f, char* action, int* index, void** value) { int res = 0; while ((res != 3) && (res != EOF)) res = fscanf(f, "%c %d %p\n", action, index, value); if (res == EOF) exit(0); } static void gap_dump(gap_array* gap, char* filename) { int i; FILE* out = fopen(filename, "w"); if (!out) { perror(filename); exit(1); } fprintf(out, "\n", gap->len, gap->hardlimit); for (i = 0; i < gap->len; i++) { void* value = gap_get(gap, i); fprintf(out, "[%d] = %p\n", i, value); } fprintf(out, "\n"); fclose(out); } int main(int argc, char* argv[]) { gap_array* gap = gap_init(0); char action; int line = 0, index; void* value; FILE* f; if (argc != 3) { fprintf(stderr, "Usage: gtest