Debian Codegraph @

modules/lsp-runtime-lib/src/test/utest/resource/environment.cpp

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 26 окт. 2020 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/test-fw/utest.h>
23 #include <lsp-plug.in/resource/Environment.h>
24 #include <lsp-plug.in/stdlib/string.h>
25
26 using namespace lsp;
27
28 UTEST_BEGIN("runtime.resource", environment)
29
30 UTEST_MAIN
31 {
32 resource::Environment env, *copy;
33 const char *s;
34
35 // Add values
36 UTEST_ASSERT(env.set("k1", "value1") == STATUS_OK);
37 UTEST_ASSERT(env.set("k2", "value2") == STATUS_OK);
38 UTEST_ASSERT(env.set("k1", "value3") == STATUS_OK);
39
40 // Check presence
41 UTEST_ASSERT(env.contains("k1"));
42 UTEST_ASSERT(env.contains("k2"));
43 UTEST_ASSERT(!env.contains("k3"));
44 UTEST_ASSERT(!env.contains("k4"));
45
46 // Fetch values
47 UTEST_ASSERT((s = env.get_utf8("k1")) != NULL);
48 UTEST_ASSERT(strcmp(s, "value3") == 0);
49 UTEST_ASSERT((s = env.get_utf8("k2")) != NULL);
50 UTEST_ASSERT(strcmp(s, "value2") == 0);
51 UTEST_ASSERT((s = env.get_utf8("k3")) == NULL);
52 UTEST_ASSERT((s = env.get_utf8("k4", "dfl")) != NULL);
53 UTEST_ASSERT(strcmp(s, "dfl") == 0);
54
55 // Clone values
56 UTEST_ASSERT((copy = env.clone()) != NULL);
57
58 // Process original environment
59 // Remove values
60 UTEST_ASSERT(env.remove("k1") == STATUS_OK);
61 UTEST_ASSERT(env.remove("k2") == STATUS_OK);
62 UTEST_ASSERT(env.remove("k3") == STATUS_NOT_FOUND);
63 UTEST_ASSERT(env.remove("k4") == STATUS_NOT_FOUND);
64
65 // Fetch values again
66 UTEST_ASSERT((s = env.get_utf8("k1")) == NULL);
67 UTEST_ASSERT((s = env.get_utf8("k2")) == NULL);
68 UTEST_ASSERT((s = env.get_utf8("k3")) == NULL);
69 UTEST_ASSERT((s = env.get_utf8("k4", "dfl")) != NULL);
70 UTEST_ASSERT(strcmp(s, "dfl") == 0);
71
72 // Check presence again
73 UTEST_ASSERT(!env.contains("k1"));
74 UTEST_ASSERT(!env.contains("k2"));
75 UTEST_ASSERT(!env.contains("k3"));
76 UTEST_ASSERT(!env.contains("k4"));
77
78 // Process cloned environment
79 // Remove values
80 UTEST_ASSERT(copy->remove("k1") == STATUS_OK);
81 UTEST_ASSERT(copy->remove("k2") == STATUS_OK);
82 UTEST_ASSERT(copy->remove("k3") == STATUS_NOT_FOUND);
83 UTEST_ASSERT(copy->remove("k4") == STATUS_NOT_FOUND);
84
85 // Fetch values again
86 UTEST_ASSERT((s = copy->get_utf8("k1")) == NULL);
87 UTEST_ASSERT((s = copy->get_utf8("k2")) == NULL);
88 UTEST_ASSERT((s = copy->get_utf8("k3")) == NULL);
89 UTEST_ASSERT((s = copy->get_utf8("k4", "dfl")) != NULL);
90 UTEST_ASSERT(strcmp(s, "dfl") == 0);
91
92 // Check presence again
93 UTEST_ASSERT(!copy->contains("k1"));
94 UTEST_ASSERT(!copy->contains("k2"));
95 UTEST_ASSERT(!copy->contains("k3"));
96 UTEST_ASSERT(!copy->contains("k4"));
97
98 // Destroy environment
99 delete copy;
100 }
101
102 UTEST_END
103
104
105