Line data Source code
1 : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 : /* test-secret-search.c: Test secret search
3 :
4 : Copyright (C) 2013 Red Hat Inc
5 :
6 : The Gnome Keyring Library is free software; you can redistribute it and/or
7 : modify it under the terms of the GNU Library General Public License as
8 : published by the Free Software Foundation; either version 2 of the
9 : License, or (at your option) any later version.
10 :
11 : The Gnome Keyring Library is distributed in the hope that it will be useful,
12 : but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : Library General Public License for more details.
15 :
16 : You should have received a copy of the GNU Library General Public
17 : License along with the Gnome Library; see the file COPYING.LIB. If not,
18 : <http://www.gnu.org/licenses/>.
19 :
20 : Author: Stef Walter <stefw@gnome.org>
21 : */
22 :
23 : #include "config.h"
24 :
25 : #include "test-service.h"
26 :
27 : #include "gkd-secret-types.h"
28 :
29 : #include "egg/egg-testing.h"
30 :
31 : #include <glib.h>
32 : #include <glib/gstdio.h>
33 : #include <gio/gio.h>
34 :
35 : #include <fcntl.h>
36 :
37 : typedef struct {
38 : TestService service;
39 : } Test;
40 :
41 : static void
42 2 : setup (Test *test,
43 : gconstpointer unused)
44 : {
45 2 : test_service_setup (&test->service);
46 2 : }
47 :
48 : static void
49 2 : teardown (Test *test,
50 : gconstpointer unused)
51 : {
52 2 : test_service_teardown (&test->service);
53 2 : }
54 :
55 : static void
56 1 : test_service_search_items_unlocked_separate (Test *test,
57 : gconstpointer unused)
58 : {
59 : GVariantBuilder builder;
60 1 : GError *error = NULL;
61 : GVariant *retval;
62 : GVariant *attrs;
63 : GVariant *unlocked;
64 : GVariant *locked;
65 :
66 1 : g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
67 1 : attrs = g_variant_builder_end (&builder);
68 :
69 1 : retval = g_dbus_connection_call_sync (test->service.connection,
70 1 : test->service.bus_name,
71 : "/org/freedesktop/secrets",
72 : SECRET_SERVICE_INTERFACE,
73 : "SearchItems",
74 : g_variant_new ("(@a{ss})", attrs),
75 : G_VARIANT_TYPE ("(aoao)"),
76 : G_DBUS_CALL_FLAGS_NO_AUTO_START,
77 : -1, NULL, &error);
78 1 : g_assert_no_error (error);
79 :
80 1 : g_variant_get (retval, "(@ao@ao)", &unlocked, &locked);
81 1 : g_variant_unref (retval);
82 :
83 1 : g_assert_cmpuint (g_variant_n_children (unlocked), ==, 0);
84 1 : g_assert_cmpuint (g_variant_n_children (locked), ==, 1);
85 :
86 1 : g_variant_unref (unlocked);
87 1 : g_variant_unref (locked);
88 1 : }
89 :
90 : static void
91 1 : test_collection_search_items_combined (Test *test,
92 : gconstpointer unused)
93 : {
94 : GVariantBuilder builder;
95 1 : GError *error = NULL;
96 : GVariant *retval;
97 : GVariant *attrs;
98 : GVariant *items;
99 :
100 1 : g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
101 1 : attrs = g_variant_builder_end (&builder);
102 :
103 1 : retval = g_dbus_connection_call_sync (test->service.connection,
104 1 : test->service.bus_name,
105 : "/org/freedesktop/secrets/collection/test",
106 : SECRET_COLLECTION_INTERFACE,
107 : "SearchItems",
108 : g_variant_new ("(@a{ss})", attrs),
109 : G_VARIANT_TYPE ("(ao)"),
110 : G_DBUS_CALL_FLAGS_NO_AUTO_START,
111 : -1, NULL, &error);
112 1 : g_assert_no_error (error);
113 :
114 1 : g_variant_get (retval, "(@ao)", &items);
115 1 : g_variant_unref (retval);
116 :
117 1 : g_assert_cmpuint (g_variant_n_children (items), ==, 1);
118 1 : g_variant_unref (items);
119 1 : }
120 :
121 : int
122 1 : main (int argc, char **argv)
123 : {
124 : #if !GLIB_CHECK_VERSION(2,35,0)
125 : g_type_init ();
126 : #endif
127 1 : g_test_init (&argc, &argv, NULL);
128 :
129 1 : g_test_add ("/secret-search/service-search-items-unlocked-separate", Test, NULL,
130 : setup, test_service_search_items_unlocked_separate, teardown);
131 1 : g_test_add ("/secret-search/collection-search-items-combined", Test, NULL,
132 : setup, test_collection_search_items_combined, teardown);
133 :
134 1 : return egg_tests_run_with_loop ();
135 : }
|