The start of moving testing from autotools and check to gtester and ctest
refs #11
--- a/CMakeLists.txt Sat Jun 26 13:20:31 2010 -0500
+++ b/CMakeLists.txt Sat Jun 26 13:20:57 2010 -0500
@@ -40,3 +40,4 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CTestTestfile.cmake Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,7 @@
+# CMake generated Testfile for +# Source directory: /home/grim/programming/gplate +# Build directory: /home/grim/programming/gplate +# This file includes the relevent testing commands required for +# testing this directory and lists subdirectories to be tested as well. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/CTestTestfile.cmake Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,1 @@
+SUBDIRS(functions tags variables) --- a/gplate/functions/CMakeLists.txt Sat Jun 26 13:20:31 2010 -0500
+++ b/gplate/functions/CMakeLists.txt Sat Jun 26 13:20:57 2010 -0500
@@ -1,3 +1,5 @@
set(GPLATE_FUNCTIONS_HEADERS
gplate-include-function.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/CTestTestfile.cmake Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,1 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/CMakeLists.txt Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,6 @@
+add_executable(test-for-function test-for-function.c) +target_link_libraries(test-for-function gplate) +add_test(ForFunction test-for-function) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/CTestTestfile.cmake Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,7 @@
+# CMake generated Testfile for +# Source directory: /home/grim/programming/gplate/gplate/functions/tests +# Build directory: /home/grim/programming/gplate/gplate/functions/tests +# This file includes the relevent testing commands required for +# testing this directory and lists subdirectories to be tested as well. +ADD_TEST(ForFunction "test-for-function") --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/test-for-function.c Sat Jun 26 13:20:57 2010 -0500
@@ -0,0 +1,172 @@
+#include <gplate/gplate.h> +#include <gplate/variables/gplate-dictionary-variable.h> +/****************************************************************************** + *****************************************************************************/ +} GPlateForFunctionTestData; + GPlateTemplate *template; + const gchar *template_string; + GPlateForFunctionTestData *data; +} GPlateForFunctionTestFixture; +/****************************************************************************** + *****************************************************************************/ +gplate_for_function_test_setup(GPlateForFunctionTestFixture *fixture, + fixture->template = gplate_template_new(); + fixture->dict = gplate_dictionary_variable_new("list"); + gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template), +gplate_for_function_test_teardown(GPlateForFunctionTestFixture *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); +/****************************************************************************** + *****************************************************************************/ +gplate_for_function_test(GPlateForFunctionTestFixture *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); +/****************************************************************************** + *****************************************************************************/ +gplate_for_function_test_zero_elements(GPlateForFunctionTestFixture *fixture, + gconstpointer user_data) + GPlateForFunctionTestData data[] = { + fixture->template_string = "{% for in in line %}{{ i }}{% endfor %}"; + fixture->expected = ""; + gplate_for_function_test(fixture); +gplate_for_function_test_one_element(GPlateForFunctionTestFixture *fixture, + gconstpointer user_data) + GPlateForFunctionTestData data[] = { + fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}"; + fixture->expected = "1"; + gplate_for_function_test(fixture); +gplate_for_function_test_two_elements(GPlateForFunctionTestFixture *fixture, + gconstpointer user_data) + GPlateForFunctionTestData data[] = { + fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}"; + fixture->expected = "AB"; + gplate_for_function_test(fixture); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + gplate_config_load_default(); + g_test_add("/functions/foo/zero_elements", + GPlateForFunctionTestFixture, + gplate_for_function_test_setup, + gplate_for_function_test_zero_elements, + gplate_for_function_test_teardown); + g_test_add("/functions/foo/one_element", + GPlateForFunctionTestFixture, + gplate_for_function_test_setup, + gplate_for_function_test_one_element, + gplate_for_function_test_teardown); + g_test_add("/functions/foo/two_elements", + GPlateForFunctionTestFixture, + gplate_for_function_test_setup, + gplate_for_function_test_two_elements, + gplate_for_function_test_teardown); --- a/tests/test-for-function.c Sat Jun 26 13:20:31 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-#endif /* HAVE_CONFIG_H */
-#include <gplate/gplate.h>
-/******************************************************************************
- *****************************************************************************/
-/******************************************************************************
- *****************************************************************************/
-static GPlateTemplate *tplate = NULL;
-static GPlateVariable *dict = NULL;
-static gchar *actual = NULL;
-/******************************************************************************
- *****************************************************************************/
- tplate = gplate_template_new();
- dict = gplate_dictionary_variable_new("list");
- gplate_collection_add_variable(GPLATE_COLLECTION(tplate), dict);
- g_object_unref(G_OBJECT(tplate));
- g_object_unref(G_OBJECT(dict));
-/******************************************************************************
- *****************************************************************************/
-for_test(ForData *fd, const gchar *tplate_string, const gchar *expected) {
- /* add the variables */
- for(i = 0, count = 0; fd[i].name; i++, count++)
- gplate_collection_add_string(dict, fd[i].name, fd[i].value);
- actual = gplate_template_render(tplate, tplate_string, NULL);
- test_string(expected, actual);
-/******************************************************************************
- *****************************************************************************/
-START_TEST(test_for_simple_zero_elements)
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "");
-START_TEST(test_for_simple_one_element)
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "1");
-START_TEST(test_for_simple_two_elements)
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "AB");
-/******************************************************************************
- *****************************************************************************/
- Suite *s = suite_create("For Function Suite");
- tc = tcase_create("Simple For Loops");
- tcase_add_checked_fixture(tc, simple_setup, simple_teardown);
- tcase_add_test(tc, test_for_simple_zero_elements);
- tcase_add_test(tc, test_for_simple_one_element);
- tcase_add_test(tc, test_for_simple_two_elements);
- suite_add_tcase(s, tc);