moving more testing stuff to it's new home and implementation
authorGary Kramlich <grim@reaperworld.com>
Sat Jun 26 15:25:18 2010 -0500 (19 months ago)
changeset 388301bcc8bdad0
parent 387 e9d714deb3a3
child 389 8baf0603ff07
moving more testing stuff to it's new home and implementation
gplate/CMakeLists.txt
gplate/tests/CMakeLists.txt
gplate/tests/test-collection-interface.c
gplate/tests/test-util-functions.c
tests/Makefile.am
tests/test-collection.h
tests/test-object.c
tests/test-object.h
tests/test-util.c
tests/test.c
     1.1 --- a/gplate/CMakeLists.txt	Sat Jun 26 13:56:06 2010 -0500
     1.2 +++ b/gplate/CMakeLists.txt	Sat Jun 26 15:25:18 2010 -0500
     1.3 @@ -1,4 +1,5 @@
     1.4  add_subdirectory(functions)
     1.5 +add_subdirectory(tests)
     1.6  add_subdirectory(tags)
     1.7  add_subdirectory(variables)
     1.8  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gplate/tests/CMakeLists.txt	Sat Jun 26 15:25:18 2010 -0500
     2.3 @@ -0,0 +1,10 @@
     2.4 +enable_testing()
     2.5 +
     2.6 +add_executable(test-collection-interface test-collection-interface.c)
     2.7 +target_link_libraries(test-collection-interface gplate)
     2.8 +add_test(GPlateCollectionInterface test-collection-interface)
     2.9 +
    2.10 +add_executable(test-util-functions test-util-functions.c)
    2.11 +target_link_libraries(test-util-functions gplate)
    2.12 +add_test(GPlateUtilityFunctions test-util-functions)
    2.13 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gplate/tests/test-collection-interface.c	Sat Jun 26 15:25:18 2010 -0500
     3.3 @@ -0,0 +1,18 @@
     3.4 +#include <gplate/gplate.h>
     3.5 +
     3.6 +#include <glib.h>
     3.7 +
     3.8 +/******************************************************************************
     3.9 + * Main
    3.10 + *****************************************************************************/
    3.11 +gint
    3.12 +main(gint argc, gchar **argv) {
    3.13 +	g_test_init(&argc, &argv, NULL);
    3.14 +
    3.15 +	g_type_init();
    3.16 +
    3.17 +	gplate_config_load_default();
    3.18 +
    3.19 +	return g_test_run();
    3.20 +}
    3.21 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/gplate/tests/test-util-functions.c	Sat Jun 26 15:25:18 2010 -0500
     4.3 @@ -0,0 +1,43 @@
     4.4 +#include <gplate/gplate.h>
     4.5 +
     4.6 +static void
     4.7 +gplate_util_test_quoted_string_helper(const gchar *string,
     4.8 +									  const gchar *contents, gboolean value)
     4.9 +{
    4.10 +	gboolean r = FALSE;
    4.11 +	gchar *c = NULL;
    4.12 +
    4.13 +	r = gplate_util_is_quoted_string(string, &c);
    4.14 +	g_assert_cmpint(r, ==, value);
    4.15 +
    4.16 +	if(contents)
    4.17 +		g_assert_cmpstr(c, ==, contents);
    4.18 +	
    4.19 +	g_free(c);
    4.20 +}
    4.21 +
    4.22 +static void
    4.23 +gplate_util_test_quoted_string(void) {
    4.24 +	gplate_util_test_quoted_string_helper("\"abc\"", "abc", TRUE);
    4.25 +	gplate_util_test_quoted_string_helper("\"abc def\"", "abc def", TRUE);
    4.26 +	gplate_util_test_quoted_string_helper("\"abc\tdef\bghi\"", "abc\tdef\bghi", TRUE);
    4.27 +	gplate_util_test_quoted_string_helper("abc \"def\"", NULL, FALSE);
    4.28 +	gplate_util_test_quoted_string_helper("\"abc\" def", NULL, FALSE);
    4.29 +	gplate_util_test_quoted_string_helper("'abc'", "abc", TRUE);
    4.30 +	gplate_util_test_quoted_string_helper("'abc def'", "abc def", TRUE);
    4.31 +	gplate_util_test_quoted_string_helper("'abc\tdef\bghi'", "abc\tdef\bghi", TRUE);
    4.32 +	gplate_util_test_quoted_string_helper("abc 'def'", NULL, FALSE);
    4.33 +	gplate_util_test_quoted_string_helper("'abc' def", NULL, FALSE);
    4.34 +	gplate_util_test_quoted_string_helper("'abc\"", NULL, FALSE);
    4.35 +	gplate_util_test_quoted_string_helper("\"abc'", NULL, FALSE);
    4.36 +}
    4.37 +
    4.38 +gint
    4.39 +main(gint argc, gchar **argv) {
    4.40 +	g_test_init(&argc, &argv, NULL);
    4.41 +
    4.42 +	g_test_add_func("/util/quoted_string", gplate_util_test_quoted_string);
    4.43 +
    4.44 +	return g_test_run();
    4.45 +}
    4.46 +
     5.1 --- a/tests/Makefile.am	Sat Jun 26 13:56:06 2010 -0500
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,38 +0,0 @@
     5.4 -EXTRA_DIST =
     5.5 -
     5.6 -SUBDIRS=templates
     5.7 -
     5.8 -LDADDS = \
     5.9 -	$(top_builddir)/gplate/libgplate.la \
    5.10 -	$(GLIB_LIBS)
    5.11 -
    5.12 -INCLUDES = \
    5.13 -	-I$(top_srcdir) \
    5.14 -	-I$(top_builddir)/gplate/
    5.15 -
    5.16 -noinst_PROGRAMS = \
    5.17 -	test-util \
    5.18 -	test-variables
    5.19 -
    5.20 -TEST_PROGS =
    5.21 -
    5.22 -TEST_PROGS += test-util
    5.23 -test_util_SOURCES = test-util.c
    5.24 -test_util_LDADD = $(LDADDS)	
    5.25 -
    5.26 -TEST_PROGS += test-variables
    5.27 -test_variables_SOURCES = test-variables.c
    5.28 -test_variables_LDADD = $(LDADDS)
    5.29 -
    5.30 -AM_CPPFLAGS=\
    5.31 -	$(DEBUG_CFLAGS) \
    5.32 -	$(GLIB_CFLAGS) \
    5.33 -	$(INCLUDES)
    5.34 -
    5.35 -test: $(TEST_PROGS)
    5.36 -	@test -z "$(TEST_PROGS)" || gtester --verbose -k $(TEST_PROGS)
    5.37 -
    5.38 -.PHONY: test
    5.39 -
    5.40 -check-local: test
    5.41 -
     6.1 --- a/tests/test-collection.h	Sat Jun 26 13:56:06 2010 -0500
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,15 +0,0 @@
     6.4 -#ifndef TEST_COLLECTION_H
     6.5 -#define TEST_COLLECTION_H
     6.6 -
     6.7 -#include <glib.h>
     6.8 -
     6.9 -#include <gplate/gplate.h>
    6.10 -
    6.11 -G_BEGIN_DECLS
    6.12 -
    6.13 -void test_collection_lookup(GPlateCollection *collection, const gchar *name, const gchar *expected);
    6.14 -void test_collection_lookup_int(GPlateCollection *collection, const gchar *name, gint expected);
    6.15 -
    6.16 -G_END_DECLS
    6.17 -
    6.18 -#endif /* TEST_COLLECTION_H */
     7.1 --- a/tests/test-object.c	Sat Jun 26 13:56:06 2010 -0500
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,17 +0,0 @@
     7.4 -#include <check.h>
     7.5 -
     7.6 -#include "test-object.h"
     7.7 -
     7.8 -void
     7.9 -test_object_is_a(GObject *obj, GType is_a) {
    7.10 -	GType type = G_TYPE_INVALID;
    7.11 -
    7.12 -	fail_unless(G_IS_OBJECT(obj), "'%p' is not an object.", obj);
    7.13 -
    7.14 -	type = G_OBJECT_TYPE(obj);
    7.15 -	fail_unless(type != G_TYPE_INVALID, "'%p' appears to not have a GType.", obj);
    7.16 -
    7.17 -	fail_unless(g_type_is_a(type, is_a), "'%s' is not a '%s'.",
    7.18 -				g_type_name(type), g_type_name(is_a));
    7.19 -}
    7.20 -
     8.1 --- a/tests/test-object.h	Sat Jun 26 13:56:06 2010 -0500
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,14 +0,0 @@
     8.4 -#ifndef TEST_OBJECT_H
     8.5 -#define TEST_OBJECT_H
     8.6 -
     8.7 -#include <glib.h>
     8.8 -
     8.9 -#include <gplate/gplate.h>
    8.10 -
    8.11 -G_BEGIN_DECLS
    8.12 -
    8.13 -void test_object_is_a(GObject *obj, GType is_a);
    8.14 -
    8.15 -G_END_DECLS
    8.16 -
    8.17 -#endif /* TEST_OBJECT_H */
     9.1 --- a/tests/test-util.c	Sat Jun 26 13:56:06 2010 -0500
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,43 +0,0 @@
     9.4 -#include <gplate/gplate.h>
     9.5 -
     9.6 -static void
     9.7 -gplate_util_test_quoted_string_helper(const gchar *string,
     9.8 -									  const gchar *contents, gboolean value)
     9.9 -{
    9.10 -	gboolean r = FALSE;
    9.11 -	gchar *c = NULL;
    9.12 -
    9.13 -	r = gplate_util_is_quoted_string(string, &c);
    9.14 -	g_assert_cmpint(r, ==, value);
    9.15 -
    9.16 -	if(contents)
    9.17 -		g_assert_cmpstr(c, ==, contents);
    9.18 -	
    9.19 -	g_free(c);
    9.20 -}
    9.21 -
    9.22 -static void
    9.23 -gplate_util_test_quoted_string(void) {
    9.24 -	gplate_util_test_quoted_string_helper("\"abc\"", "abc", TRUE);
    9.25 -	gplate_util_test_quoted_string_helper("\"abc def\"", "abc def", TRUE);
    9.26 -	gplate_util_test_quoted_string_helper("\"abc\tdef\bghi\"", "abc\tdef\bghi", TRUE);
    9.27 -	gplate_util_test_quoted_string_helper("abc \"def\"", NULL, FALSE);
    9.28 -	gplate_util_test_quoted_string_helper("\"abc\" def", NULL, FALSE);
    9.29 -	gplate_util_test_quoted_string_helper("'abc'", "abc", TRUE);
    9.30 -	gplate_util_test_quoted_string_helper("'abc def'", "abc def", TRUE);
    9.31 -	gplate_util_test_quoted_string_helper("'abc\tdef\bghi'", "abc\tdef\bghi", TRUE);
    9.32 -	gplate_util_test_quoted_string_helper("abc 'def'", NULL, FALSE);
    9.33 -	gplate_util_test_quoted_string_helper("'abc' def", NULL, FALSE);
    9.34 -	gplate_util_test_quoted_string_helper("'abc\"", NULL, FALSE);
    9.35 -	gplate_util_test_quoted_string_helper("\"abc'", NULL, FALSE);
    9.36 -}
    9.37 -
    9.38 -gint
    9.39 -main(gint argc, gchar **argv) {
    9.40 -	g_test_init(&argc, &argv, NULL);
    9.41 -
    9.42 -	g_test_add_func("/util/quoted_string", gplate_util_test_quoted_string);
    9.43 -
    9.44 -	return g_test_run();
    9.45 -}
    9.46 -
    10.1 --- a/tests/test.c	Sat Jun 26 13:56:06 2010 -0500
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,71 +0,0 @@
    10.4 -#include <glib.h>
    10.5 -
    10.6 -#include <check.h>
    10.7 -
    10.8 -#include <stdlib.h>
    10.9 -
   10.10 -#include <gplate/gplate.h>
   10.11 -
   10.12 -#include "test.h"
   10.13 -
   10.14 -/******************************************************************************
   10.15 - * Helpers
   10.16 - *****************************************************************************/
   10.17 -Suite *
   10.18 -master_suite(void) {
   10.19 -	Suite *s = suite_create("Master Suite");
   10.20 -
   10.21 -	return s;
   10.22 -}
   10.23 -
   10.24 -/******************************************************************************
   10.25 - * API
   10.26 - *****************************************************************************/
   10.27 -void
   10.28 -test_string(const gchar *expected, const gchar *actual) {
   10.29 -	fail_if(expected && !actual, TEST_EXPECTED_ACTUAL_MSG, expected, actual);
   10.30 -	fail_if(!expected && actual, TEST_EXPECTED_ACTUAL_MSG, expected, actual);
   10.31 -
   10.32 -	/* we need to handle a NULL value differently */
   10.33 -	if(!expected) {
   10.34 -		fail_unless(!expected, TEST_EXPECTED_ACTUAL_MSG, expected, actual);
   10.35 -	} else {
   10.36 -		fail_unless(g_utf8_collate(expected, actual) == 0,
   10.37 -					TEST_EXPECTED_ACTUAL_MSG, expected, actual);
   10.38 -	}
   10.39 -}
   10.40 -
   10.41 -/******************************************************************************
   10.42 - * Main!!
   10.43 - *****************************************************************************/
   10.44 -gint
   10.45 -main(void) {
   10.46 -	gint nfail = 0;
   10.47 -	SRunner *sr = NULL;
   10.48 -
   10.49 -	g_type_init();
   10.50 -
   10.51 -	gplate_config_load_default();
   10.52 -
   10.53 -	sr = srunner_create(master_suite());
   10.54 -
   10.55 -	srunner_set_xml(sr, "gplate-tests.xml");
   10.56 -
   10.57 -	srunner_add_suite(sr, variable_suite());
   10.58 -	srunner_add_suite(sr, dictionary_variable_suite());
   10.59 -	srunner_add_suite(sr, file_variable_suite());
   10.60 -
   10.61 -	srunner_add_suite(sr, syntax_suite());
   10.62 -
   10.63 -	srunner_add_suite(sr, for_suite());
   10.64 -	srunner_add_suite(sr, include_suite());
   10.65 -
   10.66 -	srunner_add_suite(sr, test_util_suite());
   10.67 -
   10.68 -	srunner_run_all(sr, CK_NORMAL);
   10.69 -	nfail = srunner_ntests_failed(sr);
   10.70 -	srunner_free(sr);
   10.71 -
   10.72 -	return (nfail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
   10.73 -}
   10.74 -