[network-manager-applet/aleksander/mobile-providers: 19/19] libnm-gtk: added unit tests for the mobile provider database



commit 3bd76beb1de4cfca483f2a13941190c8d91929c1
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Nov 27 20:39:17 2012 +0100

    libnm-gtk: added unit tests for the mobile provider database

 .gitignore                                  |    2 +-
 configure.ac                                |    1 +
 src/libnm-gtk/Makefile.am                   |    2 +
 src/libnm-gtk/tests/Makefile.am             |   21 +++++++
 src/libnm-gtk/tests/test-mobile-providers.c |   82 +++++++++++++++++++++++++++
 5 files changed, 107 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ef5d40c..9b1d8b6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,10 +41,10 @@ src/connection-editor/nm-connection-editor-service-glue.h
 src/libnm-gtk/libnm-gtk.pc
 src/libnm-gtk/NMGtk-1.0.gir
 src/libnm-gtk/NMGtk-1.0.typelib
+src/libnm-gtk/tests/test-mobile-providers
 src/marshallers/nma-marshal.*
 src/nm-applet
 src/nm-applet-migration-tool
 src/applet-dbus-bindings.h
 
 src/gconf-helpers/tests/test-upgrade
-
diff --git a/configure.ac b/configure.ac
index b41f015..c202fe6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -250,6 +250,7 @@ AC_CONFIG_FILES([
 Makefile
 src/Makefile
 src/libnm-gtk/Makefile
+src/libnm-gtk/tests/Makefile
 src/libnm-gtk/libnm-gtk.pc
 src/marshallers/Makefile
 src/utils/Makefile
diff --git a/src/libnm-gtk/Makefile.am b/src/libnm-gtk/Makefile.am
index 5a9266e..70039af 100644
--- a/src/libnm-gtk/Makefile.am
+++ b/src/libnm-gtk/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = . tests
+
 uidir = $(datadir)/libnm-gtk
 ui_DATA = wifi.ui
 
diff --git a/src/libnm-gtk/tests/Makefile.am b/src/libnm-gtk/tests/Makefile.am
new file mode 100644
index 0000000..4b61275
--- /dev/null
+++ b/src/libnm-gtk/tests/Makefile.am
@@ -0,0 +1,21 @@
+
+noinst_PROGRAMS = \
+	test-mobile-providers
+
+test_mobile_providers_SOURCES = \
+	test-mobile-providers.c
+
+test_mobile_providers_CPPFLAGS = \
+	$(NMA_CFLAGS) \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/src/libnm-gtk
+
+test_mobile_providers_LDADD = \
+	$(top_builddir)/src/libnm-gtk/libnm-gtk.la \
+	$(NMA_LIBS)
+
+check-local: test-mobile-providers
+	$(abs_builddir)/test-mobile-providers
+
+
+EXTRA_DIST =
diff --git a/src/libnm-gtk/tests/test-mobile-providers.c b/src/libnm-gtk/tests/test-mobile-providers.c
new file mode 100644
index 0000000..ec24af8
--- /dev/null
+++ b/src/libnm-gtk/tests/test-mobile-providers.c
@@ -0,0 +1,82 @@
+/* -*- 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 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:
+ *
+ * Copyright (C) 2012 Aleksander Morgado <aleksander gnu org>
+ */
+
+#include <locale.h>
+#include "nm-mobile-providers.h"
+
+static void
+mobile_providers_database_new_sync (void)
+{
+	NMAMobileProvidersDatabase *mpd;
+	GError *error = NULL;
+
+	mpd = nma_mobile_providers_database_new_sync (NULL,
+	                                              NULL,
+	                                              NULL, /* cancellable */
+	                                              &error);
+	g_assert_no_error (error);
+	g_assert (NMA_IS_MOBILE_PROVIDERS_DATABASE (mpd));
+
+	g_object_unref (mpd);
+}
+
+static void
+new_ready (GObject *source,
+           GAsyncResult *res,
+           GMainLoop *loop)
+{
+	NMAMobileProvidersDatabase *mpd;
+	GError *error = NULL;
+
+	mpd = nma_mobile_providers_database_new_finish (res, &error);
+
+	g_assert_no_error (error);
+	g_assert (NMA_IS_MOBILE_PROVIDERS_DATABASE (mpd));
+
+	nma_mobile_providers_database_dump (mpd);
+	g_object_unref (mpd);
+
+	g_main_loop_quit (loop);
+}
+
+static void
+mobile_providers_database_new_async (void)
+{
+	GMainLoop *loop;
+
+	loop = g_main_loop_new (NULL, FALSE);
+
+	nma_mobile_providers_database_new (NULL,
+	                                   NULL,
+	                                   NULL, /* cancellable */
+	                                   (GAsyncReadyCallback)new_ready,
+	                                   loop);
+
+	g_main_loop_run (loop);
+	g_main_loop_unref (loop);
+}
+
+int main (int argc, char **argv)
+{
+    setlocale (LC_ALL, "");
+
+    g_type_init ();
+    g_test_init (&argc, &argv, NULL);
+
+    g_test_add_func ("/NMA/MobileProvidersDatabase/new-sync",  mobile_providers_database_new_sync);
+    g_test_add_func ("/NMA/MobileProvidersDatabase/new-async", mobile_providers_database_new_async);
+
+    return g_test_run ();
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]