aboutsummaryrefslogtreecommitdiff
path: root/t/test_2.c
blob: b67cca29b7aee31c7efc8bccbd3862f26eb643d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
}