grim/gplate

converted test-util.c to gtester

2009-11-15, Gary Kramlich
bbab7cbd784c
Parents 477f732d08a7
Children 1db48445a111
converted test-util.c to gtester
--- a/tests/Makefile.am Sun Nov 15 01:14:25 2009 -0600
+++ b/tests/Makefile.am Sun Nov 15 01:23:15 2009 -0600
@@ -11,10 +11,15 @@
-I$(top_builddir)/gplate/
noinst_PROGRAMS = \
+ test-util \
test-variables
TEST_PROGS =
+TEST_PROGS += test-util
+test_util_SOURCES = test-util.c
+test_util_LDADD = $(LDADDS)
+
TEST_PROGS += test-variables
test_variables_SOURCES = test-variables.c
test_variables_LDADD = $(LDADDS)
--- a/tests/test-util.c Sun Nov 15 01:14:25 2009 -0600
+++ b/tests/test-util.c Sun Nov 15 01:23:15 2009 -0600
@@ -1,106 +1,43 @@
#include <gplate/gplate.h>
-#include "test.h"
-
-/******************************************************************************
- * Quoted String Tests
- *****************************************************************************/
static void
-test_quoted_string(const gchar *string, const gchar *contents,
- gboolean value)
+gplate_util_test_quoted_string_helper(const gchar *string,
+ const gchar *contents, gboolean value)
{
gboolean r = FALSE;
gchar *c = NULL;
r = gplate_util_is_quoted_string(string, &c);
- fail_unless(r == value, TEST_EXPECTED_ACTUAL_MSG,
- (value) ? "TRUE" : "FALSE",
- (r) ? "TRUE" : "FALSE");
+ g_assert_cmpint(r, ==, value);
if(contents)
- test_string(contents, c);
+ g_assert_cmpstr(c, ==, contents);
g_free(c);
}
-START_TEST(test_double_quoted_string_simple)
- test_quoted_string("\"abc\"", "abc", TRUE);
-END_TEST
-
-START_TEST(test_double_quoted_string_spaces)
- test_quoted_string("\"abc def\"", "abc def", TRUE);
-END_TEST
-
-START_TEST(test_double_quoted_string_complex)
- test_quoted_string("\"abc\tdef\bghi\"", "abc\tdef\bghi", TRUE);
-END_TEST
-
-START_TEST(test_double_quoted_string_prefix)
- test_quoted_string("abc \"def\"", NULL, FALSE);
-END_TEST
-
-START_TEST(test_double_quoted_string_suffix)
- test_quoted_string("\"abc\" def", NULL, FALSE);
-END_TEST
-
-START_TEST(test_single_quoted_string_simple)
- test_quoted_string("'abc'", "abc", TRUE);
-END_TEST
-
-START_TEST(test_single_quoted_string_spaces)
- test_quoted_string("'abc def'", "abc def", TRUE);
-END_TEST
-
-START_TEST(test_single_quoted_string_complex)
- test_quoted_string("'abc\tdef\bghi'", "abc\tdef\bghi", TRUE);
-END_TEST
-
-START_TEST(test_single_quoted_string_prefix)
- test_quoted_string("abc 'def'", NULL, FALSE);
-END_TEST
-
-START_TEST(test_single_quoted_string_suffix)
- test_quoted_string("'abc' def", NULL, FALSE);
-END_TEST
-
-START_TEST(test_mixmatched_quoted_string_single_double)
- test_quoted_string("'abc\"", NULL, FALSE);
-END_TEST
-
-START_TEST(test_mixmatched_quoted_string_double_single)
- test_quoted_string("\"abc'", NULL, FALSE);
-END_TEST
-
-/******************************************************************************
- * API
- *****************************************************************************/
-Suite *
-test_util_suite(void) {
- Suite *s = suite_create("Utility Suite");
- TCase *tc = NULL;
-
- /* quoted string */
- tc = tcase_create("Quoted String");
-
- tcase_add_test(tc, test_double_quoted_string_simple);
- tcase_add_test(tc, test_double_quoted_string_spaces);
- tcase_add_test(tc, test_double_quoted_string_complex);
- tcase_add_test(tc, test_double_quoted_string_prefix);
- tcase_add_test(tc, test_double_quoted_string_suffix);
-
- tcase_add_test(tc, test_single_quoted_string_simple);
- tcase_add_test(tc, test_single_quoted_string_spaces);
- tcase_add_test(tc, test_single_quoted_string_complex);
- tcase_add_test(tc, test_single_quoted_string_prefix);
- tcase_add_test(tc, test_single_quoted_string_suffix);
-
- tcase_add_test(tc, test_mixmatched_quoted_string_single_double);
- tcase_add_test(tc, test_mixmatched_quoted_string_double_single);
-
- suite_add_tcase(s, tc);
-
- /* first word */
-
- return s;
+static void
+gplate_util_test_quoted_string(void) {
+ gplate_util_test_quoted_string_helper("\"abc\"", "abc", TRUE);
+ gplate_util_test_quoted_string_helper("\"abc def\"", "abc def", TRUE);
+ gplate_util_test_quoted_string_helper("\"abc\tdef\bghi\"", "abc\tdef\bghi", TRUE);
+ gplate_util_test_quoted_string_helper("abc \"def\"", NULL, FALSE);
+ gplate_util_test_quoted_string_helper("\"abc\" def", NULL, FALSE);
+ gplate_util_test_quoted_string_helper("'abc'", "abc", TRUE);
+ gplate_util_test_quoted_string_helper("'abc def'", "abc def", TRUE);
+ gplate_util_test_quoted_string_helper("'abc\tdef\bghi'", "abc\tdef\bghi", TRUE);
+ gplate_util_test_quoted_string_helper("abc 'def'", NULL, FALSE);
+ gplate_util_test_quoted_string_helper("'abc' def", NULL, FALSE);
+ gplate_util_test_quoted_string_helper("'abc\"", NULL, FALSE);
+ gplate_util_test_quoted_string_helper("\"abc'", NULL, FALSE);
}
+gint
+main(gint argc, gchar **argv) {
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/util/quoted_string", gplate_util_test_quoted_string);
+
+ return g_test_run();
+}
+