Create a sublibrary for the tag testing. I'll probably do this for all components going forward.
authorGary Kramlich <grim@reaperworld.com>
Fri Jul 02 02:56:50 2010 -0500 (19 months ago)
changeset 3898baf0603ff07
parent 388 301bcc8bdad0
child 390 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
gplate/tags/tests/CMakeLists.txt
gplate/tags/tests/gplate-tag-test.c
gplate/tags/tests/gplate-tag-test.h
gplate/tags/tests/test-text-tag.c
gplate/tags/tests/test-variable-tag.c
     1.1 --- a/gplate/tags/tests/CMakeLists.txt	Sat Jun 26 15:25:18 2010 -0500
     1.2 +++ b/gplate/tags/tests/CMakeLists.txt	Fri Jul 02 02:56:50 2010 -0500
     1.3 @@ -1,6 +1,18 @@
     1.4  enable_testing()
     1.5  
     1.6 +# define the static library for tag testing
     1.7 +add_library(gplate-tag-test STATIC
     1.8 +	gplate-tag-test.c
     1.9 +)
    1.10 +target_link_libraries(gplate-tag-test gplate)
    1.11 +
    1.12 +# add the text tag tests
    1.13  add_executable(test-text-tag test-text-tag.c)
    1.14 -target_link_libraries(test-text-tag gplate)
    1.15 +target_link_libraries(test-text-tag gplate-tag-test)
    1.16  add_test(GPlateTextTag test-text-tag)
    1.17  
    1.18 +# add the variable tag tests
    1.19 +add_executable(test-variable-tag test-variable-tag.c)
    1.20 +target_link_libraries(test-variable-tag gplate-tag-test)
    1.21 +add_test(GPlateVariableTag test-variable-tag)
    1.22 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gplate/tags/tests/gplate-tag-test.c	Fri Jul 02 02:56:50 2010 -0500
     2.3 @@ -0,0 +1,32 @@
     2.4 +#include "gplate-tag-test.h"
     2.5 +
     2.6 +void
     2.7 +gplate_tag_test_setup(GPlateTagTestFixture *fixture, gconstpointer data) {
     2.8 +	fixture->template = gplate_template_new();
     2.9 +}
    2.10 +
    2.11 +void
    2.12 +gplate_tag_test_teardown(GPlateTagTestFixture *fixture, gconstpointer data) {
    2.13 +	g_object_unref(fixture->template);
    2.14 +	fixture->template = NULL;
    2.15 +
    2.16 +	if(fixture->error) {
    2.17 +		g_error_free(fixture->error);
    2.18 +		fixture->error = NULL;
    2.19 +	}
    2.20 +
    2.21 +	g_free(fixture->actual);
    2.22 +	fixture->actual = NULL;
    2.23 +}
    2.24 +
    2.25 +void
    2.26 +gplate_tag_test_output(GPlateTagTestFixture *fixture, gconstpointer data) {
    2.27 +	fixture->actual = gplate_template_render(fixture->template,
    2.28 +	                                         fixture->template_string,
    2.29 +	                                         &fixture->error);
    2.30 +
    2.31 +	g_assert(fixture->error == NULL);
    2.32 +
    2.33 +	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
    2.34 +}
    2.35 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gplate/tags/tests/gplate-tag-test.h	Fri Jul 02 02:56:50 2010 -0500
     3.3 @@ -0,0 +1,33 @@
     3.4 +#ifndef GPLATE_TAG_TEST_H
     3.5 +#define GPLATE_TAG_TEST_H
     3.6 +
     3.7 +#include <gplate/gplate.h>
     3.8 +
     3.9 +#include <glib.h>
    3.10 +
    3.11 +#define gplate_tag_test_add(path, func) \
    3.12 +	g_test_add((path), GPlateTagTestFixture, NULL, gplate_tag_test_setup, (func), gplate_tag_test_teardown)
    3.13 +
    3.14 +typedef struct _GPlateTagTestFixture GPlateTagTestFixture;
    3.15 +
    3.16 +typedef void (*GPlateTagTestFixtureFunc)(GPlateTagTestFixture *fixture, gconstpointer data);
    3.17 +
    3.18 +struct _GPlateTagTestFixture {
    3.19 +	GPlateTemplate *template;
    3.20 +	GError *error;
    3.21 +
    3.22 +	const gchar *template_string;
    3.23 +
    3.24 +	const gchar *expected;
    3.25 +	gchar *actual;
    3.26 +};
    3.27 +
    3.28 +G_BEGIN_DECLS
    3.29 +
    3.30 +void gplate_tag_test_setup(GPlateTagTestFixture *fixture, gconstpointer data);
    3.31 +void gplate_tag_test_teardown(GPlateTagTestFixture *fixture, gconstpointer data);
    3.32 +void gplate_tag_test_output(GPlateTagTestFixture *fixture, gconstpointer data);
    3.33 +
    3.34 +G_END_DECLS
    3.35 +
    3.36 +#endif /* GPLATE_TAG_TEST_H */
     4.1 --- a/gplate/tags/tests/test-text-tag.c	Sat Jun 26 15:25:18 2010 -0500
     4.2 +++ b/gplate/tags/tests/test-text-tag.c	Fri Jul 02 02:56:50 2010 -0500
     4.3 @@ -2,86 +2,39 @@
     4.4  
     4.5  #include <glib.h>
     4.6  
     4.7 -/******************************************************************************
     4.8 - * Fixtures
     4.9 - *****************************************************************************/
    4.10 -typedef struct {
    4.11 -	GPlateTemplate *template;
    4.12 -	GError *error;
    4.13 -
    4.14 -	const gchar *template_string;
    4.15 -
    4.16 -	const gchar *expected;
    4.17 -	gchar *actual;
    4.18 -} GPlateTextTagTestFixture;
    4.19 -
    4.20 -static void
    4.21 -gplate_text_tag_test_setup(GPlateTextTagTestFixture *fixture,
    4.22 -                           gconstpointer user_data)
    4.23 -{
    4.24 -	fixture->template = gplate_template_new();
    4.25 -}
    4.26 -
    4.27 -static void
    4.28 -gplate_text_tag_test_teardown(GPlateTextTagTestFixture *fixture,
    4.29 -                              gconstpointer user_data)
    4.30 -{
    4.31 -	g_object_unref(fixture->template);
    4.32 -
    4.33 -	if(fixture->error) {
    4.34 -		g_error_free(fixture->error);
    4.35 -		fixture->error = NULL;
    4.36 -	}
    4.37 -
    4.38 -	g_free(fixture->actual);
    4.39 -	fixture->actual = NULL;
    4.40 -}
    4.41 -
    4.42 -/******************************************************************************
    4.43 - * Helpers
    4.44 - *****************************************************************************/
    4.45 -static void
    4.46 -gplate_text_tag_test_output(GPlateTextTagTestFixture *fixture) {
    4.47 -	fixture->actual = gplate_template_render(fixture->template,
    4.48 -	                                         fixture->template_string,
    4.49 -	                                         &fixture->error);
    4.50 -
    4.51 -	g_assert(fixture->error == NULL);
    4.52 -
    4.53 -	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
    4.54 -}
    4.55 +#include "gplate-tag-test.h"
    4.56  
    4.57  /******************************************************************************
    4.58   * Tests
    4.59   *****************************************************************************/
    4.60  static void
    4.61 -gplate_text_tag_test_syntax_plain(GPlateTextTagTestFixture *fixture,
    4.62 -                                  gconstpointer user_data)
    4.63 +gplate_text_tag_test_syntax_plain(GPlateTagTestFixture *fixture,
    4.64 +                                  gconstpointer data)
    4.65  {
    4.66  	fixture->template_string = "simple template";
    4.67  	fixture->expected = "simple template";
    4.68  
    4.69 -	gplate_text_tag_test_output(fixture);
    4.70 +	gplate_tag_test_output(fixture, data);
    4.71  }
    4.72  
    4.73  static void
    4.74 -gplate_text_tag_test_syntax_keywords(GPlateTextTagTestFixture *fixture,
    4.75 -                                     gconstpointer user_data)
    4.76 +gplate_text_tag_test_syntax_keywords(GPlateTagTestFixture *fixture,
    4.77 +                                     gconstpointer data)
    4.78  {
    4.79  	fixture->template_string = "extends if else endif for endfor";
    4.80  	fixture->expected = "extends if else endif for endfor";
    4.81  
    4.82 -	gplate_text_tag_test_output(fixture);
    4.83 +	gplate_tag_test_output(fixture, data);
    4.84  }
    4.85  
    4.86  static void
    4.87 -gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTextTagTestFixture *fixture,
    4.88 -                                                    gconstpointer user_data)
    4.89 +gplate_text_tag_test_syntax_keywords_case_sensitive(GPlateTagTestFixture *fixture,
    4.90 +                                                    gconstpointer data)
    4.91  {
    4.92  	fixture->template_string = "EXteNds iF eLse enDif fOr enDFor";
    4.93  	fixture->expected = "EXteNds iF eLse enDif fOr enDFor";
    4.94  
    4.95 -	gplate_text_tag_test_output(fixture);
    4.96 +	gplate_tag_test_output(fixture, data);
    4.97  }
    4.98  
    4.99  /******************************************************************************
   4.100 @@ -95,26 +48,12 @@
   4.101  
   4.102  	gplate_config_load_default();
   4.103  
   4.104 -	g_test_add("/tags/text/plain",
   4.105 -	           GPlateTextTagTestFixture,
   4.106 -	           NULL,
   4.107 -	           gplate_text_tag_test_setup,
   4.108 -	           gplate_text_tag_test_syntax_plain,
   4.109 -	           gplate_text_tag_test_teardown);
   4.110 -
   4.111 -	g_test_add("/tags/text/keywords",
   4.112 -	           GPlateTextTagTestFixture,
   4.113 -	           NULL,
   4.114 -	           gplate_text_tag_test_setup,
   4.115 -	           gplate_text_tag_test_syntax_keywords,
   4.116 -	           gplate_text_tag_test_teardown);
   4.117 -
   4.118 -	g_test_add("/tags/text/keywords_case_sensitive",
   4.119 -	           GPlateTextTagTestFixture,
   4.120 -	           NULL,
   4.121 -	           gplate_text_tag_test_setup,
   4.122 -	           gplate_text_tag_test_syntax_keywords_case_sensitive,
   4.123 -	           gplate_text_tag_test_teardown);
   4.124 +	gplate_tag_test_add("/tags/text/plain",
   4.125 +	                    gplate_text_tag_test_syntax_plain);
   4.126 +	gplate_tag_test_add("/tags/text/keywords",
   4.127 +	                    gplate_text_tag_test_syntax_keywords);
   4.128 +	gplate_tag_test_add("/tags/text/keywords_case_sensitive", 
   4.129 +	                    gplate_text_tag_test_syntax_keywords_case_sensitive);
   4.130  
   4.131  	return g_test_run();
   4.132  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/gplate/tags/tests/test-variable-tag.c	Fri Jul 02 02:56:50 2010 -0500
     5.3 @@ -0,0 +1,125 @@
     5.4 +#include <gplate/gplate.h>
     5.5 +
     5.6 +#include <glib.h>
     5.7 +
     5.8 +#include "gplate-tag-test.h"
     5.9 +
    5.10 +/******************************************************************************
    5.11 + * Tests
    5.12 + *****************************************************************************/
    5.13 +static void
    5.14 +gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
    5.15 +                                gconstpointer data)
    5.16 +{
    5.17 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.18 +	                             "foo", "bar");
    5.19 +
    5.20 +	fixture->template_string = "{{ foo }}";
    5.21 +	fixture->expected = "bar";
    5.22 +
    5.23 +	gplate_tag_test_output(fixture, data);
    5.24 +}
    5.25 +
    5.26 +static void
    5.27 +gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
    5.28 +                                gconstpointer data)
    5.29 +{
    5.30 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.31 +	                             "foo", "foo");
    5.32 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.33 +	                             "bar", "bar");
    5.34 +
    5.35 +	fixture->template_string = "{{ foo }}{{ bar }}";
    5.36 +	fixture->expected = "foobar";
    5.37 +
    5.38 +	gplate_tag_test_output(fixture, data);
    5.39 +}
    5.40 +
    5.41 +static void
    5.42 +gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
    5.43 +                                 gconstpointer data)
    5.44 +{
    5.45 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.46 +	                             "foo", "foo");
    5.47 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.48 +	                             "bar", "bar");
    5.49 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.50 +	                             "baz", "baz");
    5.51 +
    5.52 +	fixture->template_string = "{{ foo }}{{ bar }}{{ baz }}";
    5.53 +	fixture->expected = "foobarbaz";
    5.54 +
    5.55 +	gplate_tag_test_output(fixture, data);
    5.56 +}
    5.57 +
    5.58 +static void
    5.59 +gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
    5.60 +                                        gconstpointer data)
    5.61 +{
    5.62 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.63 +	                             "foo", "bar");
    5.64 +
    5.65 +	fixture->template_string = "{{\nfoo}}";
    5.66 +	fixture->expected = "bar";
    5.67 +
    5.68 +	gplate_tag_test_output(fixture, data);
    5.69 +}
    5.70 +
    5.71 +static void
    5.72 +gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
    5.73 +                                        gconstpointer data)
    5.74 +{
    5.75 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.76 +	                             "foo", "bar");
    5.77 +
    5.78 +	fixture->template_string = "{{foo\n}}";
    5.79 +	fixture->expected = "bar";
    5.80 +
    5.81 +	gplate_tag_test_output(fixture, data);
    5.82 +}
    5.83 +
    5.84 +static void
    5.85 +gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
    5.86 +                                         gconstpointer data)
    5.87 +{
    5.88 +	gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    5.89 +	                             "foo", "bar");
    5.90 +
    5.91 +	fixture->template_string = "{{\nfoo\n}}";
    5.92 +	fixture->expected = "bar";
    5.93 +
    5.94 +	gplate_tag_test_output(fixture, data);
    5.95 +}
    5.96 +
    5.97 +/******************************************************************************
    5.98 + * Main
    5.99 + *****************************************************************************/
   5.100 +gint
   5.101 +main(gint argc, gchar **argv) {
   5.102 +	g_test_init(&argc, &argv, NULL);
   5.103 +
   5.104 +	g_type_init();
   5.105 +
   5.106 +	gplate_config_load_default();
   5.107 +
   5.108 +	gplate_tag_test_add("/tags/variable/single",
   5.109 +	                    gplate_variable_tag_test_single);
   5.110 +
   5.111 +	gplate_tag_test_add("/tags/variable/double",
   5.112 +	                    gplate_variable_tag_test_double);
   5.113 +
   5.114 +	gplate_tag_test_add("/tags/variable/tripple",
   5.115 +	                    gplate_variable_tag_test_tripple);
   5.116 +
   5.117 +	gplate_tag_test_add("/tags/variable/newline_prefix",
   5.118 +	                    gplate_variable_tag_test_newline_prefix);
   5.119 +
   5.120 +	gplate_tag_test_add("/tags/variable/newline_suffix",
   5.121 +	                    gplate_variable_tag_test_newline_suffix);
   5.122 +
   5.123 +	gplate_tag_test_add("/tags/variable/newline_wrapped",
   5.124 +	                    gplate_variable_tag_test_newline_wrapped);
   5.125 +
   5.126 +	return g_test_run();
   5.127 +}
   5.128 +