tests: split tests for common library into their own testsuite
authorAlexander Kanavin <alexander.kanavin@intel.com>
Wed, 27 Mar 2013 14:01:09 +0000 (16:01 +0200)
committerAlexander Kanavin <alexander.kanavin@intel.com>
Wed, 27 Mar 2013 14:01:09 +0000 (16:01 +0200)
.gitignore
configure.ac
test/Makefile.am
test/common/Makefile.am [new file with mode: 0644]
test/common/commontest.c [new file with mode: 0644]
test/plugins/passwordplugintest.c
test/plugins/pluginproxytest.c

index 99e75d5..4cae300 100644 (file)
@@ -25,6 +25,7 @@ m4/lt*.m4
 build-aux
 *dbus*gen*
 src/daemon/gsignond
+test/common/commontest
 test/db/dbtest
 test/plugins/passwordplugintest
 test/plugins/pluginproxytest
index 611fb20..4fbf744 100644 (file)
@@ -77,6 +77,7 @@ src/plugins/Makefile
 src/plugins/password/Makefile
 src/plugins/ssotest/Makefile
 test/Makefile
+test/common/Makefile
 test/db/Makefile
 test/daemon/Makefile
 test/daemon/services/com.google.code.AccountsSSO.gSingleSignOn.service
index 6a5232c..0a3b1af 100644 (file)
@@ -1 +1 @@
-SUBDIRS = db plugins daemon
+SUBDIRS = common db plugins daemon
diff --git a/test/common/Makefile.am b/test/common/Makefile.am
new file mode 100644 (file)
index 0000000..2030a50
--- /dev/null
@@ -0,0 +1,14 @@
+TESTS = commontest
+TESTS_ENVIRONMENT= SSO_PLUGINS_DIR=$(top_builddir)/src/plugins/password/.libs
+
+check_PROGRAMS = commontest
+commontest_SOURCES = commontest.c
+commontest_CFLAGS = \
+    $(GSIGNOND_CFLAGS) \
+    $(CHECK_CFLAGS) \
+    -I$(top_srcdir)/include/ 
+
+commontest_LDADD = \
+    $(top_builddir)/src/common/libgsignond-common.la \
+    $(GSIGNOND_LIBS) \
+    $(CHECK_LIBS)
\ No newline at end of file
diff --git a/test/common/commontest.c b/test/common/commontest.c
new file mode 100644 (file)
index 0000000..0207848
--- /dev/null
@@ -0,0 +1,143 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of gsignond
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
+ *
+ * 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.1 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 St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include <gsignond/gsignond-session-data.h>
+#include <gsignond/gsignond-plugin-loader.h>
+#include <gsignond/gsignond-error.h>
+#include <gsignond/gsignond-log.h>
+
+
+START_TEST (test_session_data)
+{
+    GSignondSessionData* data;
+    GSignondSessionData* data_from_variant;
+    GSignondSessionData* data_from_copy;
+    GVariant* variant;
+    
+    data = gsignond_dictionary_new();
+    fail_if(data == NULL);
+    
+    fail_unless(gsignond_session_data_get_username(data) == NULL);
+    fail_unless(gsignond_session_data_get_secret(data) == NULL);
+
+    gsignond_session_data_set_username(data, "megauser");
+    gsignond_session_data_set_secret(data, "megapassword");
+    
+    fail_unless(g_strcmp0(gsignond_session_data_get_username(data), 
+                          "megauser") == 0);
+    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data), 
+                          "megapassword") == 0);
+
+    gsignond_session_data_set_username(data, "usermega");
+    fail_unless(g_strcmp0(gsignond_session_data_get_username(data), 
+                          "usermega") == 0);
+    
+    data_from_copy = gsignond_dictionary_copy(data);
+    fail_if(data_from_copy == NULL);
+
+    fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_copy), 
+                          "usermega") == 0);
+    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_copy), 
+                          "megapassword") == 0);
+
+    variant = gsignond_dictionary_to_variant(data);
+    fail_if(variant == NULL);
+    data_from_variant = gsignond_dictionary_new_from_variant(variant);
+    fail_if(data_from_variant == NULL);
+
+    fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_variant), 
+                          "usermega") == 0);
+    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_variant), 
+                          "megapassword") == 0);
+    
+    g_variant_unref(variant);
+    gsignond_dictionary_unref(data_from_variant);
+    gsignond_dictionary_unref(data_from_copy);
+    gsignond_dictionary_unref(data);
+}
+END_TEST
+
+static void check_plugin(GSignondPlugin* plugin)
+{
+    gchar* type;
+    gchar** mechanisms;
+
+    fail_if(plugin == NULL);
+    
+    g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
+    
+    fail_unless(g_strcmp0(type, "password") == 0);
+    fail_unless(g_strcmp0(mechanisms[0], "password") == 0);
+    fail_unless(mechanisms[1] == NULL);
+    
+    g_free(type);
+    g_strfreev(mechanisms);
+}
+
+START_TEST (test_plugin_loader)
+{
+    GSignondConfig* config = gsignond_config_new();
+    fail_if(config == NULL);
+
+    GSignondPlugin* absent_plugin = gsignond_load_plugin(config, "absentplugin");
+    fail_if(absent_plugin != NULL);
+    
+    GSignondPlugin* plugin = gsignond_load_plugin(config, "password");
+    check_plugin(plugin);    
+    
+    g_object_unref(plugin);
+    g_object_unref(config);
+}
+END_TEST
+
+
+Suite* common_suite (void)
+{
+    Suite *s = suite_create ("Common library");
+    
+    /* Core test case */
+    TCase *tc_core = tcase_create ("Tests");
+    tcase_add_test (tc_core, test_session_data);
+    tcase_add_test (tc_core, test_plugin_loader);
+    suite_add_tcase (s, tc_core);
+    return s;
+}
+
+int main (void)
+{
+    int number_failed;
+    
+    g_type_init();
+    
+    Suite *s = common_suite();
+    SRunner *sr = srunner_create(s);
+    srunner_run_all(sr, CK_NORMAL);
+    number_failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+  
index d986394..ebb6377 100644 (file)
 #include <gsignond/gsignond-plugin-loader.h>
 #include <gsignond/gsignond-config.h>
 
-START_TEST (test_session_data)
-{
-    GSignondSessionData* data;
-    GSignondSessionData* data_from_variant;
-    GSignondSessionData* data_from_copy;
-    GVariant* variant;
-    
-    data = gsignond_dictionary_new();
-    fail_if(data == NULL);
-    
-    fail_unless(gsignond_session_data_get_username(data) == NULL);
-    fail_unless(gsignond_session_data_get_secret(data) == NULL);
-
-    gsignond_session_data_set_username(data, "megauser");
-    gsignond_session_data_set_secret(data, "megapassword");
-    
-    fail_unless(g_strcmp0(gsignond_session_data_get_username(data), 
-                          "megauser") == 0);
-    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data), 
-                          "megapassword") == 0);
-
-    gsignond_session_data_set_username(data, "usermega");
-    fail_unless(g_strcmp0(gsignond_session_data_get_username(data), 
-                          "usermega") == 0);
-    
-    data_from_copy = gsignond_dictionary_copy(data);
-    fail_if(data_from_copy == NULL);
-
-    fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_copy), 
-                          "usermega") == 0);
-    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_copy), 
-                          "megapassword") == 0);
-
-    variant = gsignond_dictionary_to_variant(data);
-    fail_if(variant == NULL);
-    data_from_variant = gsignond_dictionary_new_from_variant(variant);
-    fail_if(data_from_variant == NULL);
-
-    fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_variant), 
-                          "usermega") == 0);
-    fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_variant), 
-                          "megapassword") == 0);
-    
-    g_variant_unref(variant);
-    gsignond_dictionary_unref(data_from_variant);
-    gsignond_dictionary_unref(data_from_copy);
-    gsignond_dictionary_unref(data);
-}
-END_TEST
 
 static void check_plugin(GSignondPlugin* plugin)
 {
@@ -310,7 +261,6 @@ Suite* passwordplugin_suite (void)
     
     /* Core test case */
     TCase *tc_core = tcase_create ("Tests");
-    tcase_add_test (tc_core, test_session_data);
     tcase_add_test (tc_core, test_passwordplugin_create);
     tcase_add_test (tc_core, test_passwordplugin_request);
     tcase_add_test (tc_core, test_passwordplugin_user_action_finished);
index 3b5f368..7cf4f1d 100644 (file)
@@ -68,41 +68,6 @@ gsignond_test_auth_session_class_init (GSignondTestAuthSessionClass *klass)
  
 }
 
-static void check_plugin(GSignondPlugin* plugin)
-{
-    gchar* type;
-    gchar** mechanisms;
-
-    fail_if(plugin == NULL);
-    
-    g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
-    
-    fail_unless(g_strcmp0(type, "password") == 0);
-    fail_unless(g_strcmp0(mechanisms[0], "password") == 0);
-    fail_unless(mechanisms[1] == NULL);
-    
-    g_free(type);
-    g_strfreev(mechanisms);
-}
-
-
-
-START_TEST (test_plugin_loader)
-{
-    GSignondConfig* config = gsignond_config_new();
-    fail_if(config == NULL);
-
-    GSignondPlugin* absent_plugin = gsignond_load_plugin(config, "absentplugin");
-    fail_if(absent_plugin != NULL);
-    
-    GSignondPlugin* plugin = gsignond_load_plugin(config, "password");
-    check_plugin(plugin);    
-    
-    g_object_unref(plugin);
-    g_object_unref(config);
-}
-END_TEST
-
 static void check_plugin_proxy(GSignondPluginProxy* proxy)
 {
     gchar* type;
@@ -484,7 +449,6 @@ Suite* pluginproxy_suite (void)
     
     /* Core test case */
     TCase *tc_core = tcase_create ("Tests");
-    tcase_add_test (tc_core, test_plugin_loader);
     tcase_add_test (tc_core, test_pluginproxy_create);
     tcase_add_test (tc_core, test_pluginproxy_process);
     tcase_add_test (tc_core, test_pluginproxy_process_cancel);