gplate/functions/tests/test-gplate-include-function.c
author Gary Kramlich <grim@reaperworld.com>
Sun Jul 04 16:09:43 2010 -0500 (22 months ago)
changeset 405 b90b9411363f
permissions -rw-r--r--
moved the include function tests to the new format

refs #16
     1 /*
     2  * Copyright (C) 2007-2010 Gary Kramlich <grim@reaperworld.com>
     3  *
     4  * This program is free software: you can redistribute it and/or modify
     5  * it under the terms of the GNU General Public License as published by
     6  * the Free Software Foundation, either version 3 of the License, or
     7  * (at your option) any later version.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  */
    17 #include <gplate/gplate.h>
    18 
    19 #include <glib.h>
    20 
    21 /******************************************************************************
    22  * Structs
    23  *****************************************************************************/
    24 typedef struct {
    25 	GPlateTemplate *template;
    26 
    27 	const gchar *template_string;
    28 
    29 	gchar *actual;
    30 	const gchar *expected;
    31 
    32 	GError *error;
    33 } TestGPlateIncludeFunctionFixture;
    34 
    35 /******************************************************************************
    36  * Fixtures
    37  *****************************************************************************/
    38 static void
    39 test_gplate_include_function_setup(TestGPlateIncludeFunctionFixture *fixture,
    40                                    gconstpointer d)
    41 {
    42 	fixture->template = gplate_template_new();
    43 }
    44 
    45 static void
    46 test_gplate_include_function_teardown(TestGPlateIncludeFunctionFixture *fixture,
    47                                       gconstpointer d)
    48 {
    49 	g_object_unref(fixture->template);
    50 	fixture->template = NULL;
    51 
    52 	g_free(fixture->actual);
    53 	fixture->actual = NULL;
    54 
    55 	fixture->expected = NULL;
    56 
    57 	if(fixture->error) {
    58 		g_error_free(fixture->error);
    59 		fixture->error = NULL;
    60 	}
    61 }
    62 
    63 /******************************************************************************
    64  * Tests
    65  *****************************************************************************/
    66 static void
    67 test_gplate_include_function_simple(TestGPlateIncludeFunctionFixture *fixture,
    68                                     gconstpointer data)
    69 {
    70 	fixture->expected = "including\nincluded!\ndone";
    71 
    72 	fixture->actual = gplate_template_render_file(fixture->template,
    73 	                                              "templates/simple.gplate",
    74 	                                              &fixture->error);
    75 
    76 	g_assert(fixture->error == NULL);
    77 
    78 	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
    79 }
    80 
    81 static void
    82 test_gplate_include_function_double(TestGPlateIncludeFunctionFixture *fixture,
    83                                     gconstpointer data)
    84 {
    85 	fixture->expected = " \
    86 <html>\
    87 	<head>\
    88 		<title>test</title>\
    89 	</head>\
    90 	<body>\
    91 in the body\
    92 	</body>\
    93 </html>";
    94 
    95 	fixture->actual = gplate_template_render_file(fixture->template,
    96 	                                              "templates/html.gplate",
    97 	                                              &fixture->error);
    98 
    99 	g_assert(fixture->error == NULL);
   100 
   101 	g_assert_cmpstr(fixture->expected, ==, fixture->actual);
   102 }
   103 
   104 /******************************************************************************
   105  * Main!
   106  *****************************************************************************/
   107 gint
   108 main(gint argc, gchar **argv) {
   109 	g_test_init(&argc, &argv, NULL);
   110 
   111 	g_type_init();
   112 
   113 	gplate_config_load_default();
   114 
   115 	g_test_add("/functions/include/simple",
   116 	           TestGPlateIncludeFunctionFixture,
   117 	           NULL,
   118 	           test_gplate_include_function_setup,
   119 	           test_gplate_include_function_simple,
   120 	           test_gplate_include_function_teardown);
   121 
   122 	g_test_add("/functions/include/double",
   123 	           TestGPlateIncludeFunctionFixture,
   124 	           NULL,
   125 	           test_gplate_include_function_setup,
   126 	           test_gplate_include_function_double,
   127 	           test_gplate_include_function_teardown);
   128 
   129 	return g_test_run();
   130 }
   131