--- a/gplate/tags/tests/CMakeLists.txt Sat Jun 26 15:25:18 2010 -0500
+++ b/gplate/tags/tests/CMakeLists.txt Fri Jul 02 02:56:50 2010 -0500
@@ -1,6 +1,18 @@
+# define the static library for tag testing +add_library(gplate-tag-test STATIC +target_link_libraries(gplate-tag-test gplate) +# add the text tag tests add_executable(test-text-tag test-text-tag.c)
-target_link_libraries(test-text-tag gplate)
+target_link_libraries(test-text-tag gplate-tag-test) add_test(GPlateTextTag test-text-tag)
+# add the variable tag tests +add_executable(test-variable-tag test-variable-tag.c) +target_link_libraries(test-variable-tag gplate-tag-test) +add_test(GPlateVariableTag test-variable-tag) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/tags/tests/gplate-tag-test.c Fri Jul 02 02:56:50 2010 -0500
@@ -0,0 +1,32 @@
+#include "gplate-tag-test.h" +gplate_tag_test_setup(GPlateTagTestFixture *fixture, gconstpointer data) { + fixture->template = gplate_template_new(); +gplate_tag_test_teardown(GPlateTagTestFixture *fixture, gconstpointer data) { + g_object_unref(fixture->template); + fixture->template = NULL; + g_error_free(fixture->error); + g_free(fixture->actual); + fixture->actual = NULL; +gplate_tag_test_output(GPlateTagTestFixture *fixture, gconstpointer data) { + fixture->actual = gplate_template_render(fixture->template, + fixture->template_string, + g_assert(fixture->error == NULL); + g_assert_cmpstr(fixture->expected, ==, fixture->actual); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/tags/tests/gplate-tag-test.h Fri Jul 02 02:56:50 2010 -0500
@@ -0,0 +1,33 @@
+#ifndef GPLATE_TAG_TEST_H +#define GPLATE_TAG_TEST_H +#include <gplate/gplate.h> +#define gplate_tag_test_add(path, func) \ + g_test_add((path), GPlateTagTestFixture, NULL, gplate_tag_test_setup, (func), gplate_tag_test_teardown) +typedef struct _GPlateTagTestFixture GPlateTagTestFixture; +typedef void (*GPlateTagTestFixtureFunc)(GPlateTagTestFixture *fixture, gconstpointer data); +struct _GPlateTagTestFixture { + GPlateTemplate *template; + const gchar *template_string; +void gplate_tag_test_setup(GPlateTagTestFixture *fixture, gconstpointer data); +void gplate_tag_test_teardown(GPlateTagTestFixture *fixture, gconstpointer data); +void gplate_tag_test_output(GPlateTagTestFixture *fixture, gconstpointer data); +#endif /* GPLATE_TAG_TEST_H */ --- a/gplate/tags/tests/test-text-tag.c Sat Jun 26 15:25:18 2010 -0500
+++ b/gplate/tags/tests/test-text-tag.c Fri Jul 02 02:56:50 2010 -0500
@@ -2,86 +2,39 @@
-/******************************************************************************
- *****************************************************************************/
- GPlateTemplate *template;
- const gchar *template_string;
-} GPlateTextTagTestFixture;
-gplate_text_tag_test_setup(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
- fixture->template = gplate_template_new();
-gplate_text_tag_test_teardown(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
- g_object_unref(fixture->template);
- g_error_free(fixture->error);
- g_free(fixture->actual);
- fixture->actual = NULL;
-/******************************************************************************
- *****************************************************************************/
-gplate_text_tag_test_output(GPlateTextTagTestFixture *fixture) {
- fixture->actual = gplate_template_render(fixture->template,
- fixture->template_string,
- g_assert(fixture->error == NULL);
- g_assert_cmpstr(fixture->expected, ==, fixture->actual);
+#include "gplate-tag-test.h" /******************************************************************************
*****************************************************************************/
-gplate_text_tag_test_syntax_plain(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_plain(GPlateTagTestFixture *fixture, fixture->template_string = "simple template";
fixture->expected = "simple template";
- gplate_text_tag_test_output(fixture);
+ gplate_tag_test_output(fixture, data); -gplate_text_tag_test_syntax_keywords(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_keywords(GPlateTagTestFixture *fixture, fixture->template_string = "extends if else endif for endfor";
fixture->expected = "extends if else endif for endfor";
- gplate_text_tag_test_output(fixture);
+ gplate_tag_test_output(fixture, data); -gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTagTestFixture *fixture, fixture->template_string = "EXteNds iF eLse enDif fOr enDFor";
fixture->expected = "EXteNds iF eLse enDif fOr enDFor";
- gplate_text_tag_test_output(fixture);
+ gplate_tag_test_output(fixture, data); /******************************************************************************
@@ -95,26 +48,12 @@
gplate_config_load_default();
- g_test_add("/tags/text/plain",
- GPlateTextTagTestFixture,
- gplate_text_tag_test_setup,
- gplate_text_tag_test_syntax_plain,
- gplate_text_tag_test_teardown);
- g_test_add("/tags/text/keywords",
- GPlateTextTagTestFixture,
- gplate_text_tag_test_setup,
- gplate_text_tag_test_syntax_keywords,
- gplate_text_tag_test_teardown);
- g_test_add("/tags/text/keywords_case_sensitive",
- GPlateTextTagTestFixture,
- gplate_text_tag_test_setup,
- gplate_text_tag_test_syntax_keywords_case_sensitive,
- gplate_text_tag_test_teardown);
+ gplate_tag_test_add("/tags/text/plain", + gplate_text_tag_test_syntax_plain); + gplate_tag_test_add("/tags/text/keywords", + gplate_text_tag_test_syntax_keywords); + gplate_tag_test_add("/tags/text/keywords_case_sensitive", + gplate_text_tag_test_syntax_keywords_case_sensitive); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gplate/tags/tests/test-variable-tag.c Fri Jul 02 02:56:50 2010 -0500
@@ -0,0 +1,125 @@
+#include <gplate/gplate.h> +#include "gplate-tag-test.h" +/****************************************************************************** + *****************************************************************************/ +gplate_variable_tag_test_single(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{ foo }}"; + fixture->expected = "bar"; + gplate_tag_test_output(fixture, data); +gplate_variable_tag_test_double(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{ foo }}{{ bar }}"; + fixture->expected = "foobar"; + gplate_tag_test_output(fixture, data); +gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{ foo }}{{ bar }}{{ baz }}"; + fixture->expected = "foobarbaz"; + gplate_tag_test_output(fixture, data); +gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{\nfoo}}"; + fixture->expected = "bar"; + gplate_tag_test_output(fixture, data); +gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{foo\n}}"; + fixture->expected = "bar"; + gplate_tag_test_output(fixture, data); +gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture, + gplate_collection_add_string(GPLATE_COLLECTION(fixture->template), + fixture->template_string = "{{\nfoo\n}}"; + fixture->expected = "bar"; + gplate_tag_test_output(fixture, data); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar **argv) { + g_test_init(&argc, &argv, NULL); + gplate_config_load_default(); + gplate_tag_test_add("/tags/variable/single", + gplate_variable_tag_test_single); + gplate_tag_test_add("/tags/variable/double", + gplate_variable_tag_test_double); + gplate_tag_test_add("/tags/variable/tripple", + gplate_variable_tag_test_tripple); + gplate_tag_test_add("/tags/variable/newline_prefix", + gplate_variable_tag_test_newline_prefix); + gplate_tag_test_add("/tags/variable/newline_suffix", + gplate_variable_tag_test_newline_suffix); + gplate_tag_test_add("/tags/variable/newline_wrapped", + gplate_variable_tag_test_newline_wrapped);