summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-05-19 10:19:25 +0200
committerThomas Haller <thaller@redhat.com>2017-05-19 12:45:45 +0200
commit8df944c7e495d18bfecaf9d8316ef7783039c94b (patch)
tree2d1d6dd91d55183d2a042d3b19b52aab94353378
parent72104ea10a26d4b4ff245ed60c5ccd5c043c5fe0 (diff)
downloadNetworkManager-8df944c7e495d18bfecaf9d8316ef7783039c94b.tar.gz
libnm: add testable libnm/nm-libnm-utils.c file
Previously, internal parts of libnm were not testable. Instead, add "libnm/nm-libnm-utils.c" and "libnm/libnm-utils.la" to contain code that can be statically linked with a new test "libnm/tests/test-general".
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am45
-rw-r--r--libnm/nm-libnm-utils.c27
-rw-r--r--libnm/nm-libnm-utils.h26
-rw-r--r--libnm/tests/test-general.c34
5 files changed, 126 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index a2de16f61e..89a3fec76b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -182,6 +182,7 @@ test-*.trs
/libnm/nm-settings-docs.xml
/libnm/nm-settings-docs-overrides.xml
/libnm/nm-settings-keyfile-docs.xml
+/libnm/tests/test-general
/libnm/tests/test-nm-client
/libnm/tests/test-remote-settings-client
/libnm/tests/test-secret-agent
diff --git a/Makefile.am b/Makefile.am
index 32b6ba65f8..1bf3e96d26 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -737,6 +737,7 @@ libnm_lib_h_pub_nointrospect = \
libnm_lib_h_pub_mkenums = \
libnm/nm-enum-types.h
libnm_lib_h_priv = \
+ libnm/nm-libnm-utils.h \
libnm/nm-dbus-helpers.h \
libnm/nm-device-private.h \
libnm/nm-dhcp4-config.h \
@@ -793,6 +794,14 @@ libnm_lib_c_real = \
libnm_lib_c_mkenums = \
libnm/nm-enum-types.c
+libnm_lib_cppflags = \
+ $(dflt_cppflags_libnm_core) \
+ -I$(srcdir)/libnm \
+ -I$(builddir)/libnm \
+ -DG_LOG_DOMAIN=\""libnm"\" \
+ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
+ -DNMRUNDIR=\"$(nmrundir)\"
+
libnminclude_HEADERS += \
$(libnm_lib_h_pub_real) \
$(libnm_lib_h_pub_nointrospect)
@@ -802,6 +811,23 @@ nodist_libnminclude_HEADERS += \
###############################################################################
+lib_LTLIBRARIES += libnm/libnm-utils.la
+
+libnm_libnm_utils_la_CPPFLAGS = \
+ $(libnm_lib_cppflags)
+
+libnm_libnm_utils_la_SOURCES = \
+ libnm/nm-libnm-utils.c
+
+libnm_libnm_utils_la_LIBADD = \
+ libnm-core/libnm-core.la \
+ introspection/libnmdbus.la \
+ $(GLIB_LIBS)
+
+$(libnm_libnm_utils_la_OBJECTS) : $(libnm_lib_h_pub_mkenums)
+
+###############################################################################
+
lib_LTLIBRARIES += libnm/libnm.la
GLIB_GENERATED += \
@@ -820,13 +846,8 @@ $(libnm_libnm_la_OBJECTS): $(libnm_lib_h_pub_mkenum
$(libnm_tests_libnm_vpn_plugin_utils_test_la_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
libnm_libnm_la_CPPFLAGS = \
- $(dflt_cppflags_libnm_core) \
- -I$(srcdir)/libnm \
- -I$(builddir)/libnm \
- $(LIBUDEV_CFLAGS) \
- -DG_LOG_DOMAIN=\""libnm"\" \
- -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
- -DNMRUNDIR=\"$(nmrundir)\"
+ $(libnm_lib_cppflags) \
+ $(LIBUDEV_CFLAGS)
libnm_libnm_la_SOURCES = \
$(libnm_lib_h_pub_real) \
@@ -844,6 +865,7 @@ EXTRA_libnm_libnm_la_DEPENDENCIES = \
libnm_libnm_la_LIBADD = \
libnm-core/libnm-core.la \
introspection/libnmdbus.la \
+ libnm/libnm-utils.la \
$(DL_LIBS) \
$(GLIB_LIBS) \
$(UUID_LIBS) \
@@ -950,6 +972,7 @@ EXTRA_DIST += \
###############################################################################
libnm_tests_programs = \
+ libnm/tests/test-general \
libnm/tests/test-nm-client \
libnm/tests/test-remote-settings-client \
libnm/tests/test-secret-agent
@@ -967,10 +990,14 @@ libnm_tests_ldadd = \
libnm/libnm.la \
$(GLIB_LIBS)
+libnm_tests_test_general_CPPFLAGS = $(libnm_tests_cppflags)
libnm_tests_test_nm_client_CPPFLAGS = $(libnm_tests_cppflags)
libnm_tests_test_remote_settings_client_CPPFLAGS = $(libnm_tests_cppflags)
libnm_tests_test_secret_agent_CPPFLAGS = $(libnm_tests_cppflags)
+libnm_tests_test_general_SOURCES = \
+ libnm/tests/test-general.c
+
libnm_tests_test_nm_client_SOURCES = \
shared/nm-test-utils-impl.c \
shared/nm-test-libnm-utils.h \
@@ -986,10 +1013,14 @@ libnm_tests_test_secret_agent_SOURCES = \
shared/nm-test-libnm-utils.h \
libnm/tests/test-secret-agent.c
+libnm_tests_test_general_LDADD = \
+ libnm/libnm-utils.la \
+ $(libnm_tests_ldadd)
libnm_tests_test_nm_client_LDADD = $(libnm_tests_ldadd)
libnm_tests_test_remote_settings_client_LDADD = $(libnm_tests_ldadd)
libnm_tests_test_secret_agent_LDADD = $(libnm_tests_ldadd)
+$(libnm_tests_test_general_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(libnm_tests_test_nm_client_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(libnm_tests_test_remote_settings_client_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(libnm_tests_test_secret_agent_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c
new file mode 100644
index 0000000000..8cea276059
--- /dev/null
+++ b/libnm/nm-libnm-utils.c
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2008 Novell, Inc.
+ * Copyright 2007 - 2017 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "nm-libnm-utils.h"
+
+/*****************************************************************************/
+
diff --git a/libnm/nm-libnm-utils.h b/libnm/nm-libnm-utils.h
new file mode 100644
index 0000000000..356b2f9dab
--- /dev/null
+++ b/libnm/nm-libnm-utils.h
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2017 Red Hat, Inc.
+ */
+
+#ifndef __NM_LIBNM_UTILS_H__
+#define __NM_LIBNM_UTILS_H__
+
+
+
+#endif /* __NM_LIBNM_UTILS_H__ */
diff --git a/libnm/tests/test-general.c b/libnm/tests/test-general.c
new file mode 100644
index 0000000000..2653cb913d
--- /dev/null
+++ b/libnm/tests/test-general.c
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ *
+ * 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, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT SC 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 2017 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include "nm-utils/nm-test-utils.h"
+
+/*****************************************************************************/
+
+NMTST_DEFINE ();
+
+int main (int argc, char **argv)
+{
+ nmtst_init (&argc, &argv, TRUE);
+
+ return g_test_run ();
+}