1
/* libsecret - GLib wrapper for Secret Service
3
* Copyright 2012 Red Hat Inc.
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU Lesser General Public License as published
7
* by the Free Software Foundation; either version 2 of the licence or (at
8
* your option) any later version.
10
* See the included COPYING file for more information.
12
* Author: Stef Walter <stefw@gnome.org>
18
#include "secret-attributes.h"
20
#include "egg/egg-testing.h"
27
static const SecretSchema MOCK_SCHEMA = {
31
{ "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
32
{ "string", SECRET_SCHEMA_ATTRIBUTE_STRING },
33
{ "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN },
41
GHashTable *attributes;
43
attributes = secret_attributes_build (&MOCK_SCHEMA,
49
g_assert_cmpstr (g_hash_table_lookup (attributes, "number"), ==, "4");
50
g_assert_cmpstr (g_hash_table_lookup (attributes, "string"), ==, "four");
51
g_assert_cmpstr (g_hash_table_lookup (attributes, "even"), ==, "true");
53
g_hash_table_unref (attributes);
57
test_build_unknown (void)
59
GHashTable *attributes;
61
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
62
attributes = secret_attributes_build (&MOCK_SCHEMA,
67
g_assert (attributes == NULL);
70
g_test_trap_assert_failed ();
71
g_test_trap_assert_stderr ("*was not found in*");
75
test_build_null_string (void)
77
GHashTable *attributes;
79
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
80
attributes = secret_attributes_build (&MOCK_SCHEMA,
85
g_assert (attributes == NULL);
88
g_test_trap_assert_failed ();
89
g_test_trap_assert_stderr ("*attribute*NULL*");
93
test_build_non_utf8_string (void)
95
GHashTable *attributes;
97
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
98
attributes = secret_attributes_build (&MOCK_SCHEMA,
100
"string", "\xfftest",
103
g_assert (attributes == NULL);
106
g_test_trap_assert_failed ();
107
g_test_trap_assert_stderr ("*attribute*UTF-8*");
111
test_build_bad_type (void)
113
GHashTable *attributes;
115
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
116
attributes = secret_attributes_build (&MOCK_SCHEMA,
119
g_assert (attributes == NULL);
122
g_test_trap_assert_failed ();
123
g_test_trap_assert_stderr ("*invalid type*");
127
main (int argc, char **argv)
129
g_test_init (&argc, &argv, NULL);
130
g_set_prgname ("test-attributes");
133
g_test_add_func ("/attributes/build", test_build);
134
g_test_add_func ("/attributes/build-unknown", test_build_unknown);
135
g_test_add_func ("/attributes/build-null-string", test_build_null_string);
136
g_test_add_func ("/attributes/build-non-utf8-string", test_build_non_utf8_string);
137
g_test_add_func ("/attributes/build-bad-type", test_build_bad_type);
139
return g_test_run ();