gplate/tags/tests/test-gplate-variable-tag.c
author Gary Kramlich <grim@reaperworld.com>
Sun Jul 04 03:34:39 2010 -0500 (22 months ago)
changeset 400 0938cb5d076b
parent 395 gplate/tags/tests/gplate-variable-tag-test.c@2a257237a0ef
child 403 13b5031b2846
permissions -rw-r--r--
the start of the test name standardization

refs #15
grim@394
     1
/*
grim@394
     2
 * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
grim@394
     3
 *
grim@394
     4
 * This program is free software: you can redistribute it and/or modify
grim@394
     5
 * it under the terms of the GNU General Public License as published by
grim@394
     6
 * the Free Software Foundation, either version 3 of the License, or
grim@394
     7
 * (at your option) any later version.
grim@394
     8
 *
grim@394
     9
 * This program is distributed in the hope that it will be useful,
grim@394
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
grim@394
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
grim@394
    12
 * GNU General Public License for more details.
grim@394
    13
 *
grim@394
    14
 * You should have received a copy of the GNU General Public License
grim@394
    15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
grim@394
    16
 */
grim@389
    17
#include <gplate/gplate.h>
grim@389
    18
grim@389
    19
#include <glib.h>
grim@389
    20
grim@400
    21
#include "test-gplate-tag.h"
grim@389
    22
grim@389
    23
/******************************************************************************
grim@392
    24
 * Helpers
grim@392
    25
 *****************************************************************************/
grim@392
    26
static void
grim@400
    27
test_gplate_variable_tag(TestGPlateTagFixture *fixture, gconstpointer data,
grim@392
    28
                         const gchar *template_string, const gchar *expected,
grim@392
    29
                         ...)
grim@392
    30
{
grim@392
    31
	va_list vargs;
grim@392
    32
	const gchar *name = NULL, *value = NULL;
grim@392
    33
grim@392
    34
	va_start(vargs, expected);
grim@392
    35
	while((name = va_arg(vargs, const gchar *))) {
grim@392
    36
		value = va_arg(vargs, const gchar *);
grim@392
    37
grim@392
    38
		gplate_collection_add_string(GPLATE_COLLECTION(fixture->template),
grim@392
    39
		                             name, value);
grim@392
    40
	}
grim@392
    41
	va_end(vargs);
grim@392
    42
grim@400
    43
	test_gplate_tag_output(fixture, data, template_string, expected);
grim@392
    44
}
grim@392
    45
grim@392
    46
/******************************************************************************
grim@389
    47
 * Tests
grim@389
    48
 *****************************************************************************/
grim@389
    49
static void
grim@400
    50
test_gplate_variable_tag_single(TestGPlateTagFixture *fixture,
grim@389
    51
                                gconstpointer data)
grim@389
    52
{
grim@400
    53
	test_gplate_variable_tag(fixture, data,
grim@392
    54
	                         "{{ foo }}", "foo",
grim@392
    55
	                         "foo", "foo",
grim@392
    56
	                         NULL);
grim@389
    57
}
grim@389
    58
grim@389
    59
static void
grim@400
    60
test_gplate_variable_tag_double(TestGPlateTagFixture *fixture,
grim@389
    61
                                gconstpointer data)
grim@389
    62
{
grim@400
    63
	test_gplate_variable_tag(fixture, data,
grim@392
    64
	                         "{{ foo }}{{ bar }}", "foobar",
grim@392
    65
	                         "foo", "foo",
grim@392
    66
	                         "bar", "bar",
grim@392
    67
	                         NULL);
grim@389
    68
}
grim@389
    69
grim@389
    70
static void
grim@400
    71
test_gplate_variable_tag_tripple(TestGPlateTagFixture *fixture,
grim@389
    72
                                 gconstpointer data)
grim@389
    73
{
grim@400
    74
	test_gplate_variable_tag(fixture, data,
grim@392
    75
	                         "{{ foo }}{{ bar }}{{ baz }}", "foobarbaz",
grim@392
    76
	                         "foo", "foo",
grim@392
    77
	                         "bar", "bar",
grim@392
    78
	                         "baz", "baz",
grim@392
    79
	                         NULL);
grim@389
    80
}
grim@389
    81
grim@389
    82
static void
grim@400
    83
test_gplate_variable_tag_newline_prefix(TestGPlateTagFixture *fixture,
grim@389
    84
                                        gconstpointer data)
grim@389
    85
{
grim@400
    86
	test_gplate_variable_tag(fixture, data,
grim@392
    87
	                         "{{\nfoo}}", "foo",
grim@392
    88
	                         "foo", "foo",
grim@392
    89
	                         NULL);
grim@389
    90
}
grim@389
    91
grim@389
    92
static void
grim@400
    93
test_gplate_variable_tag_newline_suffix(TestGPlateTagFixture *fixture,
grim@389
    94
                                        gconstpointer data)
grim@389
    95
{
grim@400
    96
	test_gplate_variable_tag(fixture, data,
grim@392
    97
	                         "{{foo\n}}", "foo",
grim@392
    98
	                         "foo", "foo",
grim@392
    99
	                         NULL);
grim@389
   100
}
grim@389
   101
grim@389
   102
static void
grim@400
   103
test_gplate_variable_tag_newline_wrapped(TestGPlateTagFixture *fixture,
grim@389
   104
                                         gconstpointer data)
grim@389
   105
{
grim@400
   106
	test_gplate_variable_tag(fixture, data,
grim@392
   107
	                         "{{\nfoo\n}}", "foo",
grim@392
   108
	                         "foo", "foo",
grim@392
   109
	                         NULL);
grim@389
   110
}
grim@389
   111
grim@393
   112
static void
grim@400
   113
test_gplate_variable_tag_single_quotes(TestGPlateTagFixture *fixture,
grim@393
   114
                                       gconstpointer data)
grim@393
   115
{
grim@400
   116
	test_gplate_variable_tag(fixture, data,
grim@393
   117
	                         "foo '{{ bar }}' baz", "foo 'bar' baz",
grim@393
   118
	                         "bar", "bar",
grim@393
   119
	                         NULL);
grim@393
   120
}
grim@393
   121
grim@393
   122
static void
grim@400
   123
test_gplate_variable_tag_double_quotes(TestGPlateTagFixture *fixture,
grim@393
   124
                                       gconstpointer data)
grim@393
   125
{
grim@400
   126
	test_gplate_variable_tag(fixture, data,
grim@393
   127
	                         "foo \"{{ bar }}\" baz", "foo \"bar\" baz",
grim@393
   128
	                         "bar", "bar",
grim@393
   129
	                         NULL);
grim@393
   130
}
grim@393
   131
grim@393
   132
static void
grim@400
   133
test_gplate_variable_tag_mixed_quotes(TestGPlateTagFixture *fixture,
grim@393
   134
                                      gconstpointer data)
grim@393
   135
{
grim@400
   136
	test_gplate_variable_tag(fixture, data,
grim@393
   137
	                         "foo \"{{ bar }}' baz", "foo \"bar' baz",
grim@393
   138
	                         "bar", "bar",
grim@393
   139
	                         NULL);
grim@393
   140
grim@400
   141
	test_gplate_variable_tag(fixture, data,
grim@393
   142
	                         "foo '{{ bar }}\" baz", "foo 'bar\" baz",
grim@393
   143
	                         "bar", "bar",
grim@393
   144
	                         NULL);
grim@393
   145
}
grim@389
   146
/******************************************************************************
grim@389
   147
 * Main
grim@389
   148
 *****************************************************************************/
grim@389
   149
gint
grim@389
   150
main(gint argc, gchar **argv) {
grim@389
   151
	g_test_init(&argc, &argv, NULL);
grim@389
   152
grim@389
   153
	g_type_init();
grim@389
   154
grim@389
   155
	gplate_config_load_default();
grim@389
   156
grim@400
   157
	test_gplate_tag_add("/tags/variable/single",
grim@400
   158
	                    test_gplate_variable_tag_single);
grim@389
   159
grim@400
   160
	test_gplate_tag_add("/tags/variable/double",
grim@400
   161
	                    test_gplate_variable_tag_double);
grim@389
   162
grim@400
   163
	test_gplate_tag_add("/tags/variable/tripple",
grim@400
   164
	                    test_gplate_variable_tag_tripple);
grim@389
   165
grim@400
   166
	test_gplate_tag_add("/tags/variable/newline_prefix",
grim@400
   167
	                    test_gplate_variable_tag_newline_prefix);
grim@389
   168
grim@400
   169
	test_gplate_tag_add("/tags/variable/newline_suffix",
grim@400
   170
	                    test_gplate_variable_tag_newline_suffix);
grim@389
   171
grim@400
   172
	test_gplate_tag_add("/tags/variable/newline_wrapped",
grim@400
   173
	                    test_gplate_variable_tag_newline_wrapped);
grim@389
   174
grim@400
   175
	test_gplate_tag_add("/tags/variable/quotes/single",
grim@400
   176
	                    test_gplate_variable_tag_single_quotes);
grim@393
   177
grim@400
   178
	test_gplate_tag_add("/tags/variable/quotes/double",
grim@400
   179
	                    test_gplate_variable_tag_double_quotes);
grim@393
   180
grim@400
   181
	test_gplate_tag_add("/tags/variable/quotes/mixed",
grim@400
   182
	                    test_gplate_variable_tag_mixed_quotes);
grim@393
   183
grim@389
   184
	return g_test_run();
grim@389
   185
}
grim@389
   186