grim/gplate

Parents 301bcc8bdad0
Children 3a38d5cf4abd
Create a sublibrary for the tag testing. I'll probably do this for all components going forward.

Pretty much just reimplemented the tests that were created for check with gtester and ctest
--- 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 @@
enable_testing()
+# define the static library for tag testing
+add_library(gplate-tag-test STATIC
+ gplate-tag-test.c
+)
+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"
+
+void
+gplate_tag_test_setup(GPlateTagTestFixture *fixture, gconstpointer data) {
+ fixture->template = gplate_template_new();
+}
+
+void
+gplate_tag_test_teardown(GPlateTagTestFixture *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
+gplate_tag_test_output(GPlateTagTestFixture *fixture, gconstpointer data) {
+ fixture->actual = gplate_template_render(fixture->template,
+ fixture->template_string,
+ &fixture->error);
+
+ 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>
+
+#include <glib.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;
+ GError *error;
+
+ const gchar *template_string;
+
+ const gchar *expected;
+ gchar *actual;
+};
+
+G_BEGIN_DECLS
+
+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);
+
+G_END_DECLS
+
+#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 @@
#include <glib.h>
-/******************************************************************************
- * Fixtures
- *****************************************************************************/
-typedef struct {
- GPlateTemplate *template;
- GError *error;
-
- const gchar *template_string;
-
- const gchar *expected;
- gchar *actual;
-} GPlateTextTagTestFixture;
-
-static void
-gplate_text_tag_test_setup(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
-{
- fixture->template = gplate_template_new();
-}
-
-static void
-gplate_text_tag_test_teardown(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
-{
- g_object_unref(fixture->template);
-
- if(fixture->error) {
- g_error_free(fixture->error);
- fixture->error = NULL;
- }
-
- g_free(fixture->actual);
- fixture->actual = NULL;
-}
-
-/******************************************************************************
- * Helpers
- *****************************************************************************/
-static void
-gplate_text_tag_test_output(GPlateTextTagTestFixture *fixture) {
- fixture->actual = gplate_template_render(fixture->template,
- fixture->template_string,
- &fixture->error);
-
- g_assert(fixture->error == NULL);
-
- g_assert_cmpstr(fixture->expected, ==, fixture->actual);
-}
+#include "gplate-tag-test.h"
/******************************************************************************
* Tests
*****************************************************************************/
static void
-gplate_text_tag_test_syntax_plain(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_plain(GPlateTagTestFixture *fixture,
+ gconstpointer data)
{
fixture->template_string = "simple template";
fixture->expected = "simple template";
- gplate_text_tag_test_output(fixture);
+ gplate_tag_test_output(fixture, data);
}
static void
-gplate_text_tag_test_syntax_keywords(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_keywords(GPlateTagTestFixture *fixture,
+ gconstpointer data)
{
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);
}
static void
-gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTextTagTestFixture *fixture,
- gconstpointer user_data)
+gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTagTestFixture *fixture,
+ gconstpointer data)
{
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,
- NULL,
- gplate_text_tag_test_setup,
- gplate_text_tag_test_syntax_plain,
- gplate_text_tag_test_teardown);
-
- g_test_add("/tags/text/keywords",
- GPlateTextTagTestFixture,
- NULL,
- 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,
- NULL,
- 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);
return g_test_run();
}
--- /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 <glib.h>
+
+#include "gplate-tag-test.h"
+
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
+static void
+gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "bar");
+
+ fixture->template_string = "{{ foo }}";
+ fixture->expected = "bar";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+static void
+gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "foo");
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "bar", "bar");
+
+ fixture->template_string = "{{ foo }}{{ bar }}";
+ fixture->expected = "foobar";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+static void
+gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "foo");
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "bar", "bar");
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "baz", "baz");
+
+ fixture->template_string = "{{ foo }}{{ bar }}{{ baz }}";
+ fixture->expected = "foobarbaz";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+static void
+gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "bar");
+
+ fixture->template_string = "{{\nfoo}}";
+ fixture->expected = "bar";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+static void
+gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "bar");
+
+ fixture->template_string = "{{foo\n}}";
+ fixture->expected = "bar";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+static void
+gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
+ gconstpointer data)
+{
+ gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
+ "foo", "bar");
+
+ fixture->template_string = "{{\nfoo\n}}";
+ fixture->expected = "bar";
+
+ gplate_tag_test_output(fixture, data);
+}
+
+/******************************************************************************
+ * Main
+ *****************************************************************************/
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_type_init();
+
+ 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);
+
+ return g_test_run();
+}
+