|
grim@405
|
1 |
/* |
|
grim@405
|
2 |
* Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com> |
|
grim@405
|
3 |
* |
|
grim@405
|
4 |
* This program is free software: you can redistribute it and/or modify |
|
grim@405
|
5 |
* it under the terms of the GNU General Public License as published by |
|
grim@405
|
6 |
* the Free Software Foundation, either version 3 of the License, or |
|
grim@405
|
7 |
* (at your option) any later version. |
|
grim@405
|
8 |
* |
|
grim@405
|
9 |
* This program is distributed in the hope that it will be useful, |
|
grim@405
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
grim@405
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
grim@405
|
12 |
* GNU General Public License for more details. |
|
grim@405
|
13 |
* |
|
grim@405
|
14 |
* You should have received a copy of the GNU General Public License |
|
grim@405
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
grim@405
|
16 |
*/ |
|
grim@405
|
17 |
#include <gplate/gplate.h> |
|
grim@405
|
18 |
|
|
grim@405
|
19 |
#include <glib.h> |
|
grim@405
|
20 |
|
|
grim@405
|
21 |
/****************************************************************************** |
|
grim@405
|
22 |
* Structs |
|
grim@405
|
23 |
*****************************************************************************/ |
|
grim@405
|
24 |
typedef struct { |
|
grim@405
|
25 |
GPlateTemplate *template; |
|
grim@405
|
26 |
|
|
grim@405
|
27 |
const gchar *template_string; |
|
grim@405
|
28 |
|
|
grim@405
|
29 |
gchar *actual; |
|
grim@405
|
30 |
const gchar *expected; |
|
grim@405
|
31 |
|
|
grim@405
|
32 |
GError *error; |
|
grim@405
|
33 |
} TestGPlateIncludeFunctionFixture; |
|
grim@405
|
34 |
|
|
grim@405
|
35 |
/****************************************************************************** |
|
grim@405
|
36 |
* Fixtures |
|
grim@405
|
37 |
*****************************************************************************/ |
|
grim@405
|
38 |
static void |
|
grim@405
|
39 |
test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture, |
|
grim@405
|
40 |
gconstpointer d) |
|
grim@405
|
41 |
{ |
|
grim@405
|
42 |
fixture->template = gplate_template_new(); |
|
grim@405
|
43 |
} |
|
grim@405
|
44 |
|
|
grim@405
|
45 |
static void |
|
grim@405
|
46 |
test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture, |
|
grim@405
|
47 |
gconstpointer d) |
|
grim@405
|
48 |
{ |
|
grim@405
|
49 |
g_object_unref(fixture->template); |
|
grim@405
|
50 |
fixture->template = NULL; |
|
grim@405
|
51 |
|
|
grim@405
|
52 |
g_free(fixture->actual); |
|
grim@405
|
53 |
fixture->actual = NULL; |
|
grim@405
|
54 |
|
|
grim@405
|
55 |
fixture->expected = NULL; |
|
grim@405
|
56 |
|
|
grim@405
|
57 |
if(fixture->error) { |
|
grim@405
|
58 |
g_error_free(fixture->error); |
|
grim@405
|
59 |
fixture->error = NULL; |
|
grim@405
|
60 |
} |
|
grim@405
|
61 |
} |
|
grim@405
|
62 |
|
|
grim@405
|
63 |
/****************************************************************************** |
|
grim@405
|
64 |
* Tests |
|
grim@405
|
65 |
*****************************************************************************/ |
|
grim@405
|
66 |
static void |
|
grim@405
|
67 |
test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture, |
|
grim@405
|
68 |
gconstpointer data) |
|
grim@405
|
69 |
{ |
|
grim@405
|
70 |
fixture->expected = "including\nincluded!\ndone"; |
|
grim@405
|
71 |
|
|
grim@405
|
72 |
fixture->actual = gplate_template_render_file(fixture->template, |
|
grim@405
|
73 |
"templates/simple.gplate", |
|
grim@405
|
74 |
&fixture->error); |
|
grim@405
|
75 |
|
|
grim@405
|
76 |
g_assert(fixture->error == NULL); |
|
grim@405
|
77 |
|
|
grim@405
|
78 |
g_assert_cmpstr(fixture->expected, ==, fixture->actual); |
|
grim@405
|
79 |
} |
|
grim@405
|
80 |
|
|
grim@405
|
81 |
static void |
|
grim@405
|
82 |
test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture, |
|
grim@405
|
83 |
gconstpointer data) |
|
grim@405
|
84 |
{ |
|
grim@405
|
85 |
fixture->expected = " \ |
|
grim@405
|
86 |
<html>\ |
|
grim@405
|
87 |
<head>\ |
|
grim@405
|
88 |
<title>test</title>\ |
|
grim@405
|
89 |
</head>\ |
|
grim@405
|
90 |
<body>\ |
|
grim@405
|
91 |
in the body\ |
|
grim@405
|
92 |
</body>\ |
|
grim@405
|
93 |
</html>"; |
|
grim@405
|
94 |
|
|
grim@405
|
95 |
fixture->actual = gplate_template_render_file(fixture->template, |
|
grim@405
|
96 |
"templates/html.gplate", |
|
grim@405
|
97 |
&fixture->error); |
|
grim@405
|
98 |
|
|
grim@405
|
99 |
g_assert(fixture->error == NULL); |
|
grim@405
|
100 |
|
|
grim@405
|
101 |
g_assert_cmpstr(fixture->expected, ==, fixture->actual); |
|
grim@405
|
102 |
} |
|
grim@405
|
103 |
|
|
grim@405
|
104 |
/****************************************************************************** |
|
grim@405
|
105 |
* Main! |
|
grim@405
|
106 |
*****************************************************************************/ |
|
grim@405
|
107 |
gint |
|
grim@405
|
108 |
main(gint argc, gchar **argv) { |
|
grim@405
|
109 |
g_test_init(&argc, &argv, NULL); |
|
grim@405
|
110 |
|
|
grim@405
|
111 |
g_type_init(); |
|
grim@405
|
112 |
|
|
grim@405
|
113 |
gplate_config_load_default(); |
|
grim@405
|
114 |
|
|
grim@405
|
115 |
g_test_add("/functions/include/simple", |
|
grim@405
|
116 |
TestGPlateIncludeFunctionFixture, |
|
grim@405
|
117 |
NULL, |
|
grim@405
|
118 |
test_gplate_include_function_setup, |
|
grim@405
|
119 |
test_gplate_include_function_simple, |
|
grim@405
|
120 |
test_gplate_include_function_teardown); |
|
grim@405
|
121 |
|
|
grim@405
|
122 |
g_test_add("/functions/include/double", |
|
grim@405
|
123 |
TestGPlateIncludeFunctionFixture, |
|
grim@405
|
124 |
NULL, |
|
grim@405
|
125 |
test_gplate_include_function_setup, |
|
grim@405
|
126 |
test_gplate_include_function_double, |
|
grim@405
|
127 |
test_gplate_include_function_teardown); |
|
grim@405
|
128 |
|
|
grim@405
|
129 |
return g_test_run(); |
|
grim@405
|
130 |
} |
|
grim@405
|
131 |
|