added functions to the new testing stuff
--- a/tests/CMakeLists.txt Mon Sep 03 22:33:34 2012 -0500
+++ b/tests/CMakeLists.txt Tue Sep 04 01:26:16 2012 -0500
@@ -1,3 +1,4 @@
+add_subdirectory(functions) add_executable(test-gplate test-gplate.c)
@@ -5,6 +6,7 @@
target_link_libraries(test-gplate
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/functions/CMakeLists.txt Tue Sep 04 01:26:16 2012 -0500
@@ -0,0 +1,15 @@
+set(TEST_GPLATE_FUNCTIONS_HEADERS + test-gplate-functions.h +set(TEST_GPLATE_FUNCTIONS_SOURCES + test-gplate-functions.c + test-gplate-for-function.c + test-gplate-include-function.c +add_library(test-gplate-functions STATIC + ${TEST_GPLATE_FUNCTIONS_HEADERS} + ${TEST_GPLATE_FUNCTIONS_SOURCES} --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/functions/test-gplate-for-function.c Tue Sep 04 01:26:16 2012 -0500
@@ -0,0 +1,181 @@
+ * GPlate - GObject based templating library + * Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com> + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This library 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. +#include <gplate/gplate.h> +#include <gplate/variables/gplate-dictionary-variable.h> +/****************************************************************************** + *****************************************************************************/ +} TestGPlateForFunctionData; + GPlateTemplate *template; + const gchar *template_string; + TestGPlateForFunctionData *data; +} TestGPlateForFunctionFixture; +/****************************************************************************** + *****************************************************************************/ +test_gplate_for_function_setup(TestGPlateForFunctionFixture *fixture, + fixture->template = gplate_template_new(); + fixture->dict = gplate_dictionary_variable_new("list"); + gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template), +test_gplate_for_function_teardown(TestGPlateForFunctionFixture *fixture, + g_object_unref(fixture->template); + fixture->template = NULL; + g_object_unref(fixture->dict); + g_free(fixture->actual); + fixture->actual = NULL; + fixture->expected = NULL; + g_error_free(fixture->error); +/****************************************************************************** + *****************************************************************************/ +test_gplate_for_function(TestGPlateForFunctionFixture *fixture) { + /* add the variables */ + for(i = 0; fixture->data[i].name; i++) { + gplate_collection_add_string(fixture->dict, + fixture->data[i].value); + fixture->actual = gplate_template_render(fixture->template, + fixture->template_string, + g_assert(fixture->error == NULL); + g_assert_cmpstr(fixture->expected, ==, fixture->actual); +/****************************************************************************** + *****************************************************************************/ +test_gplate_for_function_zero_elements(TestGPlateForFunctionFixture *fixture, + gconstpointer user_data) + TestGPlateForFunctionData data[] = { + fixture->template_string = "{% for in in line %}{{ i }}{% endfor %}"; + fixture->expected = ""; + test_gplate_for_function(fixture); +test_gplate_for_function_one_element(TestGPlateForFunctionFixture *fixture, + gconstpointer user_data) + TestGPlateForFunctionData data[] = { + fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}"; + fixture->expected = "1"; + test_gplate_for_function(fixture); +test_gplate_for_function_two_elements(TestGPlateForFunctionFixture *fixture, + gconstpointer user_data) + TestGPlateForFunctionData data[] = { + fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}"; + fixture->expected = "AB"; + test_gplate_for_function(fixture); +/****************************************************************************** + *****************************************************************************/ +test_gplate_for_function_add_tests(void) { + g_test_add("/functions/foo/zero_elements", + TestGPlateForFunctionFixture, + test_gplate_for_function_setup, + test_gplate_for_function_zero_elements, + test_gplate_for_function_teardown); + g_test_add("/functions/foo/one_element", + TestGPlateForFunctionFixture, + test_gplate_for_function_setup, + test_gplate_for_function_one_element, + test_gplate_for_function_teardown); + g_test_add("/functions/foo/two_elements", + TestGPlateForFunctionFixture, + test_gplate_for_function_setup, + test_gplate_for_function_two_elements, + test_gplate_for_function_teardown); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/functions/test-gplate-functions.c Tue Sep 04 01:26:16 2012 -0500
@@ -0,0 +1,29 @@
+ * GPlate - GObject based templating library + * Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com> + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This library 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. +#include "test-gplate-functions.h" +/****************************************************************************** + *****************************************************************************/ +test_gplate_functions_add_tests(void) { + test_gplate_for_function_add_tests(); + test_gplate_include_function_add_tests(); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/functions/test-gplate-functions.h Tue Sep 04 01:26:16 2012 -0500
@@ -0,0 +1,36 @@
+ * GPlate - GObject based templating library + * Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com> + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This library 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. +#ifndef TEST_GPLATE_FUNCTIONS_H +#define TEST_GPLATE_FUNCTIONS_H +#include <gplate/gplate.h> +void test_gplate_functions_add_tests(void); +/* external prototypes */ +void test_gplate_for_function_add_tests(void); +void test_gplate_include_function_add_tests(void); +#endif /* TEST_GPLATE_FUNCTIONS_H */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/functions/test-gplate-include-function.c Tue Sep 04 01:26:16 2012 -0500
@@ -0,0 +1,124 @@
+ * GPlate - GObject based templating library + * Copyright (C) 2007-2012 Gary Kramlich <grim@reaperworld.com> + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This library 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 Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see <http://www.gnu.org/licenses/>. +#include <gplate/gplate.h> +/****************************************************************************** + *****************************************************************************/ + GPlateTemplate *template; + const gchar *template_string; +} TestGPlateIncludeFunctionFixture; +/****************************************************************************** + *****************************************************************************/ +test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture, + fixture->template = gplate_template_new(); +test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture, + g_object_unref(fixture->template); + fixture->template = NULL; + g_free(fixture->actual); + fixture->actual = NULL; + fixture->expected = NULL; + g_error_free(fixture->error); +/****************************************************************************** + *****************************************************************************/ +test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture, + fixture->expected = "including\nincluded!\ndone"; + fixture->actual = gplate_template_render_file(fixture->template, + "templates/simple.gplate", + g_assert(fixture->error == NULL); + g_assert_cmpstr(fixture->expected, ==, fixture->actual); +test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture, + fixture->expected = " \ + fixture->actual = gplate_template_render_file(fixture->template, + "templates/html.gplate", + g_assert(fixture->error == NULL); + g_assert_cmpstr(fixture->expected, ==, fixture->actual); +/****************************************************************************** + *****************************************************************************/ +test_gplate_include_function_add_tests(void) { + g_test_add("/functions/include/simple", + TestGPlateIncludeFunctionFixture, + test_gplate_include_function_setup, + test_gplate_include_function_simple, + test_gplate_include_function_teardown); + g_test_add("/functions/include/double", + TestGPlateIncludeFunctionFixture, + test_gplate_include_function_setup, + test_gplate_include_function_double, + test_gplate_include_function_teardown); --- a/tests/test-gplate.c Mon Sep 03 22:33:34 2012 -0500
+++ b/tests/test-gplate.c Tue Sep 04 01:26:16 2012 -0500
@@ -28,6 +28,7 @@
+ test_gplate_functions_add_tests(); test_gplate_tag_add_tests();