2 * Copyright 2012 Red Hat Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the licence or (at
7 * your option) any later version.
9 * See the included COPYING file for more information.
13 Secret.Schema no_name_schema;
15 private void test_lookup_sync () {
17 string? password = Secret.password_lookup_sync (schema, null, "even", false, "string", "one", "number", 1);
18 GLib.assert (password == "111");
19 } catch ( GLib.Error e ) {
20 GLib.error (e.message);
24 public async void test_lookup_async_ex () {
26 string? password = yield Secret.password_lookup (schema, null, "even", false, "string", "one", "number", 1);
27 GLib.assert (password == "111");
28 } catch ( GLib.Error e ) {
29 GLib.error (e.message);
33 private void test_lookup_async () {
34 var loop = new GLib.MainLoop ();
35 test_lookup_async_ex.begin ((obj, async_res) => {
41 private void test_lookup_no_name () {
43 string? password = Secret.password_lookup_sync (schema, null, "number", 5);
44 GLib.assert (password == null);
46 password = Secret.password_lookup_sync (no_name_schema, null, "number", 5);
47 GLib.assert (password == "555");
48 } catch ( GLib.Error e ) {
49 GLib.error (e.message);
53 private void test_store_sync () {
55 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
56 attributes["even"] = "false";
57 attributes["string"] = "nine";
58 attributes["number"] = "9";
60 string? password = Secret.password_lookupv_sync (schema, attributes);
61 GLib.assert (password == null);
63 bool stored = Secret.password_storev_sync (schema, attributes, Secret.COLLECTION_DEFAULT, "The number ", "999");
66 password = Secret.password_lookupv_sync (schema, attributes);
67 GLib.assert (password == "999");
68 } catch ( GLib.Error e ) {
69 GLib.error (e.message);
73 private async void test_store_async_ex () {
74 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
75 attributes["even"] = "true";
76 attributes["string"] = "eight";
77 attributes["number"] = "8";
80 string? password = yield Secret.password_lookupv (schema, attributes, null);
81 GLib.assert (password == null);
83 bool stored = yield Secret.password_storev (schema, attributes, Secret.COLLECTION_DEFAULT, "The number nine", "999", null);
86 password = yield Secret.password_lookupv (schema, attributes, null);
87 GLib.assert (password == "999");
88 } catch ( GLib.Error e ) {
89 GLib.error (e.message);
93 private void test_store_async () {
94 var loop = new GLib.MainLoop ();
95 test_store_async_ex.begin ((obj, async_res) => {
101 private void test_clear_sync () {
103 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
104 attributes["even"] = "false";
105 attributes["string"] = "nine";
106 attributes["number"] = "9";
108 string? password = Secret.password_lookupv_sync (schema, attributes);
109 GLib.assert (password == "999");
111 bool removed = Secret.password_clearv_sync (schema, attributes, null);
112 GLib.assert (removed);
114 password = Secret.password_lookupv_sync (schema, attributes);
115 GLib.assert (password == null);
116 } catch ( GLib.Error e ) {
117 GLib.error (e.message);
121 private async void test_clear_async_ex () {
122 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
123 attributes["even"] = "true";
124 attributes["string"] = "eight";
125 attributes["number"] = "8";
128 string? password = yield Secret.password_lookupv (schema, attributes, null);
129 GLib.assert (password == "999");
131 bool removed = yield Secret.password_clearv (schema, attributes, null);
132 GLib.assert (removed);
134 password = yield Secret.password_lookupv (schema, attributes, null);
135 GLib.assert (password == null);
136 } catch ( GLib.Error e ) {
137 GLib.error (e.message);
141 private void test_clear_async () {
142 var loop = new GLib.MainLoop ();
143 test_clear_async_ex.begin ((obj, async_res) => {
149 private static int main (string[] args) {
150 GLib.Test.init (ref args);
153 MockService.start ("mock-service-normal.py");
154 } catch ( GLib.Error e ) {
155 GLib.error ("Unable to start mock service: %s", e.message);
159 schema = new Secret.Schema ("org.mock.Schema", Secret.SchemaFlags.NONE,
160 "number", Secret.SchemaAttributeType.INTEGER,
161 "string", Secret.SchemaAttributeType.STRING,
162 "even", Secret.SchemaAttributeType.BOOLEAN);
164 no_name_schema = new Secret.Schema ("unused.Schema.Name", Secret.SchemaFlags.DONT_MATCH_NAME,
165 "number", Secret.SchemaAttributeType.INTEGER,
166 "string", Secret.SchemaAttributeType.STRING);
169 GLib.Test.add_data_func ("/vala/lookup/sync", test_lookup_sync);
170 GLib.Test.add_data_func ("/vala/lookup/async", test_lookup_async);
171 GLib.Test.add_data_func ("/vala/lookup/no-name", test_lookup_no_name);
172 GLib.Test.add_data_func ("/vala/store/sync", test_store_sync);
173 GLib.Test.add_data_func ("/vala/store/async", test_store_async);
174 GLib.Test.add_data_func ("/vala/clear/sync", test_clear_sync);
175 GLib.Test.add_data_func ("/vala/clear/async", test_clear_async);
177 var res = GLib.Test.run ();
179 Secret.Service.disconnect ();