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".
This commit is contained in:
Thomas Haller 2017-05-19 10:19:25 +02:00
parent 72104ea10a
commit 8df944c7e4
5 changed files with 126 additions and 7 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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)

27
libnm/nm-libnm-utils.c Normal file
View File

@ -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"
/*****************************************************************************/

26
libnm/nm-libnm-utils.h Normal file
View File

@ -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__ */

View File

@ -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 ();
}