From 59bc300ceeaa7f1836696cf23da03936b7792031 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 18 Jan 2009 18:43:18 -0500 Subject: [PATCH] move test functions somewhere commonly accessible --- include/Makefile.am | 3 +- include/nm-test-helpers.h | 48 +++++++++++++++++++ .../plugins/keyfile/tests/test-keyfile.c | 21 +------- 3 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 include/nm-test-helpers.h diff --git a/include/Makefile.am b/include/Makefile.am index d02c5f84d1..54c4d1dc80 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,7 +3,8 @@ EXTRA_DIST = \ NetworkManagerVPN.h \ wireless-helper.h \ nm-dbus-glib-types.h \ - nm-glib-compat.h + nm-glib-compat.h \ + nm-test-helpers.h NetworkManagerincludedir=$(includedir)/NetworkManager diff --git a/include/nm-test-helpers.h b/include/nm-test-helpers.h new file mode 100644 index 0000000000..0dac481dc2 --- /dev/null +++ b/include/nm-test-helpers.h @@ -0,0 +1,48 @@ +/* NetworkManager -- Network link manager + * + * Dan Williams + * + * 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. + * + * (C) Copyright 2008 Red Hat, Inc. + */ + +#ifndef NM_TEST_HELPERS_H +#define NM_TEST_HELPERS_H + +#include +#include + +static void +FAIL(const char *test_name, const char *fmt, ...) +{ + va_list args; + char buf[500]; + + snprintf (buf, 500, "FAIL: (%s) %s\n", test_name, fmt); + + va_start (args, fmt); + vfprintf (stderr, buf, args); + va_end (args); + _exit (1); +} + +#define ASSERT(x, test_name, fmt, ...) \ + if (!(x)) { \ + FAIL (test_name, fmt, ## __VA_ARGS__); \ + } + +#endif /* NM_TEST_HELPERS_H */ + diff --git a/system-settings/plugins/keyfile/tests/test-keyfile.c b/system-settings/plugins/keyfile/tests/test-keyfile.c index cbd73f1eab..bd1ee02af3 100644 --- a/system-settings/plugins/keyfile/tests/test-keyfile.c +++ b/system-settings/plugins/keyfile/tests/test-keyfile.c @@ -35,31 +35,14 @@ #include #include +#include "nm-test-helpers.h" + #include "reader.h" #include "writer.h" #define TEST_WIRED_FILE TEST_KEYFILES_DIR"/Test_Wired_Connection" #define TEST_WIRELESS_FILE TEST_KEYFILES_DIR"/Test_Wireless_Connection" -static void -FAIL(const char *test_name, const char *fmt, ...) -{ - va_list args; - char buf[500]; - - snprintf (buf, 500, "FAIL: (%s) %s\n", test_name, fmt); - - va_start (args, fmt); - vfprintf (stderr, buf, args); - va_end (args); - _exit (1); -} - -#define ASSERT(x, test_name, fmt, ...) \ - if (!(x)) { \ - FAIL (test_name, fmt, ## __VA_ARGS__); \ - } - static void test_read_valid_wired_connection (void) {