grim/gplate

b90b9411363f
Parents ce6fd664bf5d
Children 9b903d04907a
moved the include function tests to the new format

refs #16
--- a/gplate/functions/tests/CMakeLists.txt Sun Jul 04 15:35:33 2010 -0500
+++ b/gplate/functions/tests/CMakeLists.txt Sun Jul 04 16:09:43 2010 -0500
@@ -4,6 +4,10 @@
target_link_libraries(test-gplate-for-function gplate)
list(APPEND FUNCTION_TESTS test-gplate-for-function)
+add_executable(test-gplate-include-function test-gplate-include-function.c)
+target_link_libraries(test-gplate-include-function gplate)
+list(APPEND FUNCTION_TESTS test-gplate-for-function)
+
add_test(GPlateFunctions
${GTESTER} -k --verbose -o test-gplate-function.log
${FUNCTION_TESTS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/templates/footer.gplate Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,2 @@
+ </body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/templates/header.gplate Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,5 @@
+<html>
+ <head>
+ <title>test</title>
+ </head>
+ <body>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/templates/html.gplate Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,1 @@
+{% include "header.gplate" %}in the body{% include "footer.gplate" %}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/templates/simple-include.gplate Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,1 @@
+included!
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/templates/simple.gplate Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,4 @@
+including
+{% include "simple-include.gplate" %}
+done
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/test-gplate-include-function.c Sun Jul 04 16:09:43 2010 -0500
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <gplate/gplate.h>
+
+#include <glib.h>
+
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+typedef struct {
+ GPlateTemplate *template;
+
+ const gchar *template_string;
+
+ gchar *actual;
+ const gchar *expected;
+
+ GError *error;
+} TestGPlateIncludeFunctionFixture;
+
+/******************************************************************************
+ * Fixtures
+ *****************************************************************************/
+static void
+test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture,
+ gconstpointer d)
+{
+ fixture->template = gplate_template_new();
+}
+
+static void
+test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture,
+ gconstpointer d)
+{
+ g_object_unref(fixture->template);
+ fixture->template = NULL;
+
+ g_free(fixture->actual);
+ fixture->actual = NULL;
+
+ fixture->expected = NULL;
+
+ if(fixture->error) {
+ g_error_free(fixture->error);
+ fixture->error = NULL;
+ }
+}
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture,
+ gconstpointer data)
+{
+ fixture->expected = "including\nincluded!\ndone";
+
+ fixture->actual = gplate_template_render_file(fixture->template,
+ "templates/simple.gplate",
+ &fixture->error);
+
+ g_assert(fixture->error == NULL);
+
+ g_assert_cmpstr(fixture->expected, ==, fixture->actual);
+}
+
+static void
+test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture,
+ gconstpointer data)
+{
+ fixture->expected = " \
+<html>\
+ <head>\
+ <title>test</title>\
+ </head>\
+ <body>\
+in the body\
+ </body>\
+</html>";
+
+ fixture->actual = gplate_template_render_file(fixture->template,
+ "templates/html.gplate",
+ &fixture->error);
+
+ g_assert(fixture->error == NULL);
+
+ g_assert_cmpstr(fixture->expected, ==, fixture->actual);
+}
+
+/******************************************************************************
+ * Main!
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_type_init();
+
+ gplate_config_load_default();
+
+ g_test_add("/functions/include/simple",
+ TestGPlateIncludeFunctionFixture,
+ NULL,
+ test_gplate_include_function_setup,
+ test_gplate_include_function_simple,
+ test_gplate_include_function_teardown);
+
+ g_test_add("/functions/include/double",
+ TestGPlateIncludeFunctionFixture,
+ NULL,
+ test_gplate_include_function_setup,
+ test_gplate_include_function_double,
+ test_gplate_include_function_teardown);
+
+ return g_test_run();
+}
+
--- a/tests/templates/Makefile.am Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-EXTRA_DIST=\
- simple.gplate \
- simple-include.gplate
-
--- a/tests/templates/footer.gplate Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
- </body>
-</html>
--- a/tests/templates/header.gplate Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-<html>
- <head>
- <title>test</title>
- </head>
- <body>
--- a/tests/templates/html.gplate Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-{% include "header.gplate" %}in the body{% include "footer.gplate" %}
--- a/tests/templates/simple-include.gplate Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-inside the included file
--- a/tests/templates/simple.gplate Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-before the include
-{% include "simple-include.gplate" %}
-after the include
-
--- a/tests/test-include.c Sun Jul 04 15:35:33 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif /* HAVE_CONFIG_H */
-
-#include <check.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include <gplate/gplate.h>
-
-#include "test.h"
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-static GPlateTemplate *tplate = NULL;
-static GError *error = NULL;
-static gchar *msg = NULL;
-
-/******************************************************************************
- * Fixtures
- *****************************************************************************/
-static void
-simple_setup(void) {
- tplate = gplate_template_new();
-}
-
-static void
-simple_teardown(void) {
- g_object_unref(G_OBJECT(tplate));
-
- tplate = NULL;
-
- if(error)
- g_error_free(error);
- error = NULL;
-
- g_free(msg);
- msg = NULL;
-}
-
-/******************************************************************************
- * Simple Includes
- *****************************************************************************/
-START_TEST(test_include_simple_static)
- gchar *output = NULL, *e1 = NULL, *e2 = NULL;
- const gchar *expected =
- "before the include\n"
- "inside the included file\n\n"
- "after the include\n"
- "\n";
- gint r = 0;
-
- output = gplate_template_render_file(tplate, "templates/simple.gplate",
- &error);
-
- fail_unless(error == NULL,
- (error && error->message) ? error->message : "Unknown failed");
-
- r = g_utf8_collate(output, expected);
-
- e1 = g_strescape(output, NULL);
- e2 = g_strescape(expected, NULL);
- msg = g_strdup_printf("\ngot: '%s'\nwanted: '%s'\n", e1, e2);
-
- g_free(output);
- g_free(e1);
- g_free(e2);
-
- fail_unless(r == 0, msg);
-END_TEST
-
-START_TEST(test_include_html_header_footer)
- gchar *output = NULL, *e1 = NULL, *e2 = NULL;
- const gchar *expected =
- "<html>\n"
- "\t<head>\n"
- "\t\t<title>test</title>\n"
- "\t</head>\n"
- "\t<body>\n"
- "in the body"
- "\t</body>\n"
- "</html>\n\n";
- gint r = 0;
-
- output = gplate_template_render_file(tplate, "templates/html.gplate",
- &error);
-
- fail_unless(error == NULL,
- (error && error->message) ? error->message : "Unknown failure");
-
- r = g_utf8_collate(output, expected);
-
- e1 = g_strescape(output, NULL);
- e2 = g_strescape(expected, NULL);
- msg = g_strdup_printf("\ngot: '%s'\nwanted: '%s'\n", e1, e2);
-
- g_free(output);
- g_free(e1);
- g_free(e2);
-
- fail_unless(r == 0, msg);
-END_TEST
-
-/******************************************************************************
- * Exported
- *****************************************************************************/
-Suite *
-include_suite(void) {
- Suite *s = suite_create("Include Function Suite");
- TCase *tc = NULL;
-
- tc = tcase_create("Simple Includes");
- tcase_add_checked_fixture(tc, simple_setup, simple_teardown);
- tcase_add_test(tc, test_include_simple_static);
- tcase_add_test(tc, test_include_html_header_footer);
- suite_add_tcase(s, tc);
-
- return s;
-}
-