2 Secret.Schema no_name_schema;
4 private void test_lookup_sync () {
6 string? password = Secret.password_lookup_sync (schema, null, "even", false, "string", "one", "number", 1);
7 GLib.assert (password == "111");
8 } catch ( GLib.Error e ) {
9 GLib.error (e.message);
13 public async void test_lookup_async_ex () {
15 string? password = yield Secret.password_lookup (schema, null, "even", false, "string", "one", "number", 1);
16 GLib.assert (password == "111");
17 } catch ( GLib.Error e ) {
18 GLib.error (e.message);
22 private void test_lookup_async () {
23 var loop = new GLib.MainLoop ();
24 test_lookup_async_ex.begin ((obj, async_res) => {
30 private void test_lookup_no_name () {
32 string? password = Secret.password_lookup_sync (schema, null, "number", 5);
33 GLib.assert (password == null);
35 password = Secret.password_lookup_sync (no_name_schema, null, "number", 5);
36 GLib.assert (password == "555");
37 } catch ( GLib.Error e ) {
38 GLib.error (e.message);
42 private void test_store_sync () {
44 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
45 attributes["even"] = "false";
46 attributes["string"] = "nine";
47 attributes["number"] = "9";
49 string? password = Secret.password_lookupv_sync (schema, attributes);
50 GLib.assert (password == null);
52 bool stored = Secret.password_storev_sync (schema, attributes, Secret.COLLECTION_DEFAULT, "The number ", "999");
55 password = Secret.password_lookupv_sync (schema, attributes);
56 GLib.assert (password == "999");
57 } catch ( GLib.Error e ) {
58 GLib.error (e.message);
62 private async void test_store_async_ex () {
63 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
64 attributes["even"] = "true";
65 attributes["string"] = "eight";
66 attributes["number"] = "8";
69 string? password = yield Secret.password_lookupv (schema, attributes, null);
70 GLib.assert (password == null);
72 bool stored = yield Secret.password_storev (schema, attributes, Secret.COLLECTION_DEFAULT, "The number nine", "999", null);
75 password = yield Secret.password_lookupv (schema, attributes, null);
76 GLib.assert (password == "999");
77 } catch ( GLib.Error e ) {
78 GLib.error (e.message);
82 private void test_store_async () {
83 var loop = new GLib.MainLoop ();
84 test_store_async_ex.begin ((obj, async_res) => {
90 private void test_remove_sync () {
92 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
93 attributes["even"] = "false";
94 attributes["string"] = "nine";
95 attributes["number"] = "9";
97 string? password = Secret.password_lookupv_sync (schema, attributes);
98 GLib.assert (password == "999");
100 bool removed = Secret.password_removev_sync (schema, attributes, null);
101 GLib.assert (removed);
103 password = Secret.password_lookupv_sync (schema, attributes);
104 GLib.assert (password == null);
105 } catch ( GLib.Error e ) {
106 GLib.error (e.message);
110 private async void test_remove_async_ex () {
111 var attributes = new GLib.HashTable<string,string> (GLib.str_hash, GLib.str_equal);
112 attributes["even"] = "true";
113 attributes["string"] = "eight";
114 attributes["number"] = "8";
117 string? password = yield Secret.password_lookupv (schema, attributes, null);
118 GLib.assert (password == "999");
120 bool removed = yield Secret.password_removev (schema, attributes, null);
121 GLib.assert (removed);
123 password = yield Secret.password_lookupv (schema, attributes, null);
124 GLib.assert (password == null);
125 } catch ( GLib.Error e ) {
126 GLib.error (e.message);
130 private void test_remove_async () {
131 var loop = new GLib.MainLoop ();
132 test_remove_async_ex.begin ((obj, async_res) => {
138 private static int main (string[] args) {
139 GLib.Test.init (ref args);
142 MockService.start ("mock-service-normal.py");
143 } catch ( GLib.Error e ) {
144 GLib.error ("Unable to start mock service: %s", e.message);
148 schema = new Secret.Schema ("org.mock.Schema", Secret.SchemaFlags.NONE,
149 "number", Secret.SchemaAttributeType.INTEGER,
150 "string", Secret.SchemaAttributeType.STRING,
151 "even", Secret.SchemaAttributeType.BOOLEAN);
153 no_name_schema = new Secret.Schema ("unused.Schema.Name", Secret.SchemaFlags.DONT_MATCH_NAME,
154 "number", Secret.SchemaAttributeType.INTEGER,
155 "string", Secret.SchemaAttributeType.STRING);
158 GLib.Test.add_data_func ("/vala/lookup/sync", test_lookup_sync);
159 GLib.Test.add_data_func ("/vala/lookup/async", test_lookup_async);
160 GLib.Test.add_data_func ("/vala/lookup/no-name", test_lookup_no_name);
161 GLib.Test.add_data_func ("/vala/store/sync", test_store_sync);
162 GLib.Test.add_data_func ("/vala/store/async", test_store_async);
163 GLib.Test.add_data_func ("/vala/remove/sync", test_remove_sync);
164 GLib.Test.add_data_func ("/vala/remove/async", test_remove_async);
166 var res = GLib.Test.run ();