Line data Source code
1 : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 : /* test-store.c: Test general store functionality
3 :
4 : Copyright (C) 2008 Stefan Walter
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 <stef@memberwebs.com>
21 : */
22 :
23 : #include "config.h"
24 :
25 : #include <stdlib.h>
26 : #include <stdio.h>
27 : #include <string.h>
28 : #include <unistd.h>
29 :
30 : #include "mock-module.h"
31 :
32 : #include "gkm/gkm-store.h"
33 :
34 : typedef struct {
35 : GkmModule *module;
36 : GkmStore *store;
37 : } Test;
38 :
39 : static void
40 2 : setup (Test *test, gconstpointer unused)
41 : {
42 2 : test->module = mock_module_initialize_and_enter ();
43 2 : test->store = g_object_new (GKM_TYPE_STORE, NULL);
44 2 : }
45 :
46 : static void
47 2 : teardown (Test *test, gconstpointer unused)
48 : {
49 2 : g_object_unref (test->store);
50 2 : mock_module_leave_and_finalize ();
51 2 : }
52 :
53 : static void
54 1 : test_schema (Test *test, gconstpointer unused)
55 : {
56 : CK_ATTRIBUTE attr;
57 :
58 1 : attr.type = CKA_LABEL;
59 1 : attr.pValue = "Label";
60 1 : attr.ulValueLen = 5;
61 :
62 1 : gkm_store_register_schema (test->store, &attr, NULL, 0);
63 1 : g_assert (gkm_store_lookup_schema (test->store, CKA_LABEL, NULL));
64 :
65 : /* Not in the schema */
66 1 : g_assert (!gkm_store_lookup_schema (test->store, CKA_VALUE, NULL));
67 1 : }
68 :
69 : static void
70 1 : test_schema_flags (Test *test, gconstpointer unused)
71 : {
72 : CK_ATTRIBUTE attr;
73 : guint flags;
74 :
75 1 : attr.type = CKA_VALUE;
76 1 : attr.pValue = NULL;
77 1 : attr.ulValueLen = 0;
78 :
79 1 : gkm_store_register_schema (test->store, &attr, NULL, GKM_STORE_IS_SENSITIVE);
80 1 : g_assert (gkm_store_lookup_schema (test->store, CKA_VALUE, &flags));
81 1 : g_assert (flags == GKM_STORE_IS_SENSITIVE);
82 1 : }
83 :
84 : /*
85 : * That's all we can test in the base class of GkmStore without a proper
86 : * derived class. For more tests see unit-test-memory-store.c and
87 : * unit-test-file-store.c
88 : */
89 :
90 :
91 : int
92 1 : main (int argc, char **argv)
93 : {
94 : #if !GLIB_CHECK_VERSION(2,35,0)
95 : g_type_init ();
96 : #endif
97 1 : g_test_init (&argc, &argv, NULL);
98 :
99 1 : g_test_add ("/gkm/store/schema", Test, NULL, setup, test_schema, teardown);
100 1 : g_test_add ("/gkm/store/schema_flags", Test, NULL, setup, test_schema_flags, teardown);
101 :
102 1 : return g_test_run ();
103 : }
|