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