Home | History | Annotate | Download | only in tests
      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 #include "unit_test.h"
      6 
      7 void run_tests(struct test tests[])
      8 {
      9 	int i;
     10 	for (i = 0; tests[i].name; i++) {
     11 		printf("Test %s\n", tests[i].name);
     12 		memset(&tests[i].result, 0, sizeof(tests[i].result));
     13 		tests[i].test_func(&tests[i].result);
     14 		printf("Test %s (%d/%d) pass\n", tests[i].name,
     15 			tests[i].result.pass, tests[i].result.test_count);
     16 	}
     17 }
     18 
     19 void test_begin(struct test_result * result)
     20 {
     21 	result->test_count++;
     22 }
     23 
     24 void test_check(struct test_result * result, int cond)
     25 {
     26 	printf("Subtest %u -> ", result->test_count);
     27 	if (cond) {
     28 		result->pass++;
     29 		printf("Pass");
     30 	} else {
     31 		result->fail++;
     32 		printf("Fail");
     33 	}
     34 	printf("\n");
     35 }
     36