grim/gplate

Parents 981993805b19
Children 1213fc842268
the start of testing overhaul... Similiar to the main library, all the tests are separated by their function and then statically linked into the main testing executable
--- a/tests/CMakeLists.txt Mon Sep 03 18:45:07 2012 -0500
+++ b/tests/CMakeLists.txt Mon Sep 03 22:33:34 2012 -0500
@@ -1,30 +1,21 @@
-macro(add_gtest target)
- add_executable(${target} ${target}.c)
- target_link_libraries(${target} ${GLIB_LIBRARIES} gplate)
+add_subdirectory(tags)
- get_target_property(_output_name ${target} RUNTIME_OUTPUT_NAME)
- if(${_output_name})
- else(${_output_name})
- get_target_property(_output_name ${target} LOCATION)
- endif(${_output_name})
+add_executable(test-gplate test-gplate.c)
- list(APPEND TESTS ${_output_name})
-endmacro(add_gtest)
+target_link_libraries(test-gplate
+ ${GLIB_LIBRARIES}
+ gplate
+ test-gplate-tags
+)
-add_gtest(test-gplate-collection-interface)
-add_gtest(test-gplate-utility-functions)
-add_gtest(test-gplate-for-function)
-add_gtest(test-gplate-include-function)
-add_gtest(test-gplate-comment-tag)
-add_gtest(test-gplate-text-tag)
-add_gtest(test-gplate-variable-tag)
-add_gtest(test-variables)
-
+###############################################################################
+# Main Target
+###############################################################################
set(GTESTER_TESTS "${TESTS}")
set(GTESTER_LOG "testgplate.log")
add_custom_target(tests ALL
- COMMAND ${GTESTER} -k -verbose -o ${GTESTER_LOG} ${GTESTER_TESTS}
- DEPENDS ${GTESTER_TESTS}
+ COMMAND ${GTESTER} -k --verbose -o ${GTESTER_LOG} test-gplate
+ DEPENDS test-gplate
)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/CMakeLists.txt Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,17 @@
+set(TEST_GPLATE_TAGS_HEADERS
+ test-gplate-tag.h
+ test-gplate-text-tag.h
+)
+
+set(TEST_GPLATE_TAGS_SOURCES
+ test-gplate-tag.c
+ test-gplate-comment-tag.c
+ test-gplate-text-tag.c
+ test-gplate-variable-tag.c
+)
+
+add_library(test-gplate-tags STATIC
+ ${TEST_GPLATE_TAGS_HEADERS}
+ ${TEST_GPLATE_TAGS_SOURCES}
+)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/test-gplate-comment-tag.c Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,74 @@
+/*
+ * 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 <glib.h>
+
+#include "test-gplate-tag.h"
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_gplate_comment_tag_empty(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data, "{##}", "");
+}
+
+static void
+test_gplate_comment_tag_whitespace(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data, "{# #}", "");
+ test_gplate_tag_output(fixture, data, "{#\t#}", "");
+ test_gplate_tag_output(fixture, data, "{#\n#}", "");
+ test_gplate_tag_output(fixture, data, "{#\r#}", "");
+ test_gplate_tag_output(fixture, data, "{#\r\n#}", "");
+ test_gplate_tag_output(fixture, data, "{#\n\r#}", "");
+}
+
+static void
+test_gplate_comment_tag_simple(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data, "{# foo#}", "");
+ test_gplate_tag_output(fixture, data, "{#foo #}", "");
+ test_gplate_tag_output(fixture, data, "{#\tfoo#}", "");
+ test_gplate_tag_output(fixture, data, "{#foo\t#}", "");
+ test_gplate_tag_output(fixture, data, "{#\nfoo#}", "");
+ test_gplate_tag_output(fixture, data, "{#foo\n#}", "");
+ test_gplate_tag_output(fixture, data, "{#\rfoo#}", "");
+ test_gplate_tag_output(fixture, data, "{#foo\r#}", "");
+ test_gplate_tag_output(fixture, data, "{#\r\nfoo#}", "");
+ test_gplate_tag_output(fixture, data, "{#foo\r\n#}", "");
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+void
+test_gplate_comment_tag_add_tests(void) {
+ test_gplate_tag_add("/tags/comment/empty",
+ test_gplate_comment_tag_empty);
+ test_gplate_tag_add("/tags/comment/whitespace",
+ test_gplate_comment_tag_whitespace);
+ test_gplate_tag_add("/tags/comment/simple",
+ test_gplate_comment_tag_simple);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/test-gplate-tag.c Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,73 @@
+/*
+ * 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-tag.h"
+
+/******************************************************************************
+ * Fixtures
+ *****************************************************************************/
+void
+test_gplate_tag_setup(TestGPlateTagFixture *fixture, gconstpointer data) {
+ gplate_config_load_default();
+
+ fixture->template = gplate_template_new();
+}
+
+void
+test_gplate_tag_teardown(TestGPlateTagFixture *fixture, gconstpointer data) {
+ g_object_unref(fixture->template);
+ fixture->template = NULL;
+
+ if(fixture->error) {
+ g_error_free(fixture->error);
+ fixture->error = NULL;
+ }
+
+ g_free(fixture->actual);
+ fixture->actual = NULL;
+}
+
+/******************************************************************************
+ * Simple Tests
+ *****************************************************************************/
+void
+test_gplate_tag_output(TestGPlateTagFixture *fixture,
+ gconstpointer data,
+ const gchar *template_string,
+ const gchar *expected)
+{
+ fixture->template_string = template_string;
+ fixture->expected = expected;
+
+ fixture->actual = gplate_template_render(fixture->template,
+ fixture->template_string,
+ &fixture->error);
+
+ g_assert(fixture->error == NULL);
+
+ g_assert_cmpstr(fixture->expected, ==, fixture->actual);
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void
+test_gplate_tag_add_tests(void) {
+ test_gplate_text_tag_add_tests();
+ test_gplate_variable_tag_add_tests();
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/test-gplate-tag.h Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,58 @@
+/*
+ * 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_TAG_H
+#define TEST_GPLATE_TAG_H
+
+#include <gplate/gplate.h>
+
+#include <glib.h>
+
+#define test_gplate_tag_add(path, func) \
+ g_test_add((path), TestGPlateTagFixture, NULL, test_gplate_tag_setup, (func), test_gplate_tag_teardown)
+
+typedef struct _TestGPlateTagFixture TestGPlateTagFixture;
+
+typedef void (*TestGPlateTagFixtureFunc)(TestGPlateTagFixture *fixture, gconstpointer data);
+
+struct _TestGPlateTagFixture {
+ GPlateTemplate *template;
+ GError *error;
+
+ const gchar *template_string;
+
+ const gchar *expected;
+ gchar *actual;
+};
+
+G_BEGIN_DECLS
+
+void test_gplate_tag_setup(TestGPlateTagFixture *fixture, gconstpointer data);
+void test_gplate_tag_teardown(TestGPlateTagFixture *fixture, gconstpointer data);
+void test_gplate_tag_output(TestGPlateTagFixture *fixture, gconstpointer data, const gchar *template_string, const gchar *expected);
+
+void test_gplate_tag_add_tests(void);
+
+/* external prototypes */
+void test_gplate_comment_tag_add_tests(void);
+void test_gplate_text_tag_add_tests(void);
+void test_gplate_variable_tag_add_tests(void);
+
+G_END_DECLS
+
+#endif /* TEST_GPLATE_TAG_H */
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/test-gplate-text-tag.c Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,63 @@
+/*
+ * 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 <glib.h>
+
+#include "test-gplate-tag.h"
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_gplate_text_tag_syntax_plain(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data,
+ "simple template", "simple template");
+}
+
+static void
+test_gplate_text_tag_syntax_keywords(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data,
+ "extends if else endif for endfor",
+ "extends if else endif for endfor");
+}
+
+static void
+test_gplate_text_tag_syntax_keywords_case_sensitive(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_tag_output(fixture, data,
+ "EXteNds iF eLse enDif fOr enDFor",
+ "EXteNds iF eLse enDif fOr enDFor");
+}
+
+
+void
+test_gplate_text_tag_add_tests(void) {
+ test_gplate_tag_add("/tags/text/plain",
+ test_gplate_text_tag_syntax_plain);
+ test_gplate_tag_add("/tags/text/keywords",
+ test_gplate_text_tag_syntax_keywords);
+ test_gplate_tag_add("/tags/text/keywords_case_sensitive",
+ test_gplate_text_tag_syntax_keywords_case_sensitive);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/tags/test-gplate-variable-tag.c Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,229 @@
+/*
+ * 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 <glib.h>
+
+#include "test-gplate-tag.h"
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+test_gplate_variable_tag(TestGPlateTagFixture *fixture, gconstpointer data,
+ const gchar *template_string, const gchar *expected,
+ ...)
+{
+ va_list vargs;
+ const gchar *name = NULL, *value = NULL;
+
+ va_start(vargs, expected);
+ while((name = va_arg(vargs, const gchar *))) {
+ value = va_arg(vargs, const gchar *);
+
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ name, value);
+ }
+ va_end(vargs);
+
+ test_gplate_tag_output(fixture, data, template_string, expected);
+}
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{ foo }}", "foo",
+ "foo", "foo",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{ foo }}{{ bar }}", "foobar",
+ "foo", "foo",
+ "bar", "bar",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
+ "foo", "foo",
+ "bar", "bar",
+ "baz", "baz",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{\nfoo}}", "foo",
+ "foo", "foo",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{foo\n}}", "foo",
+ "foo", "foo",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "{{\nfoo\n}}", "foo",
+ "foo", "foo",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "foo '{{ bar }}' baz", "foo 'bar' baz",
+ "bar", "bar",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
+ "bar", "bar",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "foo \"{{ bar }}' baz", "foo \"bar' baz",
+ "bar", "bar",
+ NULL);
+
+ test_gplate_variable_tag(fixture, data,
+ "foo '{{ bar }}\" baz", "foo 'bar\" baz",
+ "bar", "bar",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_two_vars_one_block(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ test_gplate_variable_tag(fixture, data,
+ "one {{ two five }} three",
+ "one 2 three",
+ "two", "2",
+ "five", "5",
+ NULL);
+}
+
+static void
+test_gplate_variable_tag_nested_single(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ GPlateVariable *dict = gplate_dictionary_variable_new("foo");
+
+ gplate_collection_add_string(GPLATE_COLLECTION(dict),
+ "bar", "baz");
+
+ test_gplate_tag_output(fixture, data, "{{ foo.bar }}", "baz");
+}
+
+static void
+test_gplate_variable_tag_nested_double(TestGPlateTagFixture *fixture,
+ gconstpointer data)
+{
+ GPlateVariable *dict1 = gplate_dictionary_variable_new("foo");
+ GPlateVariable *dict2 = gplate_dictionary_variable_new("bar");
+
+ gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template),
+ dict1);
+ gplate_collection_add_variable(GPLATE_COLLECTION(dict1), dict2);
+ gplate_collection_add_string(GPLATE_COLLECTION(dict2),
+ "baz", "42");
+
+ test_gplate_tag_output(fixture, data, "{{ foo.bar.baz }}", "42");
+}
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+void
+test_gplate_variable_tag_add_tests(void) {
+ test_gplate_tag_add("/tags/variable/single",
+ test_gplate_variable_tag_single);
+
+ test_gplate_tag_add("/tags/variable/double",
+ test_gplate_variable_tag_double);
+
+ test_gplate_tag_add("/tags/variable/tripple",
+ test_gplate_variable_tag_tripple);
+
+ test_gplate_tag_add("/tags/variable/newline_prefix",
+ test_gplate_variable_tag_newline_prefix);
+
+ test_gplate_tag_add("/tags/variable/newline_suffix",
+ test_gplate_variable_tag_newline_suffix);
+
+ test_gplate_tag_add("/tags/variable/newline_wrapped",
+ test_gplate_variable_tag_newline_wrapped);
+
+ test_gplate_tag_add("/tags/variable/quotes/single",
+ test_gplate_variable_tag_single_quotes);
+
+ test_gplate_tag_add("/tags/variable/quotes/double",
+ test_gplate_variable_tag_double_quotes);
+
+ test_gplate_tag_add("/tags/variable/quotes/mixed",
+ test_gplate_variable_tag_mixed_quotes);
+
+ test_gplate_tag_add("/tags/variable/two_vars_one_block",
+ test_gplate_variable_tag_two_vars_one_block);
+
+ test_gplate_tag_add("/tags/variables/nested/single",
+ test_gplate_variable_tag_nested_single);
+
+ test_gplate_tag_add("/tags/variable/nested/double",
+ test_gplate_variable_tag_nested_double);
+}
+
--- a/tests/test-gplate-comment-tag.c Mon Sep 03 18:45:07 2012 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +0,0 @@
-/*
- * 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 <glib.h>
-
-#include "test-gplate-tag.h"
-
-/******************************************************************************
- * Tests
- *****************************************************************************/
-static void
-test_gplate_comment_tag_empty(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data, "{##}", "");
-}
-
-static void
-test_gplate_comment_tag_whitespace(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data, "{# #}", "");
- test_gplate_tag_output(fixture, data, "{#\t#}", "");
- test_gplate_tag_output(fixture, data, "{#\n#}", "");
- test_gplate_tag_output(fixture, data, "{#\r#}", "");
- test_gplate_tag_output(fixture, data, "{#\r\n#}", "");
- test_gplate_tag_output(fixture, data, "{#\n\r#}", "");
-}
-
-static void
-test_gplate_comment_tag_simple(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data, "{# foo#}", "");
- test_gplate_tag_output(fixture, data, "{#foo #}", "");
- test_gplate_tag_output(fixture, data, "{#\tfoo#}", "");
- test_gplate_tag_output(fixture, data, "{#foo\t#}", "");
- test_gplate_tag_output(fixture, data, "{#\nfoo#}", "");
- test_gplate_tag_output(fixture, data, "{#foo\n#}", "");
- test_gplate_tag_output(fixture, data, "{#\rfoo#}", "");
- test_gplate_tag_output(fixture, data, "{#foo\r#}", "");
- test_gplate_tag_output(fixture, data, "{#\r\nfoo#}", "");
- test_gplate_tag_output(fixture, data, "{#foo\r\n#}", "");
-}
-
-/******************************************************************************
- * Main
- *****************************************************************************/
-gint
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
-
- g_type_init();
-
- gplate_config_load_default();
-
- test_gplate_tag_add("/tags/comment/empty",
- test_gplate_comment_tag_empty);
- test_gplate_tag_add("/tags/comment/whitespace",
- test_gplate_comment_tag_whitespace);
- test_gplate_tag_add("/tags/comment/simple",
- test_gplate_comment_tag_simple);
-
- return g_test_run();
-}
-
--- a/tests/test-gplate-tag.c Mon Sep 03 18:45:07 2012 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * 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-tag.h"
-
-void
-test_gplate_tag_setup(TestGPlateTagFixture *fixture, gconstpointer data) {
- fixture->template = gplate_template_new();
-}
-
-void
-test_gplate_tag_teardown(TestGPlateTagFixture *fixture, gconstpointer data) {
- g_object_unref(fixture->template);
- fixture->template = NULL;
-
- if(fixture->error) {
- g_error_free(fixture->error);
- fixture->error = NULL;
- }
-
- g_free(fixture->actual);
- fixture->actual = NULL;
-}
-
-void
-test_gplate_tag_output(TestGPlateTagFixture *fixture,
- gconstpointer data,
- const gchar *template_string,
- const gchar *expected)
-{
- fixture->template_string = template_string;
- fixture->expected = expected;
-
- fixture->actual = gplate_template_render(fixture->template,
- fixture->template_string,
- &fixture->error);
-
- g_assert(fixture->error == NULL);
-
- g_assert_cmpstr(fixture->expected, ==, fixture->actual);
-}
-
--- a/tests/test-gplate-tag.h Mon Sep 03 18:45:07 2012 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/*
- * 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_TAG_H
-#define TEST_GPLATE_TAG_H
-
-#include <gplate/gplate.h>
-
-#include <glib.h>
-
-#define test_gplate_tag_add(path, func) \
- g_test_add((path), TestGPlateTagFixture, NULL, test_gplate_tag_setup, (func), test_gplate_tag_teardown)
-
-typedef struct _TestGPlateTagFixture TestGPlateTagFixture;
-
-typedef void (*TestGPlateTagFixtureFunc)(TestGPlateTagFixture *fixture, gconstpointer data);
-
-struct _TestGPlateTagFixture {
- GPlateTemplate *template;
- GError *error;
-
- const gchar *template_string;
-
- const gchar *expected;
- gchar *actual;
-};
-
-G_BEGIN_DECLS
-
-void test_gplate_tag_setup(TestGPlateTagFixture *fixture, gconstpointer data);
-void test_gplate_tag_teardown(TestGPlateTagFixture *fixture, gconstpointer data);
-void test_gplate_tag_output(TestGPlateTagFixture *fixture, gconstpointer data, const gchar *template_string, const gchar *expected);
-
-G_END_DECLS
-
-#endif /* TEST_GPLATE_TAG_H */
-
--- a/tests/test-gplate-text-tag.c Mon Sep 03 18:45:07 2012 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/*
- * 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 <glib.h>
-
-#include "test-gplate-tag.h"
-
-/******************************************************************************
- * Tests
- *****************************************************************************/
-static void
-test_gplate_text_tag_syntax_plain(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data,
- "simple template", "simple template");
-}
-
-static void
-test_gplate_text_tag_syntax_keywords(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data,
- "extends if else endif for endfor",
- "extends if else endif for endfor");
-}
-
-static void
-test_gplate_text_tag_syntax_keywords_case_sensitive(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_tag_output(fixture, data,
- "EXteNds iF eLse enDif fOr enDFor",
- "EXteNds iF eLse enDif fOr enDFor");
-}
-
-/******************************************************************************
- * Main
- *****************************************************************************/
-gint
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
-
- g_type_init();
-
- gplate_config_load_default();
-
- test_gplate_tag_add("/tags/text/plain",
- test_gplate_text_tag_syntax_plain);
- test_gplate_tag_add("/tags/text/keywords",
- test_gplate_text_tag_syntax_keywords);
- test_gplate_tag_add("/tags/text/keywords_case_sensitive",
- test_gplate_text_tag_syntax_keywords_case_sensitive);
-
- return g_test_run();
-}
-
--- a/tests/test-gplate-variable-tag.c Mon Sep 03 18:45:07 2012 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,237 +0,0 @@
-/*
- * 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 <glib.h>
-
-#include "test-gplate-tag.h"
-
-/******************************************************************************
- * Helpers
- *****************************************************************************/
-static void
-test_gplate_variable_tag(TestGPlateTagFixture *fixture, gconstpointer data,
- const gchar *template_string, const gchar *expected,
- ...)
-{
- va_list vargs;
- const gchar *name = NULL, *value = NULL;
-
- va_start(vargs, expected);
- while((name = va_arg(vargs, const gchar *))) {
- value = va_arg(vargs, const gchar *);
-
- gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
- name, value);
- }
- va_end(vargs);
-
- test_gplate_tag_output(fixture, data, template_string, expected);
-}
-
-/******************************************************************************
- * Tests
- *****************************************************************************/
-static void
-test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{ foo }}", "foo",
- "foo", "foo",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{ foo }}{{ bar }}", "foobar",
- "foo", "foo",
- "bar", "bar",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
- "foo", "foo",
- "bar", "bar",
- "baz", "baz",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{\nfoo}}", "foo",
- "foo", "foo",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{foo\n}}", "foo",
- "foo", "foo",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "{{\nfoo\n}}", "foo",
- "foo", "foo",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "foo '{{ bar }}' baz", "foo 'bar' baz",
- "bar", "bar",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
- "bar", "bar",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "foo \"{{ bar }}' baz", "foo \"bar' baz",
- "bar", "bar",
- NULL);
-
- test_gplate_variable_tag(fixture, data,
- "foo '{{ bar }}\" baz", "foo 'bar\" baz",
- "bar", "bar",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_two_vars_one_block(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- test_gplate_variable_tag(fixture, data,
- "one {{ two five }} three",
- "one 2 three",
- "two", "2",
- "five", "5",
- NULL);
-}
-
-static void
-test_gplate_variable_tag_nested_single(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- GPlateVariable *dict = gplate_dictionary_variable_new("foo");
-
- gplate_collection_add_string(GPLATE_COLLECTION(dict),
- "bar", "baz");
-
- test_gplate_tag_output(fixture, data, "{{ foo.bar }}", "baz");
-}
-
-static void
-test_gplate_variable_tag_nested_double(TestGPlateTagFixture *fixture,
- gconstpointer data)
-{
- GPlateVariable *dict1 = gplate_dictionary_variable_new("foo");
- GPlateVariable *dict2 = gplate_dictionary_variable_new("bar");
-
- gplate_collection_add_variable(GPLATE_COLLECTION(fixture->template),
- dict1);
- gplate_collection_add_variable(GPLATE_COLLECTION(dict1), dict2);
- gplate_collection_add_string(GPLATE_COLLECTION(dict2),
- "baz", "42");
-
- test_gplate_tag_output(fixture, data, "{{ foo.bar.baz }}", "42");
-}
-
-/******************************************************************************
- * Main
- *****************************************************************************/
-gint
-main(gint argc, gchar **argv) {
- g_test_init(&argc, &argv, NULL);
-
- g_type_init();
-
- gplate_config_load_default();
-
- test_gplate_tag_add("/tags/variable/single",
- test_gplate_variable_tag_single);
-
- test_gplate_tag_add("/tags/variable/double",
- test_gplate_variable_tag_double);
-
- test_gplate_tag_add("/tags/variable/tripple",
- test_gplate_variable_tag_tripple);
-
- test_gplate_tag_add("/tags/variable/newline_prefix",
- test_gplate_variable_tag_newline_prefix);
-
- test_gplate_tag_add("/tags/variable/newline_suffix",
- test_gplate_variable_tag_newline_suffix);
-
- test_gplate_tag_add("/tags/variable/newline_wrapped",
- test_gplate_variable_tag_newline_wrapped);
-
- test_gplate_tag_add("/tags/variable/quotes/single",
- test_gplate_variable_tag_single_quotes);
-
- test_gplate_tag_add("/tags/variable/quotes/double",
- test_gplate_variable_tag_double_quotes);
-
- test_gplate_tag_add("/tags/variable/quotes/mixed",
- test_gplate_variable_tag_mixed_quotes);
-
- test_gplate_tag_add("/tags/variable/two_vars_one_block",
- test_gplate_variable_tag_two_vars_one_block);
-
- test_gplate_tag_add("/tags/variables/nested/single",
- test_gplate_variable_tag_nested_single);
-
- test_gplate_tag_add("/tags/variable/nested/double",
- test_gplate_variable_tag_nested_double);
-
- return g_test_run();
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-gplate.c Mon Sep 03 22:33:34 2012 -0500
@@ -0,0 +1,35 @@
+/*
+ * 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 <glib.h>
+
+#include <gplate.h>
+
+#include "tags/test-gplate-tag.h"
+
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_type_init();
+
+ test_gplate_tag_add_tests();
+
+ return g_test_run();
+}
+