config: move NMConfig into its own subdirectory/library
Also, remove the unused NMConfigError, and add a config-parsing test program.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -178,6 +178,7 @@ src/tests/test-dhcp-options
|
||||
src/tests/test-policy-hosts
|
||||
src/tests/test-wifi-ap-utils
|
||||
src/dhcp-manager/tests/test-dhcp-dhclient
|
||||
src/config/tests/test-config
|
||||
|
||||
src/settings/plugins/keyfile/tests/test-keyfile
|
||||
src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh
|
||||
|
@@ -635,6 +635,8 @@ src/Makefile
|
||||
src/tests/Makefile
|
||||
src/generated/Makefile
|
||||
src/logging/Makefile
|
||||
src/config/Makefile
|
||||
src/config/tests/Makefile
|
||||
src/posix-signals/Makefile
|
||||
src/dns-manager/Makefile
|
||||
src/vpn-manager/Makefile
|
||||
|
@@ -1,6 +1,7 @@
|
||||
SUBDIRS= \
|
||||
generated \
|
||||
logging \
|
||||
config \
|
||||
posix-signals \
|
||||
dns-manager \
|
||||
vpn-manager \
|
||||
@@ -29,6 +30,7 @@ INCLUDES = -I${top_srcdir} \
|
||||
-I${top_builddir}/src/generated \
|
||||
-I${top_srcdir}/src/generated \
|
||||
-I${top_srcdir}/src/logging \
|
||||
-I${top_srcdir}/src/config \
|
||||
-I${top_srcdir}/src/posix-signals \
|
||||
-I${top_srcdir}/src/dns-manager \
|
||||
-I${top_srcdir}/src/vpn-manager \
|
||||
@@ -161,8 +163,6 @@ NetworkManager_SOURCES = \
|
||||
nm-ip6-config.h \
|
||||
nm-active-connection.h \
|
||||
nm-active-connection.c \
|
||||
nm-config.h \
|
||||
nm-config.c \
|
||||
main.c \
|
||||
nm-policy.c \
|
||||
nm-policy.h \
|
||||
@@ -323,6 +323,7 @@ endif
|
||||
NetworkManager_LDADD = \
|
||||
./generated/libnm-generated.la \
|
||||
./logging/libnm-logging.la \
|
||||
./config/libnm-config.la \
|
||||
./posix-signals/libnm-posix-signals.la \
|
||||
./dns-manager/libdns-manager.la \
|
||||
./vpn-manager/libvpn-manager.la \
|
||||
|
16
src/config/Makefile.am
Normal file
16
src/config/Makefile.am
Normal file
@@ -0,0 +1,16 @@
|
||||
SUBDIRS = . tests
|
||||
|
||||
noinst_LTLIBRARIES = libnm-config.la
|
||||
|
||||
libnm_config_la_SOURCES = \
|
||||
nm-config.c \
|
||||
nm-config.h
|
||||
|
||||
libnm_config_la_CPPFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
-I$(top_srcdir)/src/logging \
|
||||
-DNMCONFDIR=\"$(nmconfdir)\"
|
||||
|
||||
libnm_config_la_LIBADD = \
|
||||
$(GLIB_LIBS)
|
||||
|
@@ -48,17 +48,6 @@ G_DEFINE_TYPE (NMConfig, nm_config, G_TYPE_OBJECT)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
GQuark
|
||||
nm_config_error_quark (void)
|
||||
{
|
||||
static GQuark quark = 0;
|
||||
if (!quark)
|
||||
quark = g_quark_from_static_string ("nm-config-error");
|
||||
return quark;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
const char *
|
||||
nm_config_get_path (NMConfig *config)
|
||||
{
|
@@ -44,13 +44,6 @@ typedef struct {
|
||||
|
||||
GType nm_config_get_type (void);
|
||||
|
||||
typedef enum {
|
||||
NM_CONFIG_ERROR_NO_MEMORY = 0, /*< nick=NoMemory >*/
|
||||
} NMConfigError;
|
||||
|
||||
#define NM_CONFIG_ERROR (nm_config_error_quark ())
|
||||
GQuark nm_config_error_quark (void);
|
||||
|
||||
NMConfig *nm_config_get (void);
|
||||
NMConfig *nm_config_new (const char *cli_config_path,
|
||||
const char *cli_plugins,
|
24
src/config/tests/Makefile.am
Normal file
24
src/config/tests/Makefile.am
Normal file
@@ -0,0 +1,24 @@
|
||||
if ENABLE_TESTS
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_srcdir)/src/config
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
test-config
|
||||
|
||||
test_config_CPPFLAGS = \
|
||||
-DSRCDIR=\""$(srcdir)"\" \
|
||||
$(GLIB_CFLAGS)
|
||||
|
||||
test_config_LDADD = \
|
||||
$(top_builddir)/src/config/libnm-config.la \
|
||||
$(top_builddir)/src/logging/libnm-logging.la
|
||||
|
||||
check-local: test-config
|
||||
$(abs_builddir)/test-config
|
||||
|
||||
EXTRA_DIST = \
|
||||
NetworkManager.conf \
|
||||
bad.conf
|
||||
|
||||
endif
|
14
src/config/tests/NetworkManager.conf
Normal file
14
src/config/tests/NetworkManager.conf
Normal file
@@ -0,0 +1,14 @@
|
||||
[main]
|
||||
dhcp=dhclient
|
||||
plugins=foo,bar,baz
|
||||
|
||||
[logging]
|
||||
level=INFO
|
||||
|
||||
[connectivity]
|
||||
uri=http://example.com
|
||||
interval=100
|
||||
response=Hello
|
||||
|
||||
[extra-section]
|
||||
extra-key=some value
|
1
src/config/tests/bad.conf
Normal file
1
src/config/tests/bad.conf
Normal file
@@ -0,0 +1 @@
|
||||
This is not a keyfile.
|
120
src/config/tests/test-config.c
Normal file
120
src/config/tests/test-config.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* -*- 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 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 2013 Red Hat, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <nm-config.h>
|
||||
|
||||
static void
|
||||
test_config_simple (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
GError *error = NULL;
|
||||
const char **plugins;
|
||||
|
||||
config = nm_config_new (SRCDIR "/NetworkManager.conf",
|
||||
NULL, NULL, NULL, NULL, -1, NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_cmpstr (nm_config_get_path (config), ==, SRCDIR "/NetworkManager.conf");
|
||||
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
|
||||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_get_connectivity_interval (config), ==, 100);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 3);
|
||||
g_assert_cmpstr (plugins[0], ==, "foo");
|
||||
g_assert_cmpstr (plugins[1], ==, "bar");
|
||||
g_assert_cmpstr (plugins[2], ==, "baz");
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
static void
|
||||
test_config_non_existent (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
GError *error = NULL;
|
||||
|
||||
config = nm_config_new (SRCDIR "/no-such-file",
|
||||
NULL, NULL, NULL, NULL, -1, NULL,
|
||||
&error);
|
||||
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND);
|
||||
}
|
||||
|
||||
static void
|
||||
test_config_parse_error (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
GError *error = NULL;
|
||||
|
||||
config = nm_config_new (SRCDIR "/bad.conf",
|
||||
NULL, NULL, NULL, NULL, -1, NULL,
|
||||
&error);
|
||||
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_config_override (void)
|
||||
{
|
||||
NMConfig *config;
|
||||
GError *error = NULL;
|
||||
const char **plugins;
|
||||
|
||||
config = nm_config_new (SRCDIR "/NetworkManager.conf",
|
||||
"alpha,beta,gamma,delta", NULL, NULL, NULL, 12, NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
g_assert_cmpstr (nm_config_get_path (config), ==, SRCDIR "/NetworkManager.conf");
|
||||
g_assert_cmpstr (nm_config_get_dhcp_client (config), ==, "dhclient");
|
||||
g_assert_cmpstr (nm_config_get_log_level (config), ==, "INFO");
|
||||
g_assert_cmpint (nm_config_get_connectivity_interval (config), ==, 12);
|
||||
|
||||
plugins = nm_config_get_plugins (config);
|
||||
g_assert_cmpint (g_strv_length ((char **)plugins), ==, 4);
|
||||
g_assert_cmpstr (plugins[0], ==, "alpha");
|
||||
g_assert_cmpstr (plugins[1], ==, "beta");
|
||||
g_assert_cmpstr (plugins[2], ==, "gamma");
|
||||
g_assert_cmpstr (plugins[3], ==, "delta");
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
g_type_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/config/simple", test_config_simple);
|
||||
g_test_add_func ("/config/non-existent", test_config_non_existent);
|
||||
g_test_add_func ("/config/parse-error", test_config_parse_error);
|
||||
|
||||
/* This one has to come last, because it leaves its values in
|
||||
* nm-config.c's global variables, and there's no way to reset
|
||||
* those to NULL.
|
||||
*/
|
||||
g_test_add_func ("/config/override", test_config_override);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ libnm_generated_la_SOURCES = \
|
||||
nm_daemon_all_sources = \
|
||||
$(top_srcdir)/src/*.[ch] \
|
||||
$(top_srcdir)/src/logging/*.[ch] \
|
||||
$(top_srcdir)/src/config/*.[ch] \
|
||||
$(top_srcdir)/src/dns-manager/*.[ch] \
|
||||
$(top_srcdir)/src/vpn-manager/*.[ch] \
|
||||
$(top_srcdir)/src/dhcp-manager/*.[ch] \
|
||||
@@ -55,6 +56,7 @@ INCLUDES = \
|
||||
-I${top_builddir}/include \
|
||||
-I${top_srcdir}/src \
|
||||
-I${top_srcdir}/src/logging \
|
||||
-I${top_srcdir}/src/config \
|
||||
-I${top_srcdir}/src/dns-manager \
|
||||
-I${top_srcdir}/src/vpn-manager \
|
||||
-I${top_srcdir}/src/dhcp-manager \
|
||||
|
Reference in New Issue
Block a user