summary refs log tree commit diff
path: root/libnm-core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-core/tests')
-rw-r--r--libnm-core/tests/Makefile.am15
-rw-r--r--libnm-core/tests/Makefile.in42
-rw-r--r--libnm-core/tests/nm-core-tests-enum-types.c74
-rw-r--r--libnm-core/tests/nm-core-tests-enum-types.h23
-rw-r--r--libnm-core/tests/test-general-enums.h46
-rw-r--r--libnm-core/tests/test-general.c168
6 files changed, 358 insertions, 10 deletions
diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am
index daa5825b..dd38b3d6 100644
--- a/libnm-core/tests/Makefile.am
+++ b/libnm-core/tests/Makefile.am
@@ -1,5 +1,14 @@
 if ENABLE_TESTS
 
+include $(GLIB_MAKEFILE)
+
+GLIB_GENERATED = nm-core-tests-enum-types.h nm-core-tests-enum-types.c
+nm_core_tests_enum_types_sources = test-general-enums.h
+GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
+GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
+
+BUILT_SOURCES = $(GLIB_GENERATED)
+
 certsdir = $(srcdir)/certs
 
 AM_CPPFLAGS = \
@@ -28,6 +37,12 @@ LDADD = \
 @VALGRIND_RULES@
 TESTS = $(noinst_PROGRAMS)
 
+test_general_SOURCES = \
+	test-general.c \
+	test-general-enums.h \
+	nm-core-tests-enum-types.c \
+	nm-core-tests-enum-types.h
+
 endif
 
 # test-cert.p12 created with:
diff --git a/libnm-core/tests/Makefile.in b/libnm-core/tests/Makefile.in
index edb6a50e..a37acbe2 100644
--- a/libnm-core/tests/Makefile.in
+++ b/libnm-core/tests/Makefile.in
@@ -134,8 +134,11 @@ test_crypto_LDADD = $(LDADD)
 @ENABLE_TESTS_TRUE@test_crypto_DEPENDENCIES =  \
 @ENABLE_TESTS_TRUE@	$(top_builddir)/libnm-core/libnm-core.la \
 @ENABLE_TESTS_TRUE@	$(am__DEPENDENCIES_1)
-test_general_SOURCES = test-general.c
-test_general_OBJECTS = test-general.$(OBJEXT)
+am__test_general_SOURCES_DIST = test-general.c test-general-enums.h \
+	nm-core-tests-enum-types.c nm-core-tests-enum-types.h
+@ENABLE_TESTS_TRUE@am_test_general_OBJECTS = test-general.$(OBJEXT) \
+@ENABLE_TESTS_TRUE@	nm-core-tests-enum-types.$(OBJEXT)
+test_general_OBJECTS = $(am_test_general_OBJECTS)
 test_general_LDADD = $(LDADD)
 @ENABLE_TESTS_TRUE@test_general_DEPENDENCIES =  \
 @ENABLE_TESTS_TRUE@	$(top_builddir)/libnm-core/libnm-core.la \
@@ -204,12 +207,13 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
 am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
 am__v_CCLD_0 = @echo "  CCLD    " $@;
 am__v_CCLD_1 = 
-SOURCES = test-compare.c test-crypto.c test-general.c test-keyfile.c \
-	test-secrets.c test-setting-8021x.c test-setting-dcb.c \
-	test-settings-defaults.c
-DIST_SOURCES = test-compare.c test-crypto.c test-general.c \
+SOURCES = test-compare.c test-crypto.c $(test_general_SOURCES) \
 	test-keyfile.c test-secrets.c test-setting-8021x.c \
 	test-setting-dcb.c test-settings-defaults.c
+DIST_SOURCES = test-compare.c test-crypto.c \
+	$(am__test_general_SOURCES_DIST) test-keyfile.c test-secrets.c \
+	test-setting-8021x.c test-setting-dcb.c \
+	test-settings-defaults.c
 am__can_run_installinfo = \
   case $$AM_UPDATE_INFO_DIR in \
     n|no|NO) false;; \
@@ -703,6 +707,11 @@ with_dhcpcd = @with_dhcpcd@
 with_netconfig = @with_netconfig@
 with_resolvconf = @with_resolvconf@
 with_valgrind = @with_valgrind@
+@ENABLE_TESTS_TRUE@GLIB_GENERATED = nm-core-tests-enum-types.h nm-core-tests-enum-types.c
+@ENABLE_TESTS_TRUE@nm_core_tests_enum_types_sources = test-general-enums.h
+@ENABLE_TESTS_TRUE@GLIB_MKENUMS_H_FLAGS = --identifier-prefix NM
+@ENABLE_TESTS_TRUE@GLIB_MKENUMS_C_FLAGS = --identifier-prefix NM
+@ENABLE_TESTS_TRUE@BUILT_SOURCES = $(GLIB_GENERATED)
 @ENABLE_TESTS_TRUE@certsdir = $(srcdir)/certs
 @ENABLE_TESTS_TRUE@AM_CPPFLAGS = \
 @ENABLE_TESTS_TRUE@	-I${top_srcdir}/include \
@@ -718,6 +727,12 @@ with_valgrind = @with_valgrind@
 @ENABLE_TESTS_TRUE@	$(GLIB_LIBS)
 
 @ENABLE_TESTS_TRUE@TESTS = $(noinst_PROGRAMS)
+@ENABLE_TESTS_TRUE@test_general_SOURCES = \
+@ENABLE_TESTS_TRUE@	test-general.c \
+@ENABLE_TESTS_TRUE@	test-general-enums.h \
+@ENABLE_TESTS_TRUE@	nm-core-tests-enum-types.c \
+@ENABLE_TESTS_TRUE@	nm-core-tests-enum-types.h
+
 
 # test-cert.p12 created with:
 #
@@ -746,7 +761,8 @@ EXTRA_DIST = \
 	certs/test-key-only-decrypted.pem   \
 	certs/test-key-only.pem
 
-all: all-am
+all: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) all-am
 
 .SUFFIXES:
 .SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs
@@ -827,6 +843,7 @@ mostlyclean-compile:
 distclean-compile:
 	-rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nm-core-tests-enum-types.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-compare.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-crypto.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-general.Po@am__quote@
@@ -1159,10 +1176,12 @@ distdir: $(DISTFILES)
 	done
 check-am: all-am
 	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
-check: check-am
+check: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) check-am
 all-am: Makefile $(PROGRAMS)
 installdirs:
-install: install-am
+install: $(BUILT_SOURCES)
+	$(MAKE) $(AM_MAKEFLAGS) install-am
 install-exec: install-exec-am
 install-data: install-data-am
 uninstall: uninstall-am
@@ -1195,6 +1214,7 @@ distclean-generic:
 maintainer-clean-generic:
 	@echo "This command is intended for maintainers to use"
 	@echo "it deletes files that may require special tools to rebuild."
+	-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
 clean: clean-am
 
 clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
@@ -1266,7 +1286,7 @@ ps-am:
 
 uninstall-am:
 
-.MAKE: check-am install-am install-strip
+.MAKE: all check check-am install install-am install-strip
 
 .PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \
 	clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \
@@ -1285,6 +1305,8 @@ uninstall-am:
 .PRECIOUS: Makefile
 
 
+@ENABLE_TESTS_TRUE@include $(GLIB_MAKEFILE)
+
 @ENABLE_TESTS_TRUE@@VALGRIND_RULES@
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/libnm-core/tests/nm-core-tests-enum-types.c b/libnm-core/tests/nm-core-tests-enum-types.c
new file mode 100644
index 00000000..80271e52
--- /dev/null
+++ b/libnm-core/tests/nm-core-tests-enum-types.c
@@ -0,0 +1,74 @@
+
+
+
+/* Generated by glib-mkenums. Do not edit */
+
+#include "nm-core-tests-enum-types.h"
+
+#include "test-general-enums.h"
+
+GType
+nm_test_general_bool_enum_get_type (void)
+{
+  static volatile gsize g_define_type_id__volatile = 0;
+
+  if (g_once_init_enter (&g_define_type_id__volatile))
+    {
+      static const GEnumValue values[] = {
+        { NM_TEST_GENERAL_BOOL_ENUM_NO, "NM_TEST_GENERAL_BOOL_ENUM_NO", "no" },
+        { NM_TEST_GENERAL_BOOL_ENUM_YES, "NM_TEST_GENERAL_BOOL_ENUM_YES", "yes" },
+        { NM_TEST_GENERAL_BOOL_ENUM_MAYBE, "NM_TEST_GENERAL_BOOL_ENUM_MAYBE", "maybe" },
+        { NM_TEST_GENERAL_BOOL_ENUM_UNKNOWN, "NM_TEST_GENERAL_BOOL_ENUM_UNKNOWN", "unknown" },
+        { 0, NULL, NULL }
+      };
+      GType g_define_type_id =
+        g_enum_register_static (g_intern_static_string ("NMTestGeneralBoolEnum"), values);
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+    }
+
+  return g_define_type_id__volatile;
+}
+GType
+nm_test_general_meta_flags_get_type (void)
+{
+  static volatile gsize g_define_type_id__volatile = 0;
+
+  if (g_once_init_enter (&g_define_type_id__volatile))
+    {
+      static const GFlagsValue values[] = {
+        { NM_TEST_GENERAL_META_FLAGS_NONE, "NM_TEST_GENERAL_META_FLAGS_NONE", "none" },
+        { NM_TEST_GENERAL_META_FLAGS_FOO, "NM_TEST_GENERAL_META_FLAGS_FOO", "foo" },
+        { NM_TEST_GENERAL_META_FLAGS_BAR, "NM_TEST_GENERAL_META_FLAGS_BAR", "bar" },
+        { NM_TEST_GENERAL_META_FLAGS_BAZ, "NM_TEST_GENERAL_META_FLAGS_BAZ", "baz" },
+        { 0, NULL, NULL }
+      };
+      GType g_define_type_id =
+        g_flags_register_static (g_intern_static_string ("NMTestGeneralMetaFlags"), values);
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+    }
+
+  return g_define_type_id__volatile;
+}
+GType
+nm_test_general_color_flags_get_type (void)
+{
+  static volatile gsize g_define_type_id__volatile = 0;
+
+  if (g_once_init_enter (&g_define_type_id__volatile))
+    {
+      static const GFlagsValue values[] = {
+        { NM_TEST_GENERAL_COLOR_FLAGS_BLUE, "NM_TEST_GENERAL_COLOR_FLAGS_BLUE", "blue" },
+        { NM_TEST_GENERAL_COLOR_FLAGS_RED, "NM_TEST_GENERAL_COLOR_FLAGS_RED", "red" },
+        { NM_TEST_GENERAL_COLOR_FLAGS_GREEN, "NM_TEST_GENERAL_COLOR_FLAGS_GREEN", "green" },
+        { 0, NULL, NULL }
+      };
+      GType g_define_type_id =
+        g_flags_register_static (g_intern_static_string ("NMTestGeneralColorFlags"), values);
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+    }
+
+  return g_define_type_id__volatile;
+}
+
+
+
diff --git a/libnm-core/tests/nm-core-tests-enum-types.h b/libnm-core/tests/nm-core-tests-enum-types.h
new file mode 100644
index 00000000..90257866
--- /dev/null
+++ b/libnm-core/tests/nm-core-tests-enum-types.h
@@ -0,0 +1,23 @@
+
+
+
+/* Generated by glib-mkenums. Do not edit */
+
+#ifndef __NM_CORE_TESTS_ENUM_TYPES_H__
+#define __NM_CORE_TESTS_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+GType nm_test_general_bool_enum_get_type (void) G_GNUC_CONST;
+#define NM_TYPE_TEST_GENERAL_BOOL_ENUM (nm_test_general_bool_enum_get_type ())
+GType nm_test_general_meta_flags_get_type (void) G_GNUC_CONST;
+#define NM_TYPE_TEST_GENERAL_META_FLAGS (nm_test_general_meta_flags_get_type ())
+GType nm_test_general_color_flags_get_type (void) G_GNUC_CONST;
+#define NM_TYPE_TEST_GENERAL_COLOR_FLAGS (nm_test_general_color_flags_get_type ())
+G_END_DECLS
+
+#endif /* __NM_CORE_TESTS_ENUM_TYPES_H__ */
+
+
+
diff --git a/libnm-core/tests/test-general-enums.h b/libnm-core/tests/test-general-enums.h
new file mode 100644
index 00000000..d06d6e39
--- /dev/null
+++ b/libnm-core/tests/test-general-enums.h
@@ -0,0 +1,46 @@
+/* -*- 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 2015 Red Hat, Inc.
+ */
+
+#ifndef _NM_TEST_GENERAL_ENUMS_H_
+#define _NM_TEST_GENERAL_ENUMS_H_
+
+typedef enum {
+	NM_TEST_GENERAL_BOOL_ENUM_NO       = 0,
+	NM_TEST_GENERAL_BOOL_ENUM_YES      = 1,
+	NM_TEST_GENERAL_BOOL_ENUM_MAYBE    = 2,
+	NM_TEST_GENERAL_BOOL_ENUM_UNKNOWN  = 3,
+	NM_TEST_GENERAL_BOOL_ENUM_INVALID  = 4, /*< skip >*/
+} NMTestGeneralBoolEnum;
+
+typedef enum {
+	NM_TEST_GENERAL_META_FLAGS_NONE    = 0,
+	NM_TEST_GENERAL_META_FLAGS_FOO     = (1 << 0),
+	NM_TEST_GENERAL_META_FLAGS_BAR     = (1 << 1),
+	NM_TEST_GENERAL_META_FLAGS_BAZ     = (1 << 2),
+} NMTestGeneralMetaFlags;
+
+typedef enum {  /*< flags >*/
+	NM_TEST_GENERAL_COLOR_FLAGS_WHITE  = 1, /*< skip >*/
+	NM_TEST_GENERAL_COLOR_FLAGS_BLUE   = 2,
+	NM_TEST_GENERAL_COLOR_FLAGS_RED    = 4,
+	NM_TEST_GENERAL_COLOR_FLAGS_GREEN  = 8,
+} NMTestGeneralColorFlags;
+
+#endif /* _NM_TEST_GENERAL_ENUMS_H_ */
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index bd144f38..e9483652 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -32,6 +32,7 @@
 #include "nm-setting-private.h"
 #include "nm-utils.h"
 #include "nm-core-internal.h"
+#include "nm-core-tests-enum-types.h"
 
 #include "nm-setting-8021x.h"
 #include "nm-setting-adsl.h"
@@ -62,6 +63,7 @@
 #include "nm-glib-compat.h"
 
 #include "nm-test-utils.h"
+#include "test-general-enums.h"
 
 static void
 vpn_check_func (const char *key, const char *value, gpointer user_data)
@@ -1969,6 +1971,7 @@ test_connection_diff_a_only (void)
 			{ NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES,   NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_CONNECTION_SECONDARIES,          NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_CONNECTION_METERED,              NM_SETTING_DIFF_RESULT_IN_A },
 			{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN }
 		} },
 		{ NM_SETTING_WIRED_SETTING_NAME, {
@@ -1983,6 +1986,8 @@ test_connection_diff_a_only (void)
 			{ NM_SETTING_WIRED_S390_SUBCHANNELS,      NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_WIRED_S390_NETTYPE,          NM_SETTING_DIFF_RESULT_IN_A },
 			{ NM_SETTING_WIRED_S390_OPTIONS,          NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_WIRED_WAKE_ON_LAN,           NM_SETTING_DIFF_RESULT_IN_A },
+			{ NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD,  NM_SETTING_DIFF_RESULT_IN_A },
 			{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
 		} },
 		{ NM_SETTING_IP4_CONFIG_SETTING_NAME, {
@@ -4448,6 +4453,166 @@ test_nm_utils_ptrarray_find_binary_search (void)
 
 /******************************************************************************/
 
+static int
+_test_nm_in_set_get (int *call_counter, gboolean allow_called, int value)
+{
+	g_assert (call_counter);
+	*call_counter += 1;
+	if (!allow_called)
+		g_assert_not_reached ();
+	return value;
+}
+
+static void
+_test_nm_in_set_assert (int *call_counter, int expected)
+{
+	g_assert (call_counter);
+	g_assert_cmpint (expected, ==, *call_counter);
+	*call_counter = 0;
+}
+
+static void
+test_nm_in_set (void)
+{
+	int call_counter = 0;
+
+#define G(x) _test_nm_in_set_get (&call_counter, TRUE,  x)
+#define N(x) _test_nm_in_set_get (&call_counter, FALSE,  x)
+#define _ASSERT(expected, expr) \
+	G_STMT_START { \
+		_test_nm_in_set_assert (&call_counter, 0); \
+		g_assert (expr); \
+		_test_nm_in_set_assert (&call_counter, (expected)); \
+	} G_STMT_END
+	_ASSERT (1, !NM_IN_SET (-1, G( 1)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1)));
+
+	_ASSERT (2, !NM_IN_SET (-1, G( 1), G( 2)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N( 2)));
+	_ASSERT (2,  NM_IN_SET (-1, G( 1), G(-1)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N(-1)));
+
+	_ASSERT (3, !NM_IN_SET (-1, G( 1), G( 2), G( 3)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N( 2), N( 3)));
+	_ASSERT (2,  NM_IN_SET (-1, G( 1), G(-1), N( 3)));
+	_ASSERT (3,  NM_IN_SET (-1, G( 1), G( 2), G(-1)));
+	_ASSERT (2,  NM_IN_SET (-1, G( 1), G(-1), N(-1)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N( 2), N(-1)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N(-1), N( 3)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N(-1), N(-1)));
+
+	_ASSERT (4, !NM_IN_SET (-1, G( 1), G( 2), G( 3), G( 4)));
+	_ASSERT (1,  NM_IN_SET (-1, G(-1), N( 2), N( 3), N( 4)));
+	_ASSERT (2,  NM_IN_SET (-1, G( 1), G(-1), N( 3), N( 4)));
+	_ASSERT (3,  NM_IN_SET (-1, G( 1), G( 2), G(-1), N( 4)));
+	_ASSERT (4,  NM_IN_SET (-1, G( 1), G( 2), G( 3), G(-1)));
+
+	_ASSERT (4,  NM_IN_SET (-1, G( 1), G( 2), G( 3), G(-1), G( 5)));
+
+	_ASSERT (1, !NM_IN_SET_SE (-1, G( 1)));
+	_ASSERT (1,  NM_IN_SET_SE (-1, G(-1)));
+
+	_ASSERT (2, !NM_IN_SET_SE (-1, G( 1), G( 2)));
+	_ASSERT (2,  NM_IN_SET_SE (-1, G(-1), G( 2)));
+	_ASSERT (2,  NM_IN_SET_SE (-1, G( 1), G(-1)));
+	_ASSERT (2,  NM_IN_SET_SE (-1, G(-1), G(-1)));
+
+	_ASSERT (3, !NM_IN_SET_SE (-1, G( 1), G( 2), G( 3)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G(-1), G( 2), G( 3)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G( 1), G(-1), G( 3)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G( 1), G( 2), G(-1)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G( 1), G(-1), G(-1)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G(-1), G( 2), G(-1)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G(-1), G(-1), G( 3)));
+	_ASSERT (3,  NM_IN_SET_SE (-1, G(-1), G(-1), G(-1)));
+
+	_ASSERT (4, !NM_IN_SET_SE (-1, G( 1), G( 2), G( 3), G( 4)));
+	_ASSERT (4,  NM_IN_SET_SE (-1, G(-1), G( 2), G( 3), G( 4)));
+	_ASSERT (4,  NM_IN_SET_SE (-1, G( 1), G(-1), G( 3), G( 4)));
+	_ASSERT (4,  NM_IN_SET_SE (-1, G( 1), G( 2), G(-1), G( 4)));
+	_ASSERT (4,  NM_IN_SET_SE (-1, G( 1), G( 2), G( 3), G(-1)));
+
+	_ASSERT (5,  NM_IN_SET_SE (-1, G( 1), G( 2), G( 3), G(-1), G( 5)));
+#undef G
+#undef N
+#undef _ASSERT
+}
+
+/******************************************************************************/
+
+static void
+test_nm_utils_enum_from_str_do (GType type, const char *str,
+                                gboolean exp_result, int exp_flags,
+                                const char *exp_err_token)
+{
+	int flags = 1;
+	char *err_token = NULL;
+	gboolean result;
+
+	result = nm_utils_enum_from_str (type, str, &flags, &err_token);
+
+	g_assert (result == exp_result);
+	g_assert_cmpint (flags, ==, exp_flags);
+	g_assert_cmpstr (err_token, ==, exp_err_token);
+
+	g_free (err_token);
+}
+
+static void
+test_nm_utils_enum_to_str_do (GType type, int flags, const char *exp_str)
+{
+	char *str;
+
+	str = nm_utils_enum_to_str (type, flags);
+	g_assert_cmpstr (str, ==, exp_str);
+	g_free (str);
+}
+
+static void test_nm_utils_enum (void)
+{
+	GType bool_enum = nm_test_general_bool_enum_get_type();
+	GType meta_flags = nm_test_general_meta_flags_get_type();
+	GType color_flags = nm_test_general_color_flags_get_type();
+
+	test_nm_utils_enum_to_str_do (bool_enum, NM_TEST_GENERAL_BOOL_ENUM_YES, "yes");
+	test_nm_utils_enum_to_str_do (bool_enum, NM_TEST_GENERAL_BOOL_ENUM_UNKNOWN, "unknown");
+	test_nm_utils_enum_to_str_do (bool_enum, NM_TEST_GENERAL_BOOL_ENUM_INVALID, NULL);
+
+	test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_NONE, "");
+	test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_BAZ, "baz");
+	test_nm_utils_enum_to_str_do (meta_flags, NM_TEST_GENERAL_META_FLAGS_FOO |
+	                                          NM_TEST_GENERAL_META_FLAGS_BAR |
+	                                          NM_TEST_GENERAL_META_FLAGS_BAZ, "foo,bar,baz");
+
+	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_RED, "red");
+	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_WHITE, "");
+	test_nm_utils_enum_to_str_do (color_flags, NM_TEST_GENERAL_COLOR_FLAGS_RED |
+	                                           NM_TEST_GENERAL_COLOR_FLAGS_GREEN, "red,green");
+
+	test_nm_utils_enum_from_str_do (bool_enum, "", FALSE, 0, NULL);
+	test_nm_utils_enum_from_str_do (bool_enum, " ", FALSE, 0, NULL);
+	test_nm_utils_enum_from_str_do (bool_enum, "invalid", FALSE, 0, NULL);
+	test_nm_utils_enum_from_str_do (bool_enum, "yes", TRUE, NM_TEST_GENERAL_BOOL_ENUM_YES, NULL);
+	test_nm_utils_enum_from_str_do (bool_enum, "no", TRUE, NM_TEST_GENERAL_BOOL_ENUM_NO, NULL);
+	test_nm_utils_enum_from_str_do (bool_enum, "yes,no", FALSE, 0, NULL);
+
+	test_nm_utils_enum_from_str_do (meta_flags, "", TRUE, 0, NULL);
+	test_nm_utils_enum_from_str_do (meta_flags, " ", TRUE, 0, NULL);
+	test_nm_utils_enum_from_str_do (meta_flags, "foo", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO, NULL);
+	test_nm_utils_enum_from_str_do (meta_flags, "foo,baz", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO |
+	                                                             NM_TEST_GENERAL_META_FLAGS_BAZ, NULL);
+	test_nm_utils_enum_from_str_do (meta_flags, "foo,,bar", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO |
+	                                                              NM_TEST_GENERAL_META_FLAGS_BAR, NULL);
+	test_nm_utils_enum_from_str_do (meta_flags, "foo,baz,quux,bar", FALSE, 0, "quux");
+
+	test_nm_utils_enum_from_str_do (color_flags, "green", TRUE, NM_TEST_GENERAL_COLOR_FLAGS_GREEN, NULL);
+	test_nm_utils_enum_from_str_do (color_flags, "blue,red", TRUE, NM_TEST_GENERAL_COLOR_FLAGS_BLUE |
+	                                                               NM_TEST_GENERAL_COLOR_FLAGS_RED, NULL);
+	test_nm_utils_enum_from_str_do (color_flags, "blue,white", FALSE, 0, "white");
+}
+
+/******************************************************************************/
+
 NMTST_DEFINE ();
 
 int main (int argc, char **argv)
@@ -4455,6 +4620,7 @@ int main (int argc, char **argv)
 	nmtst_init (&argc, &argv, TRUE);
 
 	/* The tests */
+	g_test_add_func ("/core/general/test_nm_in_set", test_nm_in_set);
 	g_test_add_func ("/core/general/test_setting_vpn_items", test_setting_vpn_items);
 	g_test_add_func ("/core/general/test_setting_vpn_update_secrets", test_setting_vpn_update_secrets);
 	g_test_add_func ("/core/general/test_setting_vpn_modify_during_foreach", test_setting_vpn_modify_during_foreach);
@@ -4552,6 +4718,8 @@ int main (int argc, char **argv)
 	g_test_add_func ("/core/general/_glib_compat_g_ptr_array_insert", test_g_ptr_array_insert);
 	g_test_add_func ("/core/general/_nm_utils_ptrarray_find_binary_search", test_nm_utils_ptrarray_find_binary_search);
 
+	g_test_add_func ("/core/general/test_nm_utils_enum", test_nm_utils_enum);
+
 	return g_test_run ();
 }