Fix memleak when setting proxy property
[profile/ivi/gsignond-plugin-oauth.git] / test / oauthplugintest.c
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4  * This file is part of gsignond
5  *
6  * Copyright (C) 2012 Intel Corporation.
7  *
8  * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
9  *
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.
14  *
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.
19  *
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
23  * 02110-1301 USA
24  */
25
26 #include <check.h>
27 #include <stdlib.h>
28 #include "gsignond-oauth-plugin.h"
29 #include <gsignond/gsignond-session-data.h>
30 #include <gsignond/gsignond-plugin-interface.h>
31 #include <gsignond/gsignond-error.h>
32 #include <gsignond/gsignond-config.h>
33 #include <libsoup/soup.h>
34
35 void add_oauth1_tcase(Suite *s);
36 void add_oauth2_tcase(Suite *s);
37
38 static void check_plugin(GSignondPlugin* plugin)
39 {
40     gchar* type;
41     gchar** mechanisms;
42
43     fail_if(plugin == NULL);
44     
45     g_object_get(plugin, "type", &type, "mechanisms", &mechanisms, NULL);
46     
47     fail_unless(g_strcmp0(type, "oauth") == 0);
48     fail_unless(g_strcmp0(mechanisms[0], "oauth1") == 0);
49     fail_unless(g_strcmp0(mechanisms[1], "oauth2") == 0);
50     fail_unless(mechanisms[2] == NULL);
51     
52     g_free(type);
53     g_strfreev(mechanisms);
54 }
55
56 START_TEST (test_oauthplugin_create)
57 {
58     gpointer plugin;
59     
60     plugin = g_object_new(GSIGNOND_TYPE_OAUTH_PLUGIN, NULL);
61     check_plugin(plugin);
62     g_object_unref(plugin);
63 }
64 END_TEST
65
66     
67 Suite* oauthplugin_suite (void)
68 {
69     Suite *s = suite_create ("OAUTH plugin");
70     
71     TCase *tc_oauth_plugin = tcase_create ("OAuth plugin tests");
72     tcase_add_test (tc_oauth_plugin, test_oauthplugin_create);
73     suite_add_tcase (s, tc_oauth_plugin);
74     
75     add_oauth1_tcase(s);
76     add_oauth2_tcase(s);
77     
78     return s;
79 }
80
81 int main (void)
82 {
83     int number_failed;
84
85 #if !GLIB_CHECK_VERSION (2, 36, 0)
86     g_type_init ();
87 #endif
88     
89     Suite *s = oauthplugin_suite();
90     SRunner *sr = srunner_create(s);
91     srunner_run_all(sr, CK_NORMAL);
92     number_failed = srunner_ntests_failed(sr);
93     srunner_free(sr);
94     return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
95 }
96