ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
test_framework.h
Go to the documentation of this file.
1 
13 #include "../src/ceptr.h"
14 
15 #define MAX_FAILURES 1000
16 int spec_failures = 0;
17 int spec_total = 0;
18 char failures[MAX_FAILURES][5000];
19 char buf1[2000];
20 char buf2[2000];
21 
22 #define spec_is_true(x) spec_total++;if (x){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be true",__FUNCTION__,__LINE__,#x);}
23 #define spec_is_false(x) spec_total++;if (!(x)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be false",__FUNCTION__,__LINE__,#x);}
24 #define spec_is_equal(got, expected) spec_total++; {int __got=got;int __ex=expected;if (__ex==__got){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %d but was %d",__FUNCTION__,__LINE__,#got,__ex,__got);}}
25 #define spec_is_str_equal(got, expected) spec_total++; {char *__got=got;char *__ex=expected; if (strcmp(__got,__ex)==0){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be:\n \"%s\"\nbut_was:\n \"%s\"",__FUNCTION__,__LINE__,#got,__ex,__got);}}
26 #define spec_is_long_equal(got, expected) spec_total++; {long __got=got;long __ex=(long)expected;if (__ex==__got){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %ld but was %ld",__FUNCTION__,__LINE__,#got,__ex,__got);}}
27 #define spec_is_ptr_equal(got, expected) spec_total++; {void *__got=got;void *__ex=expected;if (__ex==__got){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %p but was %p",__FUNCTION__,__LINE__,#got,__ex,__got);}}
28 #define spec_is_path_equal(got, expected) spec_total++; {int *__got=got;int *__ex=expected; if (__got && _t_path_equal(__got,__ex)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %s but was %s",__FUNCTION__,__LINE__,#got,_t_sprint_path(__ex,buf1),__got ? _t_sprint_path(__got,buf2) : "nil");}}
29 #define spec_is_float_equal(got, expected) spec_total++; {float=__got;float __ex=expected; if (__ex==__got){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %f but was %f",__FUNCTION__,__LINE__,#got,__ex,__got);}}
30 #define spec_is_buffer_equal(got, expected, length) spec_total++; if ((strlen(expected) == length) && memcmp(got,expected,length)==0){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %ld bytes from %s to match %s but got %.*s",__FUNCTION__,__LINE__,(long)length,#got,#expected,(int)length,got);}
31 
32 void report_tests() {
33  int i;
34  if (spec_failures > 0) {
35  printf("\n%d out of %d specs failed:\n", spec_failures,spec_total);
36  for (i = 0; i < spec_failures; i++) {
37  printf("%s\n", failures[i]);
38  }
39  }
40  else {
41  printf("\nAll %d specs pass\n", spec_total);
42  }
43 }