#include #include //Nested loops w/ break char t_1[] = "What is a loop with no items?Something\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!"; char c_2_3[] = "Render error: Variable \"loop1\" was not bound to a value\n"; #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,t,e)\ 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{\ if(strcmp(TMPL_err(t,NULL),e) != 0){\ fprintf(stderr, "Error in test 3.%d.%d\n",n,n2);\ printf("Error was: '%s'\nShould have been: '%s'\n",TMPL_err(t,NULL),e);\ return -1;\ }\ 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 tests3\n"); struct TMPL_templates* t; struct TMPL_varlist *vl; struct TMPL_loop *l1; 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,t,c_2_3); TMPL_free_template(t); TMPL_free_varlist(vl); log("Test 3 complete\n"); return 0; }