grim/gplate
Clone
Summary
Browse
Changes
Graph
The start of moving testing from autotools and check to gtester and ctest
2010-06-26, Gary Kramlich
125f0d26e4cb
The start of moving testing from autotools and check to gtester and ctest
refs #11
#ifdef HAVE_CONFIG_H
#
include
<config.h>
#endif
/* HAVE_CONFIG_H */
#include
<check.h>
#include
<stdio.h>
#include
<string.h>
#include
<gplate/gplate.h>
#include
"test.h"
/******************************************************************************
* Globals
*****************************************************************************/
static
GPlateTemplate
*
tplate
=
NULL
;
static
GError
*
error
=
NULL
;
static
gchar
*
msg
=
NULL
;
/******************************************************************************
* Fixtures
*****************************************************************************/
static
void
simple_setup
(
void
)
{
tplate
=
gplate_template_new
();
}
static
void
simple_teardown
(
void
)
{
g_object_unref
(
G_OBJECT
(
tplate
));
tplate
=
NULL
;
if
(
error
)
g_error_free
(
error
);
error
=
NULL
;
g_free
(
msg
);
msg
=
NULL
;
}
/******************************************************************************
* Simple Includes
*****************************************************************************/
START_TEST
(
test_include_simple_static
)
gchar
*
output
=
NULL
,
*
e1
=
NULL
,
*
e2
=
NULL
;
const
gchar
*
expected
=
"before the include
\n
"
"inside the included file
\n\n
"
"after the include
\n
"
"
\n
"
;
gint
r
=
0
;
output
=
gplate_template_render_file
(
tplate
,
"templates/simple.gplate"
,
&
error
);
fail_unless
(
error
==
NULL
,
(
error
&&
error
->
message
)
?
error
->
message
:
"Unknown failed"
);
r
=
g_utf8_collate
(
output
,
expected
);
e1
=
g_strescape
(
output
,
NULL
);
e2
=
g_strescape
(
expected
,
NULL
);
msg
=
g_strdup_printf
(
"
\n
got: '%s'
\n
wanted: '%s'
\n
"
,
e1
,
e2
);
g_free
(
output
);
g_free
(
e1
);
g_free
(
e2
);
fail_unless
(
r
==
0
,
msg
);
END_TEST
START_TEST
(
test_include_html_header_footer
)
gchar
*
output
=
NULL
,
*
e1
=
NULL
,
*
e2
=
NULL
;
const
gchar
*
expected
=
"<html>
\n
"
"
\t
<head>
\n
"
"
\t\t
<title>test</title>
\n
"
"
\t
</head>
\n
"
"
\t
<body>
\n
"
"in the body"
"
\t
</body>
\n
"
"</html>
\n\n
"
;
gint
r
=
0
;
output
=
gplate_template_render_file
(
tplate
,
"templates/html.gplate"
,
&
error
);
fail_unless
(
error
==
NULL
,
(
error
&&
error
->
message
)
?
error
->
message
:
"Unknown failure"
);
r
=
g_utf8_collate
(
output
,
expected
);
e1
=
g_strescape
(
output
,
NULL
);
e2
=
g_strescape
(
expected
,
NULL
);
msg
=
g_strdup_printf
(
"
\n
got: '%s'
\n
wanted: '%s'
\n
"
,
e1
,
e2
);
g_free
(
output
);
g_free
(
e1
);
g_free
(
e2
);
fail_unless
(
r
==
0
,
msg
);
END_TEST
/******************************************************************************
* Exported
*****************************************************************************/
Suite
*
include_suite
(
void
)
{
Suite
*
s
=
suite_create
(
"Include Function Suite"
);
TCase
*
tc
=
NULL
;
tc
=
tcase_create
(
"Simple Includes"
);
tcase_add_checked_fixture
(
tc
,
simple_setup
,
simple_teardown
);
tcase_add_test
(
tc
,
test_include_simple_static
);
tcase_add_test
(
tc
,
test_include_html_header_footer
);
suite_add_tcase
(
s
,
tc
);
return
s
;
}