summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-10-07 12:00:53 +0200
committerThomas Haller <thaller@redhat.com>2016-10-11 11:37:46 +0200
commiteab8b06d8b958bcabb2397cbc68e4525c2d8f7db (patch)
tree66704d466f92e56326fef42ba162a20651bf064d
parent254f892c9c6c5b52c9cf5cd4784f8545c9f4c913 (diff)
ifcfg-rh/tests: merge test-ifcfg-rh-utils into test-ifcfg-rh
We don't need need separate unit tests for basic tests that can just run in the same test-run. If you really need to run only a particular set of tests, try ./src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh -p /settings/plugins/ifcfg-rh/utils Results in less compilation (time), and less binaries to test during `make check`.
-rw-r--r--.gitignore2
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/Makefile.am13
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c155
-rw-r--r--src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c119
4 files changed, 121 insertions, 168 deletions
diff --git a/.gitignore b/.gitignore
index 46c69ace1..ba1463955 100644
--- a/.gitignore
+++ b/.gitignore
@@ -252,7 +252,6 @@ test-*.trs
/src/settings/plugins/ibft/tests/test-ibft
/src/settings/plugins/ifcfg-rh/nmdbus-ifcfg-rh.[ch]
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh
-/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
/src/settings/plugins/ifnet/tests/test-ifnet
/src/settings/plugins/ifupdown/tests/test-ifupdown
/src/settings/plugins/keyfile/tests/test-keyfile
@@ -281,4 +280,5 @@ test-*.trs
/initscript/Slackware/rc.networkmanager
/initscript/*/[Nn]etwork[Mm]anager
/src/devices/wifi/tests/test-wifi-ap-utils
+/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
/src/settings/plugins/ifnet/tests/check_ifnet
diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am
index 434c56ce9..8b94006cd 100644
--- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am
+++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am
@@ -28,7 +28,7 @@ AM_LDFLAGS = \
$(GLIB_LIBS) \
$(CODE_COVERAGE_LDFLAGS)
-noinst_PROGRAMS = test-ifcfg-rh test-ifcfg-rh-utils
+noinst_PROGRAMS = test-ifcfg-rh
test_ifcfg_rh_SOURCES = \
test-ifcfg-rh.c \
@@ -40,19 +40,10 @@ test_ifcfg_rh_SOURCES = \
test_ifcfg_rh_LDADD = \
$(top_builddir)/src/libNetworkManager.la
-test_ifcfg_rh_utils_SOURCES = \
- test-ifcfg-rh-utils.c \
- ../nms-ifcfg-rh-utils.c \
- ../shvar.c
-
-test_ifcfg_rh_utils_LDADD = \
- $(top_builddir)/src/libNetworkManager.la
-
@VALGRIND_RULES@
-TESTS = test-ifcfg-rh-utils test-ifcfg-rh
+TESTS = test-ifcfg-rh
check-local:
$(call check_so_symbols,$(builddir)/../.libs/libnm-settings-plugin-ifcfg-rh.so)
endif
-
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c
deleted file mode 100644
index 65a75f0b8..000000000
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* NetworkManager system settings service - keyfile plugin
- *
- * 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.
- *
- * Copyright (C) 2008 - 2011 Red Hat, Inc.
- */
-
-#include "nm-default.h"
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <string.h>
-
-#include "nms-ifcfg-rh-common.h"
-#include "nms-ifcfg-rh-utils.h"
-
-#include "nm-test-utils-core.h"
-
-static void
-test_get_ifcfg_name (const char *desc,
- const char *path,
- gboolean only_ifcfg,
- const char *expected)
-{
- const char *result;
-
- result = utils_get_ifcfg_name (path, only_ifcfg);
- g_assert_cmpstr (result, ==, expected);
-}
-
-static void
-test_get_ifcfg_path (const char *desc,
- const char *path,
- const char *expected)
-{
- char *result;
-
- result = utils_get_ifcfg_path (path);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
-}
-
-static void
-test_get_keys_path (const char *desc,
- const char *path,
- const char *expected)
-{
- char *result;
-
- result = utils_get_keys_path (path);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
-}
-
-static void
-test_get_route_path (const char *desc,
- const char *path,
- const char *expected)
-{
- char *result;
-
- result = utils_get_route_path (path);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
-}
-
-static void
-test_ignored (const char *desc, const char *path, gboolean expected_ignored)
-{
- gboolean result;
-
- result = utils_should_ignore_file (path, FALSE);
- g_assert (result == expected_ignored);
-}
-
-static void
-test_name (void)
-{
- test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL);
- test_get_ifcfg_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar");
- test_get_ifcfg_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah");
- test_get_ifcfg_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala");
- test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL);
- test_get_ifcfg_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL);
- test_get_ifcfg_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala");
- test_get_ifcfg_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala");
- test_get_ifcfg_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala");
-
- test_get_ifcfg_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL);
- test_get_ifcfg_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL);
- test_get_ifcfg_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL);
-}
-
-static void
-test_path (void)
-{
- test_get_ifcfg_path ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL);
- test_get_ifcfg_path ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah");
- test_get_ifcfg_path ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah");
- test_get_ifcfg_path ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah");
-
- test_get_keys_path ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL);
- test_get_keys_path ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar");
- test_get_keys_path ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar");
- test_get_keys_path ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar");
-
- test_get_route_path ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL);
- test_get_route_path ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar");
- test_get_route_path ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar");
- test_get_route_path ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar");
-}
-
-static void
-test_ignore (void)
-{
- test_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE);
- test_ignored ("ignored-keys", "keys-FooBar", FALSE);
- test_ignored ("ignored-route", "route-FooBar", FALSE);
- test_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE);
- test_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE);
- test_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE);
- test_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE);
- test_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE);
- test_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE);
- test_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE);
-}
-
-NMTST_DEFINE ();
-
-int main (int argc, char **argv)
-{
- nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT");
-
- /* The tests */
- g_test_add_func ("/settings/plugins/ifcfg-rh/name", test_name);
- g_test_add_func ("/settings/plugins/ifcfg-rh/path", test_path);
- g_test_add_func ("/settings/plugins/ifcfg-rh/ignore", test_ignore);
-
- return g_test_run ();
-}
-
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 2869f4838..8a12805c9 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -8850,6 +8850,120 @@ test_sit_read_ignore (void)
/*****************************************************************************/
+static void
+do_test_utils_name (const char *desc,
+ const char *path,
+ gboolean only_ifcfg,
+ const char *expected)
+{
+ const char *result;
+
+ result = utils_get_ifcfg_name (path, only_ifcfg);
+ g_assert_cmpstr (result, ==, expected);
+}
+
+static void
+test_utils_name (void)
+{
+ do_test_utils_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL);
+ do_test_utils_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar");
+ do_test_utils_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah");
+ do_test_utils_name ("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala");
+ do_test_utils_name ("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL);
+ do_test_utils_name ("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL);
+ do_test_utils_name ("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala");
+ do_test_utils_name ("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala");
+ do_test_utils_name ("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala");
+
+ do_test_utils_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL);
+ do_test_utils_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL);
+ do_test_utils_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL);
+}
+
+/*****************************************************************************/
+
+static void
+do_test_utils_path_ifcfg (const char *desc,
+ const char *path,
+ const char *expected)
+{
+ char *result;
+
+ result = utils_get_ifcfg_path (path);
+ g_assert_cmpstr (result, ==, expected);
+ g_free (result);
+}
+
+static void
+do_test_utils_path_keys (const char *desc,
+ const char *path,
+ const char *expected)
+{
+ char *result;
+
+ result = utils_get_keys_path (path);
+ g_assert_cmpstr (result, ==, expected);
+ g_free (result);
+}
+
+static void
+do_test_utils_path_route (const char *desc,
+ const char *path,
+ const char *expected)
+{
+ char *result;
+
+ result = utils_get_route_path (path);
+ g_assert_cmpstr (result, ==, expected);
+ g_free (result);
+}
+
+static void
+test_utils_path (void)
+{
+ do_test_utils_path_ifcfg ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL);
+ do_test_utils_path_ifcfg ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah");
+ do_test_utils_path_ifcfg ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah");
+ do_test_utils_path_ifcfg ("ifcfg-path-from-route", "/foo/bar/route-BlahBlah", "/foo/bar/ifcfg-BlahBlah");
+
+ do_test_utils_path_keys ("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL);
+ do_test_utils_path_keys ("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar");
+ do_test_utils_path_keys ("keys-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/keys-FooBar");
+ do_test_utils_path_keys ("keys-path-from-route", "/foo/bar/route-FooBar", "/foo/bar/keys-FooBar");
+
+ do_test_utils_path_route ("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL);
+ do_test_utils_path_route ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar");
+ do_test_utils_path_route ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar");
+ do_test_utils_path_route ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar");
+}
+
+/*****************************************************************************/
+
+static void
+do_test_utils_ignored (const char *desc, const char *path, gboolean expected_ignored)
+{
+ gboolean result;
+
+ result = utils_should_ignore_file (path, FALSE);
+ g_assert (result == expected_ignored);
+}
+
+static void
+test_utils_ignore (void)
+{
+ do_test_utils_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE);
+ do_test_utils_ignored ("ignored-keys", "keys-FooBar", FALSE);
+ do_test_utils_ignored ("ignored-route", "route-FooBar", FALSE);
+ do_test_utils_ignored ("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE);
+ do_test_utils_ignored ("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE);
+ do_test_utils_ignored ("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE);
+ do_test_utils_ignored ("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE);
+ do_test_utils_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE);
+ do_test_utils_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE);
+ do_test_utils_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE);
+}
+
+/*****************************************************************************/
#define TPATH "/settings/plugins/ifcfg-rh/"
@@ -9098,6 +9212,9 @@ int main (int argc, char **argv)
g_test_add_data_func (TPATH "wwan/write-gsm", GUINT_TO_POINTER (TRUE), test_write_mobile_broadband);
g_test_add_data_func (TPATH "wwan/write-cdma", GUINT_TO_POINTER (FALSE), test_write_mobile_broadband);
+ g_test_add_func (TPATH "utils/name", test_utils_name);
+ g_test_add_func (TPATH "utils/path", test_utils_path);
+ g_test_add_func (TPATH "utils/ignore", test_utils_ignore);
+
return g_test_run ();
}
-