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
setup(Test * test,gconstpointer unused)40 setup (Test *test, gconstpointer unused)
41 {
42 	test->module = mock_module_initialize_and_enter ();
43 	test->store = g_object_new (GKM_TYPE_STORE, NULL);
44 }
45 
46 static void
teardown(Test * test,gconstpointer unused)47 teardown (Test *test, gconstpointer unused)
48 {
49 	g_object_unref (test->store);
50 	mock_module_leave_and_finalize ();
51 }
52 
53 static void
test_schema(Test * test,gconstpointer unused)54 test_schema (Test *test, gconstpointer unused)
55 {
56 	CK_ATTRIBUTE attr;
57 
58 	attr.type = CKA_LABEL;
59 	attr.pValue = "Label";
60 	attr.ulValueLen = 5;
61 
62 	gkm_store_register_schema (test->store, &attr, NULL, 0);
63 	g_assert (gkm_store_lookup_schema (test->store, CKA_LABEL, NULL));
64 
65 	/* Not in the schema */
66 	g_assert (!gkm_store_lookup_schema (test->store, CKA_VALUE, NULL));
67 }
68 
69 static void
test_schema_flags(Test * test,gconstpointer unused)70 test_schema_flags (Test *test, gconstpointer unused)
71 {
72 	CK_ATTRIBUTE attr;
73 	guint flags;
74 
75 	attr.type = CKA_VALUE;
76 	attr.pValue = NULL;
77 	attr.ulValueLen = 0;
78 
79 	gkm_store_register_schema (test->store, &attr, NULL, GKM_STORE_IS_SENSITIVE);
80 	g_assert (gkm_store_lookup_schema (test->store, CKA_VALUE, &flags));
81 	g_assert (flags == GKM_STORE_IS_SENSITIVE);
82 }
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
main(int argc,char ** argv)92 main (int argc, char **argv)
93 {
94 #if !GLIB_CHECK_VERSION(2,35,0)
95 	g_type_init ();
96 #endif
97 	g_test_init (&argc, &argv, NULL);
98 
99 	g_test_add ("/gkm/store/schema", Test, NULL, setup, test_schema, teardown);
100 	g_test_add ("/gkm/store/schema_flags", Test, NULL, setup, test_schema_flags, teardown);
101 
102 	return g_test_run ();
103 }
104