1.1 --- a/gplate/functions/tests/CMakeLists.txt Sun Jul 04 15:35:33 2010 -0500
1.2 +++ b/gplate/functions/tests/CMakeLists.txt Sun Jul 04 16:09:43 2010 -0500
1.3 @@ -4,6 +4,10 @@
1.4 target_link_libraries(test-gplate-for-function gplate)
1.5 list(APPEND FUNCTION_TESTS test-gplate-for-function)
1.6
1.7 +add_executable(test-gplate-include-function test-gplate-include-function.c)
1.8 +target_link_libraries(test-gplate-include-function gplate)
1.9 +list(APPEND FUNCTION_TESTS test-gplate-for-function)
1.10 +
1.11 add_test(GPlateFunctions
1.12 ${GTESTER} -k --verbose -o test-gplate-function.log
1.13 ${FUNCTION_TESTS}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/gplate/functions/tests/templates/footer.gplate Sun Jul 04 16:09:43 2010 -0500
2.3 @@ -0,0 +1,2 @@
2.4 + </body>
2.5 +</html>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/gplate/functions/tests/templates/header.gplate Sun Jul 04 16:09:43 2010 -0500
3.3 @@ -0,0 +1,5 @@
3.4 +<html>
3.5 + <head>
3.6 + <title>test</title>
3.7 + </head>
3.8 + <body>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/gplate/functions/tests/templates/html.gplate Sun Jul 04 16:09:43 2010 -0500
4.3 @@ -0,0 +1,1 @@
4.4 +{% include "header.gplate" %}in the body{% include "footer.gplate" %}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/gplate/functions/tests/templates/simple-include.gplate Sun Jul 04 16:09:43 2010 -0500
5.3 @@ -0,0 +1,1 @@
5.4 +included!
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/gplate/functions/tests/templates/simple.gplate Sun Jul 04 16:09:43 2010 -0500
6.3 @@ -0,0 +1,4 @@
6.4 +including
6.5 +{% include "simple-include.gplate" %}
6.6 +done
6.7 +
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/gplate/functions/tests/test-gplate-include-function.c Sun Jul 04 16:09:43 2010 -0500
7.3 @@ -0,0 +1,131 @@
7.4 +/*
7.5 + * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
7.6 + *
7.7 + * This program is free software: you can redistribute it and/or modify
7.8 + * it under the terms of the GNU General Public License as published by
7.9 + * the Free Software Foundation, either version 3 of the License, or
7.10 + * (at your option) any later version.
7.11 + *
7.12 + * This program is distributed in the hope that it will be useful,
7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 + * GNU General Public License for more details.
7.16 + *
7.17 + * You should have received a copy of the GNU General Public License
7.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7.19 + */
7.20 +#include <gplate/gplate.h>
7.21 +
7.22 +#include <glib.h>
7.23 +
7.24 +/******************************************************************************
7.25 + * Structs
7.26 + *****************************************************************************/
7.27 +typedef struct {
7.28 + GPlateTemplate *template;
7.29 +
7.30 + const gchar *template_string;
7.31 +
7.32 + gchar *actual;
7.33 + const gchar *expected;
7.34 +
7.35 + GError *error;
7.36 +} TestGPlateIncludeFunctionFixture;
7.37 +
7.38 +/******************************************************************************
7.39 + * Fixtures
7.40 + *****************************************************************************/
7.41 +static void
7.42 +test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture,
7.43 + gconstpointer d)
7.44 +{
7.45 + fixture->template = gplate_template_new();
7.46 +}
7.47 +
7.48 +static void
7.49 +test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture,
7.50 + gconstpointer d)
7.51 +{
7.52 + g_object_unref(fixture->template);
7.53 + fixture->template = NULL;
7.54 +
7.55 + g_free(fixture->actual);
7.56 + fixture->actual = NULL;
7.57 +
7.58 + fixture->expected = NULL;
7.59 +
7.60 + if(fixture->error) {
7.61 + g_error_free(fixture->error);
7.62 + fixture->error = NULL;
7.63 + }
7.64 +}
7.65 +
7.66 +/******************************************************************************
7.67 + * Tests
7.68 + *****************************************************************************/
7.69 +static void
7.70 +test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture,
7.71 + gconstpointer data)
7.72 +{
7.73 + fixture->expected = "including\nincluded!\ndone";
7.74 +
7.75 + fixture->actual = gplate_template_render_file(fixture->template,
7.76 + "templates/simple.gplate",
7.77 + &fixture->error);
7.78 +
7.79 + g_assert(fixture->error == NULL);
7.80 +
7.81 + g_assert_cmpstr(fixture->expected, ==, fixture->actual);
7.82 +}
7.83 +
7.84 +static void
7.85 +test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture,
7.86 + gconstpointer data)
7.87 +{
7.88 + fixture->expected = " \
7.89 +<html>\
7.90 + <head>\
7.91 + <title>test</title>\
7.92 + </head>\
7.93 + <body>\
7.94 +in the body\
7.95 + </body>\
7.96 +</html>";
7.97 +
7.98 + fixture->actual = gplate_template_render_file(fixture->template,
7.99 + "templates/html.gplate",
7.100 + &fixture->error);
7.101 +
7.102 + g_assert(fixture->error == NULL);
7.103 +
7.104 + g_assert_cmpstr(fixture->expected, ==, fixture->actual);
7.105 +}
7.106 +
7.107 +/******************************************************************************
7.108 + * Main!
7.109 + *****************************************************************************/
7.110 +gint
7.111 +main(gint argc, gchar **argv) {
7.112 + g_test_init(&argc, &argv, NULL);
7.113 +
7.114 + g_type_init();
7.115 +
7.116 + gplate_config_load_default();
7.117 +
7.118 + g_test_add("/functions/include/simple",
7.119 + TestGPlateIncludeFunctionFixture,
7.120 + NULL,
7.121 + test_gplate_include_function_setup,
7.122 + test_gplate_include_function_simple,
7.123 + test_gplate_include_function_teardown);
7.124 +
7.125 + g_test_add("/functions/include/double",
7.126 + TestGPlateIncludeFunctionFixture,
7.127 + NULL,
7.128 + test_gplate_include_function_setup,
7.129 + test_gplate_include_function_double,
7.130 + test_gplate_include_function_teardown);
7.131 +
7.132 + return g_test_run();
7.133 +}
7.134 +
8.1 --- a/tests/templates/Makefile.am Sun Jul 04 15:35:33 2010 -0500
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,4 +0,0 @@
8.4 -EXTRA_DIST=\
8.5 - simple.gplate \
8.6 - simple-include.gplate
8.7 -
9.1 --- a/tests/templates/footer.gplate Sun Jul 04 15:35:33 2010 -0500
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,2 +0,0 @@
9.4 - </body>
9.5 -</html>
10.1 --- a/tests/templates/header.gplate Sun Jul 04 15:35:33 2010 -0500
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,5 +0,0 @@
10.4 -<html>
10.5 - <head>
10.6 - <title>test</title>
10.7 - </head>
10.8 - <body>
11.1 --- a/tests/templates/html.gplate Sun Jul 04 15:35:33 2010 -0500
11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
11.3 @@ -1,1 +0,0 @@
11.4 -{% include "header.gplate" %}in the body{% include "footer.gplate" %}
12.1 --- a/tests/templates/simple-include.gplate Sun Jul 04 15:35:33 2010 -0500
12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
12.3 @@ -1,1 +0,0 @@
12.4 -inside the included file
13.1 --- a/tests/templates/simple.gplate Sun Jul 04 15:35:33 2010 -0500
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,4 +0,0 @@
13.4 -before the include
13.5 -{% include "simple-include.gplate" %}
13.6 -after the include
13.7 -
14.1 --- a/tests/test-include.c Sun Jul 04 15:35:33 2010 -0500
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,122 +0,0 @@
14.4 -#ifdef HAVE_CONFIG_H
14.5 -# include <config.h>
14.6 -#endif /* HAVE_CONFIG_H */
14.7 -
14.8 -#include <check.h>
14.9 -
14.10 -#include <stdio.h>
14.11 -#include <string.h>
14.12 -
14.13 -#include <gplate/gplate.h>
14.14 -
14.15 -#include "test.h"
14.16 -
14.17 -/******************************************************************************
14.18 - * Globals
14.19 - *****************************************************************************/
14.20 -static GPlateTemplate *tplate = NULL;
14.21 -static GError *error = NULL;
14.22 -static gchar *msg = NULL;
14.23 -
14.24 -/******************************************************************************
14.25 - * Fixtures
14.26 - *****************************************************************************/
14.27 -static void
14.28 -simple_setup(void) {
14.29 - tplate = gplate_template_new();
14.30 -}
14.31 -
14.32 -static void
14.33 -simple_teardown(void) {
14.34 - g_object_unref(G_OBJECT(tplate));
14.35 -
14.36 - tplate = NULL;
14.37 -
14.38 - if(error)
14.39 - g_error_free(error);
14.40 - error = NULL;
14.41 -
14.42 - g_free(msg);
14.43 - msg = NULL;
14.44 -}
14.45 -
14.46 -/******************************************************************************
14.47 - * Simple Includes
14.48 - *****************************************************************************/
14.49 -START_TEST(test_include_simple_static)
14.50 - gchar *output = NULL, *e1 = NULL, *e2 = NULL;
14.51 - const gchar *expected =
14.52 - "before the include\n"
14.53 - "inside the included file\n\n"
14.54 - "after the include\n"
14.55 - "\n";
14.56 - gint r = 0;
14.57 -
14.58 - output = gplate_template_render_file(tplate, "templates/simple.gplate",
14.59 - &error);
14.60 -
14.61 - fail_unless(error == NULL,
14.62 - (error && error->message) ? error->message : "Unknown failed");
14.63 -
14.64 - r = g_utf8_collate(output, expected);
14.65 -
14.66 - e1 = g_strescape(output, NULL);
14.67 - e2 = g_strescape(expected, NULL);
14.68 - msg = g_strdup_printf("\ngot: '%s'\nwanted: '%s'\n", e1, e2);
14.69 -
14.70 - g_free(output);
14.71 - g_free(e1);
14.72 - g_free(e2);
14.73 -
14.74 - fail_unless(r == 0, msg);
14.75 -END_TEST
14.76 -
14.77 -START_TEST(test_include_html_header_footer)
14.78 - gchar *output = NULL, *e1 = NULL, *e2 = NULL;
14.79 - const gchar *expected =
14.80 - "<html>\n"
14.81 - "\t<head>\n"
14.82 - "\t\t<title>test</title>\n"
14.83 - "\t</head>\n"
14.84 - "\t<body>\n"
14.85 - "in the body"
14.86 - "\t</body>\n"
14.87 - "</html>\n\n";
14.88 - gint r = 0;
14.89 -
14.90 - output = gplate_template_render_file(tplate, "templates/html.gplate",
14.91 - &error);
14.92 -
14.93 - fail_unless(error == NULL,
14.94 - (error && error->message) ? error->message : "Unknown failure");
14.95 -
14.96 - r = g_utf8_collate(output, expected);
14.97 -
14.98 - e1 = g_strescape(output, NULL);
14.99 - e2 = g_strescape(expected, NULL);
14.100 - msg = g_strdup_printf("\ngot: '%s'\nwanted: '%s'\n", e1, e2);
14.101 -
14.102 - g_free(output);
14.103 - g_free(e1);
14.104 - g_free(e2);
14.105 -
14.106 - fail_unless(r == 0, msg);
14.107 -END_TEST
14.108 -
14.109 -/******************************************************************************
14.110 - * Exported
14.111 - *****************************************************************************/
14.112 -Suite *
14.113 -include_suite(void) {
14.114 - Suite *s = suite_create("Include Function Suite");
14.115 - TCase *tc = NULL;
14.116 -
14.117 - tc = tcase_create("Simple Includes");
14.118 - tcase_add_checked_fixture(tc, simple_setup, simple_teardown);
14.119 - tcase_add_test(tc, test_include_simple_static);
14.120 - tcase_add_test(tc, test_include_html_header_footer);
14.121 - suite_add_tcase(s, tc);
14.122 -
14.123 - return s;
14.124 -}
14.125 -