gplate/functions/tests/test-gplate-include-function.c
changeset 405 b90b9411363f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gplate/functions/tests/test-gplate-include-function.c	Sun Jul 04 16:09:43 2010 -0500
     1.3 @@ -0,0 +1,131 @@
     1.4 +/*
     1.5 + * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
     1.6 + *
     1.7 + * This program is free software: you can redistribute it and/or modify
     1.8 + * it under the terms of the GNU General Public License as published by
     1.9 + * the Free Software Foundation, either version 3 of the License, or
    1.10 + * (at your option) any later version.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.19 + */
    1.20 +#include <gplate/gplate.h>
    1.21 +
    1.22 +#include <glib.h>
    1.23 +
    1.24 +/******************************************************************************
    1.25 + * Structs
    1.26 + *****************************************************************************/
    1.27 +typedef struct {
    1.28 +	GPlateTemplate *template;
    1.29 +
    1.30 +	const gchar *template_string;
    1.31 +
    1.32 +	gchar *actual;
    1.33 +	const gchar *expected;
    1.34 +
    1.35 +	GError *error;
    1.36 +} TestGPlateIncludeFunctionFixture;
    1.37 +
    1.38 +/******************************************************************************
    1.39 + * Fixtures
    1.40 + *****************************************************************************/
    1.41 +static void
    1.42 +test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture,
    1.43 +                                   gconstpointer d)
    1.44 +{
    1.45 +	fixture->template = gplate_template_new();
    1.46 +}
    1.47 +
    1.48 +static void
    1.49 +test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture,
    1.50 +                                      gconstpointer d)
    1.51 +{
    1.52 +	g_object_unref(fixture->template);
    1.53 +	fixture->template = NULL;
    1.54 +
    1.55 +	g_free(fixture->actual);
    1.56 +	fixture->actual = NULL;
    1.57 +
    1.58 +	fixture->expected = NULL;
    1.59 +
    1.60 +	if(fixture->error) {
    1.61 +		g_error_free(fixture->error);
    1.62 +		fixture->error = NULL;
    1.63 +	}
    1.64 +}
    1.65 +
    1.66 +/******************************************************************************
    1.67 + * Tests
    1.68 + *****************************************************************************/
    1.69 +static void
    1.70 +test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture,
    1.71 +                                    gconstpointer data)
    1.72 +{
    1.73 +	fixture->expected = "including\nincluded!\ndone";
    1.74 +
    1.75 +	fixture->actual = gplate_template_render_file(fixture->template,
    1.76 +	                                              "templates/simple.gplate",
    1.77 +	                                              &fixture->error);
    1.78 +
    1.79 +	g_assert(fixture->error == NULL);
    1.80 +
    1.81 +	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
    1.82 +}
    1.83 +
    1.84 +static void
    1.85 +test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture,
    1.86 +                                    gconstpointer data)
    1.87 +{
    1.88 +	fixture->expected = " \
    1.89 +<html>\
    1.90 +	<head>\
    1.91 +		<title>test</title>\
    1.92 +	</head>\
    1.93 +	<body>\
    1.94 +in the body\
    1.95 +	</body>\
    1.96 +</html>";
    1.97 +
    1.98 +	fixture->actual = gplate_template_render_file(fixture->template,
    1.99 +	                                              "templates/html.gplate",
   1.100 +	                                              &fixture->error);
   1.101 +
   1.102 +	g_assert(fixture->error == NULL);
   1.103 +
   1.104 +	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
   1.105 +}
   1.106 +
   1.107 +/******************************************************************************
   1.108 + * Main!
   1.109 + *****************************************************************************/
   1.110 +gint
   1.111 +main(gint argc, gchar **argv) {
   1.112 +	g_test_init(&argc, &argv, NULL);
   1.113 +
   1.114 +	g_type_init();
   1.115 +
   1.116 +	gplate_config_load_default();
   1.117 +
   1.118 +	g_test_add("/functions/include/simple",
   1.119 +	           TestGPlateIncludeFunctionFixture,
   1.120 +	           NULL,
   1.121 +	           test_gplate_include_function_setup,
   1.122 +	           test_gplate_include_function_simple,
   1.123 +	           test_gplate_include_function_teardown);
   1.124 +
   1.125 +	g_test_add("/functions/include/double",
   1.126 +	           TestGPlateIncludeFunctionFixture,
   1.127 +	           NULL,
   1.128 +	           test_gplate_include_function_setup,
   1.129 +	           test_gplate_include_function_double,
   1.130 +	           test_gplate_include_function_teardown);
   1.131 +
   1.132 +	return g_test_run();
   1.133 +}
   1.134 +