gplate/tags/tests/gplate-variable-tag-test.c
author Gary Kramlich <grim@reaperworld.com>
Fri Jul 02 03:13:36 2010 -0500 (22 months ago)
changeset 392 27f9b7952d63
parent 391 20d032b30b6a
child 393 e54d0b8f5a56
permissions -rw-r--r--
updated the variable tag tests to use a variadic function to do the heavy lifting to avoid code duplication and wasted effort and so on
     1 #include <gplate/gplate.h>
     2 
     3 #include <glib.h>
     4 
     5 #include "gplate-tag-test.h"
     6 
     7 /******************************************************************************
     8  * Helpers
     9  *****************************************************************************/
    10 static void
    11 gplate_variable_tag_test(GPlateTagTestFixture *fixture, gconstpointer data,
    12                          const gchar *template_string, const gchar *expected,
    13                          ...)
    14 {
    15 	va_list vargs;
    16 	const gchar *name = NULL, *value = NULL;
    17 
    18 	fixture->template_string = template_string;
    19 	fixture->expected = expected;
    20 
    21 	va_start(vargs, expected);
    22 	while((name = va_arg(vargs, const gchar *))) {
    23 		value = va_arg(vargs, const gchar *);
    24 
    25 		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
    26 		                             name, value);
    27 	}
    28 
    29 	va_end(vargs);
    30 
    31 	gplate_tag_test_output(fixture, data);
    32 }
    33 
    34 /******************************************************************************
    35  * Tests
    36  *****************************************************************************/
    37 static void
    38 gplate_variable_tag_test_single(GPlateTagTestFixture *fixture,
    39                                 gconstpointer data)
    40 {
    41 	gplate_variable_tag_test(fixture, data,
    42 	                         "{{ foo }}", "foo",
    43 	                         "foo", "foo",
    44 	                         NULL);
    45 }
    46 
    47 static void
    48 gplate_variable_tag_test_double(GPlateTagTestFixture *fixture,
    49                                 gconstpointer data)
    50 {
    51 	gplate_variable_tag_test(fixture, data,
    52 	                         "{{ foo }}{{ bar }}", "foobar",
    53 	                         "foo", "foo",
    54 	                         "bar", "bar",
    55 	                         NULL);
    56 }
    57 
    58 static void
    59 gplate_variable_tag_test_tripple(GPlateTagTestFixture *fixture,
    60                                  gconstpointer data)
    61 {
    62 	gplate_variable_tag_test(fixture, data,
    63 	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
    64 	                         "foo", "foo",
    65 	                         "bar", "bar",
    66 	                         "baz", "baz",
    67 	                         NULL);
    68 }
    69 
    70 static void
    71 gplate_variable_tag_test_newline_prefix(GPlateTagTestFixture *fixture,
    72                                         gconstpointer data)
    73 {
    74 	gplate_variable_tag_test(fixture, data,
    75 	                         "{{\nfoo}}", "foo",
    76 	                         "foo", "foo",
    77 	                         NULL);
    78 }
    79 
    80 static void
    81 gplate_variable_tag_test_newline_suffix(GPlateTagTestFixture *fixture,
    82                                         gconstpointer data)
    83 {
    84 	gplate_variable_tag_test(fixture, data,
    85 	                         "{{foo\n}}", "foo",
    86 	                         "foo", "foo",
    87 	                         NULL);
    88 }
    89 
    90 static void
    91 gplate_variable_tag_test_newline_wrapped(GPlateTagTestFixture *fixture,
    92                                          gconstpointer data)
    93 {
    94 	gplate_variable_tag_test(fixture, data,
    95 	                         "{{\nfoo\n}}", "foo",
    96 	                         "foo", "foo",
    97 	                         NULL);
    98 }
    99 
   100 /******************************************************************************
   101  * Main
   102  *****************************************************************************/
   103 gint
   104 main(gint argc, gchar **argv) {
   105 	g_test_init(&argc, &argv, NULL);
   106 
   107 	g_type_init();
   108 
   109 	gplate_config_load_default();
   110 
   111 	gplate_tag_test_add("/tags/variable/single",
   112 	                    gplate_variable_tag_test_single);
   113 
   114 	gplate_tag_test_add("/tags/variable/double",
   115 	                    gplate_variable_tag_test_double);
   116 
   117 	gplate_tag_test_add("/tags/variable/tripple",
   118 	                    gplate_variable_tag_test_tripple);
   119 
   120 	gplate_tag_test_add("/tags/variable/newline_prefix",
   121 	                    gplate_variable_tag_test_newline_prefix);
   122 
   123 	gplate_tag_test_add("/tags/variable/newline_suffix",
   124 	                    gplate_variable_tag_test_newline_suffix);
   125 
   126 	gplate_tag_test_add("/tags/variable/newline_wrapped",
   127 	                    gplate_variable_tag_test_newline_wrapped);
   128 
   129 	return g_test_run();
   130 }
   131