Add tests for lib->get|set
[strongswan.git] / src / libstrongswan / tests / test_utils.c
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16
17 #include <check.h>
18
19 #include <library.h>
20
21 /*******************************************************************************
22 * object storage on lib
23 */
24
25 START_TEST(test_objects)
26 {
27 char *k1 = "key1", *k2 = "key2";
28 char *v1 = "val1", *val;
29
30 ck_assert(lib->get(lib, k1) == NULL);
31
32 ck_assert(lib->set(lib, k1, v1));
33 ck_assert(!lib->set(lib, k1, v1));
34
35 val = lib->get(lib, k1);
36 ck_assert(val != NULL);
37 ck_assert(streq(val, v1));
38
39 ck_assert(lib->set(lib, k1, NULL));
40 ck_assert(!lib->set(lib, k2, NULL));
41
42 ck_assert(lib->get(lib, k1) == NULL);
43 }
44 END_TEST
45
46 Suite *utils_suite_create()
47 {
48 Suite *s;
49 TCase *tc;
50
51 s = suite_create("utils");
52
53 tc = tcase_create("objects");
54 tcase_add_test(tc, test_objects);
55 suite_add_tcase(s, tc);
56
57 return s;
58 }