1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
/* unit-test-secret-compat.c: Test secret compat files
4
Copyright (C) 2008 Stefan Walter
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.
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.
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
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
21
Author: Stef Walter <stef@memberwebs.com>
26
#include "test-suite.h"
28
#include "gkm-secret-compat.h"
36
TESTING_TEST(access_free)
40
ac = g_new0 (GkmSecretAccess, 1);
41
ac->pathname = g_strdup ("/path");
42
ac->display_name = g_strdup ("Display");
43
ac->types_allowed = GKM_SECRET_ACCESS_READ;
45
gkm_secret_compat_access_free (ac);
48
TESTING_TEST(acl_free)
54
for (i = 0; i < 10; ++i) {
55
ac = g_new0 (GkmSecretAccess, 1);
56
ac->pathname = g_strdup ("/path");
57
ac->display_name = g_strdup ("Display");
58
ac->types_allowed = GKM_SECRET_ACCESS_READ;
59
acl = g_list_prepend (acl, ac);
62
gkm_secret_compat_acl_free (acl);
65
TESTING_TEST(parse_item_type)
69
type = gkm_secret_compat_parse_item_type ("org.freedesktop.Secret.Generic");
70
g_assert_cmpuint (type, ==, 0);
71
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.NetworkPassword");
72
g_assert_cmpuint (type, ==, 1);
73
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.Note");
74
g_assert_cmpuint (type, ==, 2);
75
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.ChainedKeyring");
76
g_assert_cmpuint (type, ==, 3);
77
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.EncryptionKey");
78
g_assert_cmpuint (type, ==, 4);
79
type = gkm_secret_compat_parse_item_type ("org.gnome.keyring.PkStorage");
80
g_assert_cmpuint (type, ==, 0x100);
82
/* Invalid returns generic secret */
83
type = gkm_secret_compat_parse_item_type ("invalid");
84
g_assert_cmpuint (type, ==, 0);
86
/* Null returns generic secret */
87
type = gkm_secret_compat_parse_item_type (NULL);
88
g_assert_cmpuint (type, ==, 0);
91
TESTING_TEST(format_item_type)
95
type = gkm_secret_compat_format_item_type (0);
96
g_assert_cmpstr (type, ==, "org.freedesktop.Secret.Generic");
97
type = gkm_secret_compat_format_item_type (1);
98
g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword");
99
type = gkm_secret_compat_format_item_type (2);
100
g_assert_cmpstr (type, ==, "org.gnome.keyring.Note");
101
type = gkm_secret_compat_format_item_type (3);
102
g_assert_cmpstr (type, ==, "org.gnome.keyring.ChainedKeyring");
103
type = gkm_secret_compat_format_item_type (4);
104
g_assert_cmpstr (type, ==, "org.gnome.keyring.EncryptionKey");
105
type = gkm_secret_compat_format_item_type (0x100);
106
g_assert_cmpstr (type, ==, "org.gnome.keyring.PkStorage");
108
/* Higher bits shouldn't make a difference */
109
type = gkm_secret_compat_format_item_type (0xF0000001);
110
g_assert_cmpstr (type, ==, "org.gnome.keyring.NetworkPassword");
112
/* Unrecognized should be null */
113
type = gkm_secret_compat_format_item_type (32);
114
g_assert (type == NULL);