-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.c
68 lines (53 loc) · 1.75 KB
/
tests.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <stdio.h>
#include "mustache.h"
Dict*
simulate_request() {
Dict *dict = Mstc_dict_new();
Dict *sub, *subsub;
Mstc_dict_setValue(dict, "title", "My wonderfull title");
Mstc_dict_setValue(dict, "name", "jojo");
Mstc_dict_setValue(dict, "genre", "male");
Mstc_dict_setValue(dict, "page_link", "<a href=\"https://www.gg.fr\">gg</a>");
Mstc_dict_setValue(dict, "author", "jojo");
Mstc_dict_setValue(dict, "url", "http://jojo.fr");
sub = Mstc_dict_addSectionItem(dict, "pets");
Mstc_dict_setValue(sub, "name", "gwen");
Mstc_dict_setValue(sub, "kind", "chien");
sub = Mstc_dict_addSectionItem(dict, "pets");
Mstc_dict_setValue(sub, "name", "chuchen");
Mstc_dict_setValue(sub, "kind", "chat");
subsub = Mstc_dict_addSectionItem(sub, "nest");
Mstc_dict_setValue(subsub, "name", "hello nest");
Mstc_dict_setValue(dict, "footer", "copyrithg jojo");
Mstc_dict_setValue(dict, "noescape", "<a href=\"#\">jo</a>");
Mstc_dict_setValue(dict, "escape", "<a href=\"#\">'jo'</a>");
return dict;
}
int
main(int argc, char **argv) {
int count;
if (argc > 2)
count = atoi(argv[2]);
else
count = 1000;
TemplateStore *store = Mstc_template_create();
Template *template = Mstc_template_get(store, argv[1]);
Dict *dict;
char *output;
int i;
for (i=0; i<count; i++) {
dict = simulate_request();
output = Mstc_expand(template, dict);
Mstc_dict_free(dict);
free(output);
}
/* one more to print out */
dict = simulate_request();
output = Mstc_expand(template, dict);
Mstc_dict_free(dict);
printf("%s\n",output);
free(output);
Mstc_template_free(store);
return EXIT_SUCCESS;
}