grim/gplate

Parents 6611e9570ec2
Children 13b5031b2846
guess there wasn't a whole lot left for the test name standardization

closes #15
--- a/gplate/functions/tests/CMakeLists.txt Sun Jul 04 03:36:01 2010 -0500
+++ b/gplate/functions/tests/CMakeLists.txt Sun Jul 04 03:40:27 2010 -0500
@@ -1,6 +1,11 @@
enable_testing()
-add_executable(test-for-function test-for-function.c)
-target_link_libraries(test-for-function gplate)
-add_test(GPlateForFunction test-for-function)
+add_executable(test-gplate-for-function test-gplate-for-function.c)
+target_link_libraries(test-gplate-for-function gplate)
+list(APPEND FUNCTION_TESTS test-gplate-for-function)
+add_test(GPlateFunctions
+ ${GTESTER} -k --verbose -o test-gplate-function.log
+ ${FUNCTION_TESTS}
+)
+
--- a/gplate/functions/tests/test-for-function.c Sun Jul 04 03:36:01 2010 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/*
- * 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 <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();
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/functions/tests/test-gplate-for-function.c Sun Jul 04 03:40:27 2010 -0500
@@ -0,0 +1,188 @@
+/*
+ * 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 <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/gplate/tests/CMakeLists.txt Sun Jul 04 03:36:01 2010 -0500
+++ b/gplate/tests/CMakeLists.txt Sun Jul 04 03:40:27 2010 -0500
@@ -6,7 +6,7 @@
add_executable(test-gplate-collection-interface test-gplate-collection-interface.c)
target_link_libraries(test-gplate-collection-interface gplate)
add_test(GPlateCollectionInterface
- gtester -k --verbose -o test-gplate-collection-interface.log
+ ${GTESTER} -k --verbose -o test-gplate-collection-interface.log
test-gplate-collection-interface
)
@@ -16,7 +16,7 @@
add_executable(test-gplate-utility-functions test-gplate-utility-functions.c)
target_link_libraries(test-gplate-utility-functions gplate)
add_test(GPlateUtilityFunctions
- gtester -k --verbose -o test-gplate-utility-functions.log
+ ${GTESTER} -k --verbose -o test-gplate-utility-functions.log
test-gplate-utility-functions
)