1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of gsignond
6 * Copyright (C) 2012 Intel Corporation.
8 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
30 #include <glib-unix.h>
31 #include "gsignond/gsignond-session-data.h"
32 #include "gsignond/gsignond-error.h"
33 #include "gsignond/gsignond-log.h"
34 #include "common/gsignond-pipe-stream.h"
35 #include "common/gsignond-plugin-loader.h"
37 START_TEST (test_pipe_stream)
39 GSignondPipeStream *stream = NULL;
41 fail_unless (pipe (pipefd) == 0);
42 stream = gsignond_pipe_stream_new (pipefd[0], pipefd[1], TRUE);
43 fail_if (stream == NULL);
44 g_object_unref (stream);
48 START_TEST (test_session_data)
50 GSignondSessionData* data;
51 GSignondSessionData* data_from_variant;
52 GSignondSessionData* data_from_copy;
55 data = gsignond_dictionary_new();
56 fail_if(data == NULL);
58 fail_unless(gsignond_session_data_get_username(data) == NULL);
59 fail_unless(gsignond_session_data_get_secret(data) == NULL);
61 gsignond_session_data_set_username(data, "megauser");
62 gsignond_session_data_set_secret(data, "megapassword");
64 fail_unless(g_strcmp0(gsignond_session_data_get_username(data),
66 fail_unless(g_strcmp0(gsignond_session_data_get_secret(data),
67 "megapassword") == 0);
69 gsignond_session_data_set_username(data, "usermega");
70 fail_unless(g_strcmp0(gsignond_session_data_get_username(data),
73 data_from_copy = gsignond_dictionary_copy(data);
74 fail_if(data_from_copy == NULL);
76 fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_copy),
78 fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_copy),
79 "megapassword") == 0);
81 variant = gsignond_dictionary_to_variant(data);
82 fail_if(variant == NULL);
83 data_from_variant = gsignond_dictionary_new_from_variant(variant);
84 fail_if(data_from_variant == NULL);
86 fail_unless(g_strcmp0(gsignond_session_data_get_username(data_from_variant),
88 fail_unless(g_strcmp0(gsignond_session_data_get_secret(data_from_variant),
89 "megapassword") == 0);
91 g_variant_unref(variant);
92 gsignond_dictionary_unref(data_from_variant);
93 gsignond_dictionary_unref(data_from_copy);
94 gsignond_dictionary_unref(data);
98 static void check_plugin(GSignondPlugin* plugin)
103 fail_if(plugin == NULL);
105 g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
107 fail_unless(g_strcmp0(type, "password") == 0);
108 fail_unless(g_strcmp0(mechanisms[0], "password") == 0);
109 fail_unless(mechanisms[1] == NULL);
112 g_strfreev(mechanisms);
115 START_TEST (test_plugin_loader)
117 GSignondConfig* config = gsignond_config_new();
118 fail_if(config == NULL);
120 GSignondPlugin* absent_plugin = gsignond_load_plugin(config, "absentplugin");
121 fail_if(absent_plugin != NULL);
123 GSignondPlugin* plugin = gsignond_load_plugin(config, "password");
124 check_plugin(plugin);
126 g_object_unref(plugin);
127 g_object_unref(config);
131 Suite* common_suite (void)
133 Suite *s = suite_create ("Common library");
136 TCase *tc_core = tcase_create ("Tests");
137 tcase_add_test (tc_core, test_pipe_stream);
138 tcase_add_test (tc_core, test_session_data);
139 tcase_add_test (tc_core, test_plugin_loader);
140 suite_add_tcase (s, tc_core);
148 #if !GLIB_CHECK_VERSION (2, 36, 0)
152 Suite *s = common_suite();
153 SRunner *sr = srunner_create(s);
154 srunner_run_all(sr, CK_NORMAL);
155 number_failed = srunner_ntests_failed(sr);
157 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;