1 | /*
|
---|
2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <errno.h>
|
---|
30 | #include <pcut/pcut.h>
|
---|
31 | #include <tbarcfg/tbarcfg.h>
|
---|
32 | #include <stdio.h>
|
---|
33 |
|
---|
34 | PCUT_INIT;
|
---|
35 |
|
---|
36 | PCUT_TEST_SUITE(tbarcfg);
|
---|
37 |
|
---|
38 | /** Creating, opening and closing taskbar configuration */
|
---|
39 | PCUT_TEST(create_open_close)
|
---|
40 | {
|
---|
41 | errno_t rc;
|
---|
42 | tbarcfg_t *tbcfg;
|
---|
43 | char fname[L_tmpnam], *p;
|
---|
44 |
|
---|
45 | p = tmpnam(fname);
|
---|
46 | PCUT_ASSERT_NOT_NULL(p);
|
---|
47 |
|
---|
48 | /* Create new repository */
|
---|
49 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
50 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
51 |
|
---|
52 | tbarcfg_close(tbcfg);
|
---|
53 |
|
---|
54 | /* Re-open the repository */
|
---|
55 |
|
---|
56 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
57 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
58 |
|
---|
59 | tbarcfg_close(tbcfg);
|
---|
60 | remove(fname);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /** Iterating over start menu entries */
|
---|
64 | PCUT_TEST(first_next)
|
---|
65 | {
|
---|
66 | errno_t rc;
|
---|
67 | tbarcfg_t *tbcfg;
|
---|
68 | char fname[L_tmpnam], *p;
|
---|
69 | smenu_entry_t *e1 = NULL, *e2 = NULL;
|
---|
70 | smenu_entry_t *e;
|
---|
71 |
|
---|
72 | p = tmpnam(fname);
|
---|
73 | PCUT_ASSERT_NOT_NULL(p);
|
---|
74 |
|
---|
75 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
76 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
77 |
|
---|
78 | rc = smenu_entry_create(tbcfg, "A", "a", &e1);
|
---|
79 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
80 | PCUT_ASSERT_NOT_NULL(e1);
|
---|
81 |
|
---|
82 | rc = smenu_entry_create(tbcfg, "B", "b", &e2);
|
---|
83 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
84 | PCUT_ASSERT_NOT_NULL(e2);
|
---|
85 |
|
---|
86 | /* Create entry without getting a pointer to it */
|
---|
87 | rc = smenu_entry_create(tbcfg, "C", "c", NULL);
|
---|
88 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
89 |
|
---|
90 | e = tbarcfg_smenu_first(tbcfg);
|
---|
91 | PCUT_ASSERT_EQUALS(e1, e);
|
---|
92 | e = tbarcfg_smenu_next(e);
|
---|
93 | PCUT_ASSERT_EQUALS(e2, e);
|
---|
94 | e = tbarcfg_smenu_next(e);
|
---|
95 | PCUT_ASSERT_NOT_NULL(e);
|
---|
96 | e = tbarcfg_smenu_next(e);
|
---|
97 | PCUT_ASSERT_NULL(e);
|
---|
98 |
|
---|
99 | tbarcfg_close(tbcfg);
|
---|
100 | remove(fname);
|
---|
101 | }
|
---|
102 |
|
---|
103 | /** Getting menu entry properties */
|
---|
104 | PCUT_TEST(get_caption_cmd)
|
---|
105 | {
|
---|
106 | errno_t rc;
|
---|
107 | tbarcfg_t *tbcfg;
|
---|
108 | char fname[L_tmpnam], *p;
|
---|
109 | smenu_entry_t *e;
|
---|
110 | const char *caption;
|
---|
111 | const char *cmd;
|
---|
112 |
|
---|
113 | p = tmpnam(fname);
|
---|
114 | PCUT_ASSERT_NOT_NULL(p);
|
---|
115 |
|
---|
116 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
117 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
118 |
|
---|
119 | rc = smenu_entry_create(tbcfg, "A", "a", &e);
|
---|
120 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
121 |
|
---|
122 | caption = smenu_entry_get_caption(e);
|
---|
123 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
124 | cmd = smenu_entry_get_cmd(e);
|
---|
125 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
126 |
|
---|
127 | tbarcfg_close(tbcfg);
|
---|
128 | remove(fname);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Setting menu entry properties */
|
---|
132 | PCUT_TEST(set_caption_cmd)
|
---|
133 | {
|
---|
134 | errno_t rc;
|
---|
135 | tbarcfg_t *tbcfg;
|
---|
136 | char fname[L_tmpnam], *p;
|
---|
137 | smenu_entry_t *e;
|
---|
138 | const char *caption;
|
---|
139 | const char *cmd;
|
---|
140 |
|
---|
141 | p = tmpnam(fname);
|
---|
142 | PCUT_ASSERT_NOT_NULL(p);
|
---|
143 |
|
---|
144 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
145 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
146 |
|
---|
147 | rc = smenu_entry_create(tbcfg, "A", "a", &e);
|
---|
148 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
149 |
|
---|
150 | caption = smenu_entry_get_caption(e);
|
---|
151 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
152 | cmd = smenu_entry_get_cmd(e);
|
---|
153 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
154 |
|
---|
155 | /* Set properties */
|
---|
156 | rc = smenu_entry_set_caption(e, "B");
|
---|
157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
158 | rc = smenu_entry_set_cmd(e, "b");
|
---|
159 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
160 |
|
---|
161 | rc = smenu_entry_save(e);
|
---|
162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
163 |
|
---|
164 | /* Check that properties have been set */
|
---|
165 | caption = smenu_entry_get_caption(e);
|
---|
166 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
167 | cmd = smenu_entry_get_cmd(e);
|
---|
168 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
169 |
|
---|
170 | tbarcfg_close(tbcfg);
|
---|
171 |
|
---|
172 | /* Re-open repository */
|
---|
173 |
|
---|
174 | rc = tbarcfg_open(fname, &tbcfg);
|
---|
175 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
176 |
|
---|
177 | e = tbarcfg_smenu_first(tbcfg);
|
---|
178 | PCUT_ASSERT_NOT_NULL(e);
|
---|
179 |
|
---|
180 | /* Check that new values of properties have persisted */
|
---|
181 | caption = smenu_entry_get_caption(e);
|
---|
182 | PCUT_ASSERT_STR_EQUALS("B", caption);
|
---|
183 | cmd = smenu_entry_get_cmd(e);
|
---|
184 | PCUT_ASSERT_STR_EQUALS("b", cmd);
|
---|
185 |
|
---|
186 | tbarcfg_close(tbcfg);
|
---|
187 | remove(fname);
|
---|
188 | }
|
---|
189 |
|
---|
190 | /** Create start menu entry */
|
---|
191 | PCUT_TEST(entry_create)
|
---|
192 | {
|
---|
193 | errno_t rc;
|
---|
194 | tbarcfg_t *tbcfg;
|
---|
195 | char fname[L_tmpnam], *p;
|
---|
196 | smenu_entry_t *e;
|
---|
197 | const char *caption;
|
---|
198 | const char *cmd;
|
---|
199 |
|
---|
200 | p = tmpnam(fname);
|
---|
201 | PCUT_ASSERT_NOT_NULL(p);
|
---|
202 |
|
---|
203 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
204 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
205 |
|
---|
206 | rc = smenu_entry_create(tbcfg, "A", "a", &e);
|
---|
207 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
208 | PCUT_ASSERT_NOT_NULL(e);
|
---|
209 |
|
---|
210 | caption = smenu_entry_get_caption(e);
|
---|
211 | PCUT_ASSERT_STR_EQUALS("A", caption);
|
---|
212 | cmd = smenu_entry_get_cmd(e);
|
---|
213 | PCUT_ASSERT_STR_EQUALS("a", cmd);
|
---|
214 |
|
---|
215 | tbarcfg_close(tbcfg);
|
---|
216 | remove(fname);
|
---|
217 | }
|
---|
218 |
|
---|
219 | /** Destroy start menu entry */
|
---|
220 | PCUT_TEST(entry_destroy)
|
---|
221 | {
|
---|
222 | errno_t rc;
|
---|
223 | tbarcfg_t *tbcfg;
|
---|
224 | char fname[L_tmpnam], *p;
|
---|
225 | smenu_entry_t *e, *f;
|
---|
226 |
|
---|
227 | p = tmpnam(fname);
|
---|
228 | PCUT_ASSERT_NOT_NULL(p);
|
---|
229 |
|
---|
230 | rc = tbarcfg_create(fname, &tbcfg);
|
---|
231 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
232 |
|
---|
233 | rc = smenu_entry_create(tbcfg, "A", "a", &e);
|
---|
234 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
235 |
|
---|
236 | f = tbarcfg_smenu_first(tbcfg);
|
---|
237 | PCUT_ASSERT_EQUALS(e, f);
|
---|
238 |
|
---|
239 | rc = smenu_entry_destroy(e);
|
---|
240 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
241 |
|
---|
242 | f = tbarcfg_smenu_first(tbcfg);
|
---|
243 | PCUT_ASSERT_NULL(f);
|
---|
244 |
|
---|
245 | tbarcfg_close(tbcfg);
|
---|
246 | remove(fname);
|
---|
247 | }
|
---|
248 |
|
---|
249 | PCUT_EXPORT(tbarcfg);
|
---|