static void circular_buffer_test(circular_buffer_t cb) { int i; test_t t; for (i = 0; i < 7; ++i) { memset(t.buf, 0, sizeof(t.buf)); t.index = i + 1; sprintf(t.buf, "the test buffer with id=>%d\n", t.index); t.len = strlen(t.buf); circular_buffer_put(cb, (const char*)&t, sizeof(t)); } fprintf(stdout, "size : %d\n", circular_buffer_size(cb)); fprintf(stdout, "circular buffer get=>%d\n", circular_buffer_get(cb, sizeof(t), (char*)&t)); fprintf(stdout, "size : %d\n", circular_buffer_size(cb)); test_show(t); for (i = 0; i < 1; ++i) { memset(t.buf, 0, sizeof(t.buf)); t.index = (i + 7) * (i + 7); sprintf(t.buf, "the test buffer with id=>%d\n", t.index); t.len = strlen(t.buf); circular_buffer_put(cb, (const char*)&t, sizeof(t)); } fprintf(stdout, "size : %d\n", circular_buffer_size(cb)); while (!circular_buffer_empty(cb)) { circular_buffer_get(cb, sizeof(t), (char*)&t); test_show(t); } fprintf(stdout, "size : %d\n", circular_buffer_size(cb)); }
void test_assert(int result, int value) { if (result != value) { test_show("assert (%d == %d) FAILED\n", result, value); exit(1); } }
static void diff_file(const char *file, const char *outfile, const char *msg) { char *diffcmd = malloc(SNPRINTF_SIZE); char *difffname = malloc(SNPRINTF_SIZE); int total_size; assert(file && outfile); assert(diffcmd && difffname); if (total_size = snprintf(difffname, SNPRINTF_SIZE, "%s.diff", outfile) >= SNPRINTF_SIZE) { difffname = malloc(total_size); assert(difffname); snprintf(difffname, total_size, "%s.diff", outfile); } if (total_size = snprintf(diffcmd, SNPRINTF_SIZE, "diff -N \"%s%s\" \"%s\" >> \"%s\"", TEST_RESULT_DIR, file, outfile, difffname) >= SNPRINTF_SIZE) { diffcmd = malloc(total_size); assert(diffcmd); snprintf(diffcmd, total_size, "diff -N \"%s%s\" \"%s\" >> \"%s\"", TEST_RESULT_DIR, file, outfile, difffname); } if (system(diffcmd)) { test_show(msg); show_diff(difffname); free(difffname); free(diffcmd); exit(1); } free(difffname); free(diffcmd); remove(difffname); }
static void show_diff(char *difffname) { char diffline[512]; FILE *difffile; difffile = fopen(difffname, "r"); if (!difffile) { test_show("Error couldn't open %s to display the diff\n", difffname); return; } test_show("!diff follows\n"); while (fgets(diffline, sizeof(diffline), difffile)) { /* Call fprintf directly here because we unmodified diff output */ fprintf(my_stdout, "%s", diffline); } fclose(difffile); test_show("!diff end\n"); }
void test_fail(const char *fmt, ...) { va_list args; if (fmt) { va_start(args, fmt); vtest_show(fmt, args); va_end(args); } test_show("FAIL"); exit(1); }
void test_passed(void) { test_show("PASSED\n"); passed = 1; }
int main (int argc, char **argv) { gtk_init (&argc, &argv); test_show (); return 0; }