From b992bb9e62f4430ad0cfbf81b5d1fabcd0492dbb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 3 Nov 2011 12:22:43 +0000 Subject: [PATCH 09/14] Turn _dbus_glib_test into a standalone test case, since it only tests public API --- .gitignore | 1 + dbus/dbus-glib.c | 29 ------------------- dbus/dbus-gtest.c | 4 --- dbus/dbus-gtest.h | 1 - test/Makefile.am | 37 +++++++++++++++++++++---- test/errors.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 40 deletions(-) create mode 100644 test/errors.c diff --git a/.gitignore b/.gitignore index 5652fa8..01c4493 100644 --- a/.gitignore +++ b/.gitignore @@ -191,6 +191,7 @@ missing stamp-h1 test/Makefile test/Makefile.in +/test/test-errors test/core/Makefile test/core/Makefile.in test/core/my-object-marshal.c diff --git a/dbus/dbus-glib.c b/dbus/dbus-glib.c index 4ca8db6..df36ecf 100644 --- a/dbus/dbus-glib.c +++ b/dbus/dbus-glib.c @@ -367,32 +367,3 @@ dbus_g_message_get_message (DBusGMessage *gmessage) { return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage); } - -#ifdef DBUS_BUILD_TESTS - -/* - * Unit test for general glib stuff - * Returns: %TRUE on success. - */ -gboolean -_dbus_glib_test (const char *test_data_dir) -{ - DBusError err; - GError *gerror = NULL; - - dbus_error_init (&err); - dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!"); - - dbus_set_g_error (&gerror, &err); - g_assert (gerror != NULL); - g_assert (gerror->domain == DBUS_GERROR); - g_assert (gerror->code == DBUS_GERROR_NO_MEMORY); - g_assert (!strcmp (gerror->message, "Out of memory!")); - - dbus_error_init (&err); - g_clear_error (&gerror); - - return TRUE; -} - -#endif /* DBUS_BUILD_TESTS */ diff --git a/dbus/dbus-gtest.c b/dbus/dbus-gtest.c index 9783efd..59dbe5b 100644 --- a/dbus/dbus-gtest.c +++ b/dbus/dbus-gtest.c @@ -67,10 +67,6 @@ dbus_glib_internal_do_not_use_run_tests (const char *test_data_dir) if (!_dbus_gvalue_test (test_data_dir)) die ("gvalue utils"); - printf ("%s: running glib tests\n", "dbus-glib-test"); - if (!_dbus_glib_test (test_data_dir)) - die ("glib"); - printf ("%s: running mainloop integration tests\n", "dbus-glib-test"); if (!_dbus_gmain_test (test_data_dir)) die ("gmain"); diff --git a/dbus/dbus-gtest.h b/dbus/dbus-gtest.h index 7a57b51..b94f506 100644 --- a/dbus/dbus-gtest.h +++ b/dbus/dbus-gtest.h @@ -29,7 +29,6 @@ gboolean _dbus_gmain_test (const char *test_data_dir); gboolean _dbus_gobject_test (const char *test_data_dir); gboolean _dbus_gutils_test (const char *test_data_dir); -gboolean _dbus_glib_test (const char *test_data_dir); gboolean _dbus_gvalue_test (const char *test_data_dir); gboolean _dbus_gvalue_utils_test (const char *test_data_dir); diff --git a/test/Makefile.am b/test/Makefile.am index 7ba11a8..cb18ff5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -5,15 +5,27 @@ INCLUDES = \ -I$(top_srcdir) \ -I$(top_builddir) \ -I$(top_builddir)/dbus \ - $(DBUS_CFLAGS) + $(DBUS_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(NULL) + +LDADD = \ + $(top_builddir)/dbus/libdbus-glib-1.la \ + $(DBUS_GLIB_LIBS) \ + $(NULL) if DBUS_BUILD_TESTS -TEST_BINARIES=test-service -else -TEST_BINARIES= +test_programs = \ + test-errors \ + $(NULL) + +# not actually tests, but used by tests +test_related_programs = \ + test-service \ + $(NULL) endif -noinst_PROGRAMS= $(TEST_BINARIES) +test_errors_SOURCES = errors.c test_service_SOURCES= \ test-service.c @@ -23,4 +35,17 @@ test_service_LDADD=$(DBUS_LIBS) EXTRA_DIST = data/nested-introspect.xml test-compile-nested.sh TESTS_ENVIRONMENT=top_builddir=$(top_builddir) srcdir=$(srcdir) -TESTS = test-compile-nested.sh + +test_scripts = \ + test-compile-nested.sh \ + $(NULL) + +TESTS = \ + $(test_programs) \ + $(test_scripts) \ + $(NULL) + +noinst_PROGRAMS = \ + $(test_programs) \ + $(test_related_programs) \ + $(NULL) diff --git a/test/errors.c b/test/errors.c new file mode 100644 index 0000000..ba08595 --- /dev/null +++ b/test/errors.c @@ -0,0 +1,79 @@ +/* Regression test for dbus-glib GError mapping + * + * Copyright © 2004 Red Hat, Inc. + * Copyright © 2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include + +#include + +#include + +#include +#include + +typedef struct { + int dummy; +} Fixture; + +static void +setup (Fixture *f G_GNUC_UNUSED, + gconstpointer context G_GNUC_UNUSED) +{ +} + +static void +test_errors (Fixture *f G_GNUC_UNUSED, + gconstpointer context G_GNUC_UNUSED) +{ + DBusError err; + GError *gerror = NULL; + + dbus_error_init (&err); + dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!"); + + dbus_set_g_error (&gerror, &err); + g_assert (gerror != NULL); + g_assert (gerror->domain == DBUS_GERROR); + g_assert (gerror->code == DBUS_GERROR_NO_MEMORY); + g_assert (!strcmp (gerror->message, "Out of memory!")); + + dbus_error_init (&err); + g_clear_error (&gerror); +} + +static void +teardown (Fixture *f G_GNUC_UNUSED, + gconstpointer addr G_GNUC_UNUSED) +{ +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + g_type_init (); + + g_test_add ("/errors", Fixture, NULL, setup, test_errors, teardown); + + return g_test_run (); +} -- 1.7.7.1