grim/gplate

Parents 66423b8da85b
Children 8eb812e8cbb5
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 @@
add_subdirectory(gplate)
+enable_testing()
--- /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.
+SUBDIRS(gplate)
--- /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 @@
+add_subdirectory(tests)
+
set(GPLATE_FUNCTIONS_HEADERS
gplate-for-function.h
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 @@
+SUBDIRS(tests)
--- /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 @@
+enable_testing()
+
+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>
+
+#include <glib.h>
+
+/******************************************************************************
+ * Structs
+ *****************************************************************************/
+typedef struct {
+ const gchar *name;
+ const gchar *value;
+} GPlateForFunctionTestData;
+
+typedef struct {
+ GPlateTemplate *template;
+
+ GPlateVariable *dict;
+
+ const gchar *template_string;
+
+ gchar *actual;
+ const gchar *expected;
+
+ GError *error;
+
+ GPlateForFunctionTestData *data;
+} GPlateForFunctionTestFixture;
+
+/******************************************************************************
+ * Fixtures
+ *****************************************************************************/
+static void
+gplate_for_function_test_setup(GPlateForFunctionTestFixture *fixture,
+ gconstpointer d)
+{
+ fixture->template = gplate_template_new();
+ fixture->dict = gplate_dictionary_variable_new("list");
+
+ gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template),
+ fixture->dict);
+}
+
+static void
+gplate_for_function_test_teardown(GPlateForFunctionTestFixture *fixture,
+ gconstpointer d)
+{
+ g_object_unref(fixture->template);
+ fixture->template = NULL;
+
+ g_object_unref(fixture->dict);
+ fixture->dict = NULL;
+
+ g_free(fixture->actual);
+ fixture->actual = NULL;
+
+ fixture->expected = NULL;
+
+ if(fixture->error) {
+ g_error_free(fixture->error);
+ fixture->error = NULL;
+ }
+}
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+gplate_for_function_test(GPlateForFunctionTestFixture *fixture) {
+ gint i = 0;
+
+ /* add the variables */
+ for(i = 0; fixture->data[i].name; i++) {
+ gplate_collection_add_string(fixture->dict,
+ fixture->data[i].name,
+ fixture->data[i].value);
+ }
+
+ fixture->actual = gplate_template_render(fixture->template,
+ fixture->template_string,
+ &fixture->error);
+
+ g_assert(fixture->error == NULL);
+
+ g_assert_cmpstr(fixture->expected, ==, fixture->actual);
+}
+
+/******************************************************************************
+ * Simple For's
+ *****************************************************************************/
+static void
+gplate_for_function_test_zero_elements(GPlateForFunctionTestFixture *fixture,
+ gconstpointer user_data)
+{
+ GPlateForFunctionTestData data[] = {
+ { NULL, NULL },
+ };
+
+ fixture->data = data;
+ fixture->template_string = "{% for in in line %}{{ i }}{% endfor %}";
+ fixture->expected = "";
+
+ gplate_for_function_test(fixture);
+}
+
+static void
+gplate_for_function_test_one_element(GPlateForFunctionTestFixture *fixture,
+ gconstpointer user_data)
+{
+ GPlateForFunctionTestData data[] = {
+ { "one", "1" },
+ { NULL, NULL },
+ };
+
+ fixture->data = data;
+ fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}";
+ fixture->expected = "1";
+
+ gplate_for_function_test(fixture);
+}
+
+static void
+gplate_for_function_test_two_elements(GPlateForFunctionTestFixture *fixture,
+ gconstpointer user_data)
+{
+ GPlateForFunctionTestData data[] = {
+ { "a", "A" },
+ { "b", "B" },
+ { NULL, NULL },
+ };
+
+ fixture->data = data;
+ fixture->template_string = "{% for i in list %}{{ i }}{% endfor %}";
+ fixture->expected = "AB";
+
+ gplate_for_function_test(fixture);
+}
+
+/******************************************************************************
+ * Main!
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_type_init();
+
+ gplate_config_load_default();
+
+ g_test_add("/functions/foo/zero_elements",
+ GPlateForFunctionTestFixture,
+ NULL,
+ gplate_for_function_test_setup,
+ gplate_for_function_test_zero_elements,
+ gplate_for_function_test_teardown);
+
+ g_test_add("/functions/foo/one_element",
+ GPlateForFunctionTestFixture,
+ NULL,
+ gplate_for_function_test_setup,
+ gplate_for_function_test_one_element,
+ gplate_for_function_test_teardown);
+
+ g_test_add("/functions/foo/two_elements",
+ GPlateForFunctionTestFixture,
+ NULL,
+ gplate_for_function_test_setup,
+ gplate_for_function_test_two_elements,
+ gplate_for_function_test_teardown);
+
+ return g_test_run();
+}
+
--- 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 @@
-#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"
-
-/******************************************************************************
- * Structs
- *****************************************************************************/
-typedef struct {
- const gchar *name;
- const gchar *value;
-} ForData;
-
-/******************************************************************************
- * Globals
- *****************************************************************************/
-static GPlateTemplate *tplate = NULL;
-static GPlateVariable *dict = NULL;
-static gchar *actual = NULL;
-
-/******************************************************************************
- * Fixtures
- *****************************************************************************/
-static void
-simple_setup(void) {
- tplate = gplate_template_new();
-
- dict = gplate_dictionary_variable_new("list");
- gplate_collection_add_variable(GPLATE_COLLECTION(tplate), dict);
-}
-
-static void
-simple_teardown(void) {
- g_object_unref(G_OBJECT(tplate));
- g_object_unref(G_OBJECT(dict));
-
- g_free(actual);
- actual = NULL;
-}
-
-/******************************************************************************
- * Helpers
- *****************************************************************************/
-static void
-for_test(ForData *fd, const gchar *tplate_string, const gchar *expected) {
- gint i = 0, count = 0;
-
- /* 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);
-}
-
-/******************************************************************************
- * Simple For's
- *****************************************************************************/
-START_TEST(test_for_simple_zero_elements)
- ForData fd[] = {
- { NULL, NULL },
- };
-
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "");
-END_TEST
-
-START_TEST(test_for_simple_one_element)
- ForData fd[] = {
- { "one", "1" },
- { NULL, NULL },
- };
-
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "1");
-END_TEST
-
-START_TEST(test_for_simple_two_elements)
- ForData fd[] = {
- { "a", "A" },
- { "b", "B" },
- { NULL, NULL },
- };
-
- for_test(fd, "{% for i in list %}{{ i }}{% endfor %}", "AB");
-END_TEST
-
-/******************************************************************************
- * Exported
- *****************************************************************************/
-Suite *
-for_suite(void) {
- Suite *s = suite_create("For Function Suite");
- TCase *tc = NULL;
-
- 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);
-
- return s;
-}
-