aboutsummaryrefslogtreecommitdiff
path: root/t/test_2.c
diff options
context:
space:
mode:
Diffstat (limited to 't/test_2.c')
-rw-r--r--t/test_2.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/t/test_2.c b/t/test_2.c
new file mode 100644
index 0000000..b67cca2
--- /dev/null
+++ b/t/test_2.c
@@ -0,0 +1,47 @@
+
+#include <stdio.h>
+
+#include <ctemplates.h>
+
+char t_1[] = "This is a <TMPL_LOOP name=\"loop1\"><TMPL_LOOP name=\"loop2\">Text<TMPL_BREAK>Text2<TMPL_END><TMPL_END>!";
+char c_1_1[] = "This is a Text!";
+
+#define log(x) printf(x)
+
+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;
+
+ /*Test 1: Variable*/
+ t = TMPL_alloc_template(t_1);
+ vl = TMPL_alloc_varlist();
+ TMPL_add_var_to_varlist(vl,"what","template");
+ l1 = TMPL_alloc_loop();
+ vl1 = TMPL_alloc_varlist();
+
+ l2 = TMPL_alloc_loop();
+ vl2 = TMPL_alloc_varlist();
+ TMPL_add_varlist_to_loop(l2,vl2);
+ TMPL_add_loop_to_varlist(vl1,"loop2",l2);
+
+ TMPL_add_varlist_to_loop(l1,vl1);
+ TMPL_add_loop_to_varlist(vl,"loop1",l1);
+
+ ret = TMPL_render(t,vl,&dummy);
+ if(strcmp(ret,c_1_1) != 0){
+ fprintf(stderr,"Error in test file 2, test 1\n");
+ printf("Result should have been '%s'\n was '%s'\n",c_1_1,ret);
+ if(t->error)
+ printf(TMPL_err(t, NULL));
+ return -1;
+ }
+ TMPL_free_template(t);
+ TMPL_free_varlist(vl);
+ log("Test 1 complete\n");
+
+ return 0;
+}