source: mainline/uspace/lib/sif/test/sif.c@ 1c398db2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1c398db2 was b79903b, checked in by Jiri Svoboda <jiri@…>, 7 years ago

SIF, work-in-progress.

  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * Copyright (c) 2018 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 <stdio.h>
32#include "../include/sif.h"
33
34PCUT_INIT;
35
36PCUT_TEST_SUITE(sif);
37
38/** Test sif_create. */
39PCUT_TEST(sif_create)
40{
41 sif_sess_t *sess;
42 errno_t rc;
43 int rv;
44 char *fname;
45 char *p;
46
47 fname = calloc(L_tmpnam, 1);
48 PCUT_ASSERT_NOT_NULL(fname);
49
50 p = tmpnam(fname);
51 PCUT_ASSERT_TRUE(p == fname);
52
53 rc = sif_create(fname, &sess);
54 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
55
56 rc = sif_close(sess);
57 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
58
59 rv = remove(fname);
60 PCUT_ASSERT_INT_EQUALS(0, rv);
61}
62
63/** Test sif_node_prepend_child. */
64PCUT_TEST(sif_node_prepend_child)
65{
66 sif_sess_t *sess;
67 sif_node_t *root;
68 sif_node_t *ca;
69 sif_node_t *cb;
70 sif_node_t *c1;
71 sif_node_t *c2;
72 sif_node_t *c3;
73 sif_trans_t *trans;
74 errno_t rc;
75 int rv;
76 char *fname;
77 char *p;
78
79 fname = calloc(L_tmpnam, 1);
80 PCUT_ASSERT_NOT_NULL(fname);
81
82 p = tmpnam(fname);
83 PCUT_ASSERT_TRUE(p == fname);
84
85 rc = sif_create(fname, &sess);
86 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
87
88 root = sif_get_root(sess);
89
90 rc = sif_trans_begin(sess, &trans);
91 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
92
93 rc = sif_node_prepend_child(trans, root, "a", &ca);
94 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
95
96 rc = sif_node_prepend_child(trans, root, "b", &cb);
97 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
98
99 rc = sif_trans_end(trans);
100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
101
102 c1 = sif_node_first_child(root);
103 PCUT_ASSERT_TRUE(c1 == cb);
104
105 c2 = sif_node_next_child(c1);
106 PCUT_ASSERT_TRUE(c2 == ca);
107
108 c3 = sif_node_next_child(c2);
109 PCUT_ASSERT_TRUE(c3 == NULL);
110
111 rc = sif_close(sess);
112 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
113
114 rv = remove(fname);
115 PCUT_ASSERT_INT_EQUALS(0, rv);
116}
117
118/** Test sif_node_append_child. */
119PCUT_TEST(sif_node_append_child)
120{
121 sif_sess_t *sess;
122 sif_node_t *root;
123 sif_node_t *ca;
124 sif_node_t *cb;
125 sif_node_t *c1;
126 sif_node_t *c2;
127 sif_node_t *c3;
128 sif_trans_t *trans;
129 errno_t rc;
130 int rv;
131 char *fname;
132 char *p;
133
134 fname = calloc(L_tmpnam, 1);
135 PCUT_ASSERT_NOT_NULL(fname);
136
137 p = tmpnam(fname);
138 PCUT_ASSERT_TRUE(p == fname);
139
140 rc = sif_create(fname, &sess);
141 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
142
143 root = sif_get_root(sess);
144
145 rc = sif_trans_begin(sess, &trans);
146 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
147
148 rc = sif_node_append_child(trans, root, "a", &ca);
149 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
150
151 rc = sif_node_append_child(trans, root, "b", &cb);
152 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
153
154 rc = sif_trans_end(trans);
155 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156
157 c1 = sif_node_first_child(root);
158 PCUT_ASSERT_TRUE(c1 == ca);
159
160 c2 = sif_node_next_child(c1);
161 PCUT_ASSERT_TRUE(c2 == cb);
162
163 c3 = sif_node_next_child(c2);
164 PCUT_ASSERT_TRUE(c3 == NULL);
165
166 rc = sif_close(sess);
167 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
168
169 rv = remove(fname);
170 PCUT_ASSERT_INT_EQUALS(0, rv);
171}
172
173/** Test sif_node_insert_before. */
174PCUT_TEST(sif_node_insert_before)
175{
176 sif_sess_t *sess;
177 sif_node_t *root;
178 sif_node_t *ca;
179 sif_node_t *cb;
180 sif_node_t *cc;
181 sif_node_t *c1;
182 sif_node_t *c2;
183 sif_node_t *c3;
184 sif_node_t *c4;
185 sif_trans_t *trans;
186 errno_t rc;
187 int rv;
188 char *fname;
189 char *p;
190
191 fname = calloc(L_tmpnam, 1);
192 PCUT_ASSERT_NOT_NULL(fname);
193
194 p = tmpnam(fname);
195 PCUT_ASSERT_TRUE(p == fname);
196
197 rc = sif_create(fname, &sess);
198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
199
200 root = sif_get_root(sess);
201
202 rc = sif_trans_begin(sess, &trans);
203 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
204
205 rc = sif_node_append_child(trans, root, "a", &ca);
206 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
207
208 rc = sif_node_append_child(trans, root, "c", &cc);
209 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
210
211 rc = sif_node_insert_before(trans, cc, "b", &cb);
212 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
213
214 rc = sif_trans_end(trans);
215 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
216
217 c1 = sif_node_first_child(root);
218 PCUT_ASSERT_TRUE(c1 == ca);
219
220 c2 = sif_node_next_child(c1);
221 PCUT_ASSERT_TRUE(c2 == cb);
222
223 c3 = sif_node_next_child(c2);
224 PCUT_ASSERT_TRUE(c3 == cc);
225
226 c4 = sif_node_next_child(c3);
227 PCUT_ASSERT_TRUE(c4 == NULL);
228
229 rc = sif_close(sess);
230 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
231
232 rv = remove(fname);
233 PCUT_ASSERT_INT_EQUALS(0, rv);
234}
235
236/** Test sif_node_insert_after. */
237PCUT_TEST(sif_node_insert_after)
238{
239 sif_sess_t *sess;
240 sif_node_t *root;
241 sif_node_t *ca;
242 sif_node_t *cb;
243 sif_node_t *cc;
244 sif_node_t *c1;
245 sif_node_t *c2;
246 sif_node_t *c3;
247 sif_node_t *c4;
248 sif_trans_t *trans;
249 errno_t rc;
250 int rv;
251 char *fname;
252 char *p;
253
254 fname = calloc(L_tmpnam, 1);
255 PCUT_ASSERT_NOT_NULL(fname);
256
257 p = tmpnam(fname);
258 PCUT_ASSERT_TRUE(p == fname);
259
260 rc = sif_create(fname, &sess);
261 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
262
263 root = sif_get_root(sess);
264
265 rc = sif_trans_begin(sess, &trans);
266 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
267
268 rc = sif_node_append_child(trans, root, "a", &ca);
269 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
270
271 rc = sif_node_append_child(trans, root, "c", &cc);
272 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
273
274 rc = sif_node_insert_after(trans, ca, "b", &cb);
275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
276
277 rc = sif_trans_end(trans);
278 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
279
280 c1 = sif_node_first_child(root);
281 PCUT_ASSERT_TRUE(c1 == ca);
282
283 c2 = sif_node_next_child(c1);
284 PCUT_ASSERT_TRUE(c2 == cb);
285
286 c3 = sif_node_next_child(c2);
287 PCUT_ASSERT_TRUE(c3 == cc);
288
289 c4 = sif_node_next_child(c3);
290 PCUT_ASSERT_TRUE(c4 == NULL);
291
292 rc = sif_close(sess);
293 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
294
295 rv = remove(fname);
296 PCUT_ASSERT_INT_EQUALS(0, rv);
297}
298
299PCUT_EXPORT(sif);
Note: See TracBrowser for help on using the repository browser.