diff options
Diffstat (limited to 't/test_3.c')
| -rw-r--r-- | t/test_3.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/t/test_3.c b/t/test_3.c new file mode 100644 index 0000000..dc55aa6 --- /dev/null +++ b/t/test_3.c @@ -0,0 +1,72 @@ +#include <stdio.h> + +#include <ctemplates.h> + +//Nested loops w/ break +char t_1[] = "What is a loop with no items?<TMPL_LOOP name=\"loop1\">Something<TMPL_END>\nA sad little pile of bits!"; +char c_1_1[] = "What is a loop with no items?\nA sad little pile of bits!"; +char c_1_2[] = "What is a loop with no items?\nA sad little pile of bits!"; + +#define log(x) printf(x) + +#define check(n,n2,a,b)\ + if(strcmp(a,b) != 0){\ + fprintf(stderr, "Error in test 3.%d.%d\n",n,n2);\ + printf("Result should have been '%s'\n was '%s'\n", b, a);\ + if(t->error)\ + printf(TMPL_err(t, NULL));\ + return -1;\ + }else{\ + printf("\n\n##########\n##Test %d.%d passed\n##########\n\n\n",n,n2);\ + } + +#define check_isnull(n,n2,a)\ + if(a != NULL){\ + fprintf(stderr, "Error in test 3.%d.%d\n",n,n2);\ + printf("Result should have been NULL\n was '%s'\n", a);\ + if(t->error)\ + printf(TMPL_err(t, NULL));\ + return -1;\ + }else{\ + printf("\n\n##########\n##Test %d.%d passed\n##########\n\n\n",n,n2);\ + } + +#define template(x,y) \ + err = TMPL_alloc_template(x,&y);\ + if(err != 0){\ + printf("Error: %s\n",TMPL_err(y,&dummy));\ + return -1;\ + } + +int main(){ + log("Running tests2\n"); + struct TMPL_templates* t; + struct TMPL_varlist *vl,*vl1,*vl2; + struct TMPL_loop *l1,*l2; + char* ret; + size_t dummy; + int err; + + /*Test 1: Variable*/ + template(t_1,t); + vl = TMPL_alloc_varlist(); + l1 = TMPL_alloc_loop(); + TMPL_add_loop_to_varlist(vl,"loop1",l1); + ret = TMPL_render(t,vl,&dummy); + check(1,1,ret,c_1_1); + TMPL_free_template(t); + TMPL_free_varlist(vl); + log("Test 1 complete\n"); + + template(t_1,t); + vl = TMPL_alloc_varlist(); + l1 = TMPL_alloc_loop(); + TMPL_add_loop_to_varlist(vl,"notaloop",l1); + ret = TMPL_render(t,vl,&dummy); + check_isnull(1,2,ret); + TMPL_free_template(t); + TMPL_free_varlist(vl); + log("Test 2 complete\n"); + + return 0; +} |
