t_proplib.c revision 1.4 1 1.4 thorpej /* $NetBSD: t_proplib.c,v 1.4 2020/06/24 14:28:10 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej *
16 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
27 1.1 thorpej */
28 1.1 thorpej
29 1.1 thorpej /*
30 1.1 thorpej * Written by Jason Thorpe 5/26/2006.
31 1.1 thorpej * Public domain.
32 1.1 thorpej */
33 1.1 thorpej
34 1.1 thorpej #include <sys/cdefs.h>
35 1.1 thorpej __COPYRIGHT("@(#) Copyright (c) 2008, 2020\
36 1.1 thorpej The NetBSD Foundation, inc. All rights reserved.");
37 1.4 thorpej __RCSID("$NetBSD: t_proplib.c,v 1.4 2020/06/24 14:28:10 thorpej Exp $");
38 1.1 thorpej
39 1.1 thorpej #include <limits.h>
40 1.1 thorpej #include <stdlib.h>
41 1.1 thorpej #include <string.h>
42 1.1 thorpej #include <prop/proplib.h>
43 1.1 thorpej
44 1.1 thorpej #include <atf-c.h>
45 1.1 thorpej
46 1.1 thorpej static const char compare1[] =
47 1.1 thorpej "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
48 1.1 thorpej "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
49 1.1 thorpej "<plist version=\"1.0\">\n"
50 1.1 thorpej "<dict>\n"
51 1.1 thorpej " <key>false-val</key>\n"
52 1.1 thorpej " <false/>\n"
53 1.1 thorpej " <key>one</key>\n"
54 1.1 thorpej " <integer>1</integer>\n"
55 1.1 thorpej " <key>three</key>\n"
56 1.1 thorpej " <array>\n"
57 1.1 thorpej " <dict>\n"
58 1.1 thorpej " <key>one</key>\n"
59 1.1 thorpej " <integer>1</integer>\n"
60 1.1 thorpej " <key>two</key>\n"
61 1.1 thorpej " <string>number-two</string>\n"
62 1.1 thorpej " </dict>\n"
63 1.1 thorpej " <dict>\n"
64 1.1 thorpej " <key>one</key>\n"
65 1.1 thorpej " <integer>1</integer>\n"
66 1.1 thorpej " <key>two</key>\n"
67 1.1 thorpej " <string>number-two</string>\n"
68 1.1 thorpej " </dict>\n"
69 1.1 thorpej " <dict>\n"
70 1.1 thorpej " <key>one</key>\n"
71 1.1 thorpej " <integer>1</integer>\n"
72 1.1 thorpej " <key>two</key>\n"
73 1.1 thorpej " <string>number-two</string>\n"
74 1.1 thorpej " </dict>\n"
75 1.1 thorpej " </array>\n"
76 1.1 thorpej " <key>true-val</key>\n"
77 1.1 thorpej " <true/>\n"
78 1.1 thorpej " <key>two</key>\n"
79 1.1 thorpej " <string>number-two</string>\n"
80 1.1 thorpej "</dict>\n"
81 1.1 thorpej "</plist>\n";
82 1.1 thorpej
83 1.1 thorpej static const char const_data1[] = {
84 1.1 thorpej 0xde, 0xad, 0xbe, 0xef
85 1.1 thorpej };
86 1.1 thorpej
87 1.1 thorpej static const char const_data2[] = {
88 1.1 thorpej 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
89 1.1 thorpej };
90 1.1 thorpej
91 1.1 thorpej static const char const_string1[] =
92 1.1 thorpej "The quick brown fox jumps over the lazy dog.";
93 1.1 thorpej
94 1.1 thorpej static const char const_string2[] =
95 1.1 thorpej "Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
96 1.1 thorpej "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
97 1.1 thorpej
98 1.1 thorpej ATF_TC(prop_basic);
99 1.1 thorpej ATF_TC_HEAD(prop_basic, tc)
100 1.1 thorpej {
101 1.1 thorpej atf_tc_set_md_var(tc, "descr", "A basic test of proplib(3)");
102 1.1 thorpej }
103 1.1 thorpej
104 1.1 thorpej ATF_TC_BODY(prop_basic, tc)
105 1.1 thorpej {
106 1.1 thorpej prop_dictionary_t dict;
107 1.1 thorpej char *ext1;
108 1.1 thorpej
109 1.1 thorpej dict = prop_dictionary_create();
110 1.1 thorpej ATF_REQUIRE(dict != NULL);
111 1.1 thorpej
112 1.1 thorpej {
113 1.2 thorpej prop_number_t num = prop_number_create_signed(1);
114 1.1 thorpej ATF_REQUIRE(num != NULL);
115 1.1 thorpej
116 1.1 thorpej ATF_REQUIRE_EQ(prop_dictionary_set(dict, "one", num), true);
117 1.1 thorpej prop_object_release(num);
118 1.1 thorpej }
119 1.1 thorpej
120 1.1 thorpej {
121 1.2 thorpej prop_string_t str = prop_string_create_copy("number-two");
122 1.1 thorpej ATF_REQUIRE(str != NULL);
123 1.1 thorpej
124 1.1 thorpej ATF_REQUIRE_EQ(prop_dictionary_set(dict, "two", str), true);
125 1.1 thorpej prop_object_release(str);
126 1.1 thorpej }
127 1.1 thorpej
128 1.1 thorpej {
129 1.1 thorpej prop_array_t arr;
130 1.1 thorpej prop_dictionary_t dict_copy;
131 1.1 thorpej int i;
132 1.1 thorpej
133 1.1 thorpej arr = prop_array_create();
134 1.1 thorpej ATF_REQUIRE(arr != NULL);
135 1.1 thorpej
136 1.1 thorpej for (i = 0; i < 3; ++i) {
137 1.1 thorpej dict_copy = prop_dictionary_copy(dict);
138 1.1 thorpej ATF_REQUIRE(dict_copy != NULL);
139 1.1 thorpej ATF_REQUIRE_EQ(prop_array_add(arr, dict_copy), true);
140 1.1 thorpej prop_object_release(dict_copy);
141 1.1 thorpej }
142 1.1 thorpej
143 1.1 thorpej ATF_REQUIRE_EQ(prop_dictionary_set(dict, "three", arr), true);
144 1.1 thorpej prop_object_release(arr);
145 1.1 thorpej }
146 1.1 thorpej
147 1.1 thorpej {
148 1.1 thorpej prop_bool_t val = prop_bool_create(true);
149 1.1 thorpej ATF_REQUIRE(val != NULL);
150 1.1 thorpej ATF_REQUIRE_EQ(prop_dictionary_set(dict, "true-val", val), true);
151 1.1 thorpej prop_object_release(val);
152 1.1 thorpej
153 1.1 thorpej val = prop_bool_create(false);
154 1.1 thorpej ATF_REQUIRE(val != NULL);
155 1.1 thorpej ATF_REQUIRE_EQ(prop_dictionary_set(dict, "false-val", val), true);
156 1.1 thorpej prop_object_release(val);
157 1.1 thorpej }
158 1.1 thorpej
159 1.1 thorpej ext1 = prop_dictionary_externalize(dict);
160 1.1 thorpej ATF_REQUIRE(ext1 != NULL);
161 1.1 thorpej ATF_REQUIRE_STREQ(compare1, ext1);
162 1.1 thorpej
163 1.1 thorpej {
164 1.1 thorpej prop_dictionary_t dict2;
165 1.1 thorpej char *ext2;
166 1.1 thorpej
167 1.1 thorpej dict2 = prop_dictionary_internalize(ext1);
168 1.1 thorpej ATF_REQUIRE(dict2 != NULL);
169 1.1 thorpej ext2 = prop_dictionary_externalize(dict2);
170 1.1 thorpej ATF_REQUIRE(ext2 != NULL);
171 1.1 thorpej ATF_REQUIRE_STREQ(ext1, ext2);
172 1.1 thorpej prop_object_release(dict2);
173 1.1 thorpej free(ext2);
174 1.1 thorpej }
175 1.1 thorpej
176 1.1 thorpej prop_object_release(dict);
177 1.1 thorpej free(ext1);
178 1.1 thorpej }
179 1.1 thorpej
180 1.1 thorpej ATF_TC(prop_dictionary_equals);
181 1.1 thorpej ATF_TC_HEAD(prop_dictionary_equals, tc)
182 1.1 thorpej {
183 1.1 thorpej atf_tc_set_md_var(tc, "descr", "Test prop_dictionary_equals(3)");
184 1.1 thorpej }
185 1.1 thorpej
186 1.1 thorpej ATF_TC_BODY(prop_dictionary_equals, tc)
187 1.1 thorpej {
188 1.1 thorpej prop_dictionary_t c, d;
189 1.1 thorpej
190 1.1 thorpej /*
191 1.1 thorpej * Fixed, should not fail any more...
192 1.1 thorpej *
193 1.1 thorpej atf_tc_expect_death("PR lib/43964");
194 1.1 thorpej *
195 1.1 thorpej */
196 1.1 thorpej
197 1.1 thorpej d = prop_dictionary_internalize(compare1);
198 1.1 thorpej
199 1.1 thorpej ATF_REQUIRE(d != NULL);
200 1.1 thorpej
201 1.1 thorpej c = prop_dictionary_copy(d);
202 1.1 thorpej
203 1.1 thorpej ATF_REQUIRE(c != NULL);
204 1.1 thorpej
205 1.1 thorpej if (prop_dictionary_equals(c, d) != true)
206 1.1 thorpej atf_tc_fail("dictionaries are not equal");
207 1.1 thorpej
208 1.1 thorpej prop_object_release(c);
209 1.1 thorpej prop_object_release(d);
210 1.1 thorpej }
211 1.1 thorpej
212 1.1 thorpej ATF_TC(prop_data_basic);
213 1.1 thorpej ATF_TC_HEAD(prop_data_basic, tc)
214 1.1 thorpej {
215 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_data basics");
216 1.1 thorpej }
217 1.1 thorpej ATF_TC_BODY(prop_data_basic, tc)
218 1.1 thorpej {
219 1.1 thorpej prop_data_t d1, d2;
220 1.1 thorpej char buf[sizeof(const_data1)];
221 1.1 thorpej
222 1.1 thorpej /*
223 1.1 thorpej * This test exercises implementation details, not only
224 1.1 thorpej * API contract.
225 1.1 thorpej */
226 1.1 thorpej
227 1.3 thorpej d1 = prop_data_create_copy(const_data1, 0);
228 1.3 thorpej ATF_REQUIRE(d1 != NULL);
229 1.3 thorpej ATF_REQUIRE(prop_data_value(d1) == NULL);
230 1.3 thorpej prop_object_release(d1);
231 1.3 thorpej
232 1.3 thorpej d1 = prop_data_create_copy(NULL, sizeof(const_data1));
233 1.3 thorpej ATF_REQUIRE(d1 != NULL);
234 1.3 thorpej ATF_REQUIRE(prop_data_value(d1) == NULL);
235 1.3 thorpej prop_object_release(d1);
236 1.3 thorpej
237 1.3 thorpej d1 = prop_data_create_nocopy(const_data1, 0);
238 1.3 thorpej ATF_REQUIRE(d1 != NULL);
239 1.3 thorpej ATF_REQUIRE(prop_data_value(d1) == NULL);
240 1.3 thorpej prop_object_release(d1);
241 1.3 thorpej
242 1.3 thorpej d1 = prop_data_create_nocopy(NULL, sizeof(const_data1));
243 1.3 thorpej ATF_REQUIRE(d1 != NULL);
244 1.3 thorpej ATF_REQUIRE(prop_data_value(d1) == NULL);
245 1.3 thorpej prop_object_release(d1);
246 1.3 thorpej
247 1.1 thorpej d1 = prop_data_create_nocopy(const_data1, sizeof(const_data1));
248 1.1 thorpej ATF_REQUIRE(d1 != NULL);
249 1.1 thorpej ATF_REQUIRE(prop_data_value(d1) == const_data1);
250 1.1 thorpej d2 = prop_data_copy(d1);
251 1.1 thorpej ATF_REQUIRE(d2 != NULL);
252 1.1 thorpej ATF_REQUIRE(d2 == d1);
253 1.1 thorpej prop_object_release(d1);
254 1.1 thorpej prop_object_release(d2);
255 1.1 thorpej
256 1.1 thorpej d1 = prop_data_create_copy(const_data1, sizeof(const_data1));
257 1.1 thorpej ATF_REQUIRE(d1 != NULL);
258 1.1 thorpej ATF_REQUIRE(prop_data_value(d1) != const_data1);
259 1.1 thorpej d2 = prop_data_copy(d1);
260 1.1 thorpej ATF_REQUIRE(d2 != NULL);
261 1.1 thorpej ATF_REQUIRE(d2 == d1);
262 1.1 thorpej ATF_REQUIRE(prop_data_equals(d1, d2));
263 1.1 thorpej prop_object_release(d2);
264 1.1 thorpej
265 1.1 thorpej d2 = prop_data_create_copy(const_data2, sizeof(const_data2));
266 1.1 thorpej ATF_REQUIRE(d2 != NULL);
267 1.1 thorpej ATF_REQUIRE(prop_data_value(d2) != const_data2);
268 1.1 thorpej ATF_REQUIRE(!prop_data_equals(d1, d2));
269 1.1 thorpej
270 1.1 thorpej ATF_REQUIRE(prop_data_size(d1) == sizeof(const_data1));
271 1.1 thorpej ATF_REQUIRE(prop_data_size(d2) == sizeof(const_data2));
272 1.1 thorpej
273 1.1 thorpej ATF_REQUIRE(prop_data_copy_value(d1, buf, sizeof(buf)));
274 1.1 thorpej ATF_REQUIRE(memcmp(buf, const_data1, sizeof(buf)) == 0);
275 1.1 thorpej ATF_REQUIRE(!prop_data_copy_value(d2, buf, sizeof(buf)));
276 1.1 thorpej
277 1.1 thorpej prop_object_release(d1);
278 1.1 thorpej prop_object_release(d2);
279 1.1 thorpej }
280 1.1 thorpej
281 1.1 thorpej ATF_TC(prop_number_basic);
282 1.1 thorpej ATF_TC_HEAD(prop_number_basic, tc)
283 1.1 thorpej {
284 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_number basics");
285 1.1 thorpej }
286 1.1 thorpej ATF_TC_BODY(prop_number_basic, tc)
287 1.1 thorpej {
288 1.1 thorpej prop_number_t s1, s2, u1, u2, u3, u4;
289 1.1 thorpej
290 1.1 thorpej /*
291 1.1 thorpej * This test exercises implementation details, not only
292 1.1 thorpej * API contract.
293 1.1 thorpej */
294 1.1 thorpej
295 1.1 thorpej s1 = prop_number_create_signed(INTMAX_MAX);
296 1.1 thorpej ATF_REQUIRE(s1 != NULL);
297 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(s1) == false);
298 1.1 thorpej ATF_REQUIRE(prop_number_signed_value(s1) == INTMAX_MAX);
299 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(s1) == INTMAX_MAX);
300 1.1 thorpej ATF_REQUIRE(prop_number_equals_signed(s1, INTMAX_MAX) == true);
301 1.1 thorpej
302 1.1 thorpej s2 = prop_number_create_signed(INTMAX_MAX);
303 1.1 thorpej ATF_REQUIRE(s2 == s1);
304 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(s2) == false);
305 1.1 thorpej
306 1.1 thorpej u1 = prop_number_create_unsigned(UINTMAX_MAX);
307 1.1 thorpej ATF_REQUIRE(u1 != NULL);
308 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u1) == true);
309 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u1) == UINTMAX_MAX);
310 1.1 thorpej ATF_REQUIRE(prop_number_equals_unsigned(u1, UINTMAX_MAX) == true);
311 1.1 thorpej
312 1.1 thorpej u2 = prop_number_create_unsigned(0);
313 1.1 thorpej ATF_REQUIRE(u2 != NULL);
314 1.1 thorpej ATF_REQUIRE(u2 != u1);
315 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u2) == true);
316 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u2) == 0);
317 1.1 thorpej
318 1.1 thorpej u3 = prop_number_copy(u1);
319 1.1 thorpej ATF_REQUIRE(u3 == u1);
320 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u3) == true);
321 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u3) == UINTMAX_MAX);
322 1.1 thorpej
323 1.1 thorpej u4 = prop_number_create_unsigned(INTMAX_MAX);
324 1.1 thorpej ATF_REQUIRE(u4 != NULL);
325 1.1 thorpej ATF_REQUIRE(u4 != s1);
326 1.1 thorpej ATF_REQUIRE(prop_number_equals_signed(u4, INTMAX_MAX) == true);
327 1.1 thorpej ATF_REQUIRE(prop_number_equals_unsigned(u4, INTMAX_MAX) == true);
328 1.1 thorpej
329 1.1 thorpej prop_object_release(s1);
330 1.1 thorpej prop_object_release(s2);
331 1.1 thorpej
332 1.1 thorpej prop_object_release(u1);
333 1.1 thorpej prop_object_release(u2);
334 1.1 thorpej prop_object_release(u3);
335 1.1 thorpej prop_object_release(u4);
336 1.1 thorpej }
337 1.1 thorpej
338 1.1 thorpej ATF_TC(prop_number_range_check);
339 1.1 thorpej ATF_TC_HEAD(prop_number_range_check, tc)
340 1.1 thorpej {
341 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_number range checking");
342 1.1 thorpej }
343 1.1 thorpej ATF_TC_BODY(prop_number_range_check, tc)
344 1.1 thorpej {
345 1.1 thorpej union {
346 1.1 thorpej signed char v_schar;
347 1.1 thorpej short v_shrt;
348 1.1 thorpej int v_int;
349 1.1 thorpej long v_long;
350 1.1 thorpej long long v_llong;
351 1.1 thorpej intptr_t v_intptr;
352 1.1 thorpej int8_t v_int8;
353 1.1 thorpej int16_t v_int16;
354 1.1 thorpej int32_t v_int32;
355 1.1 thorpej int64_t v_int64;
356 1.1 thorpej
357 1.1 thorpej unsigned char v_uchar;
358 1.1 thorpej unsigned short v_ushrt;
359 1.1 thorpej unsigned int v_uint;
360 1.1 thorpej unsigned long v_ulong;
361 1.1 thorpej unsigned long long v_ullong;
362 1.1 thorpej uintptr_t v_uintptr;
363 1.1 thorpej uint8_t v_uint8;
364 1.1 thorpej uint16_t v_uint16;
365 1.1 thorpej uint32_t v_uint32;
366 1.1 thorpej uint64_t v_uint64;
367 1.1 thorpej } val;
368 1.1 thorpej
369 1.1 thorpej prop_number_t n_schar_max = prop_number_create_signed(SCHAR_MAX);
370 1.1 thorpej prop_number_t n_schar_min = prop_number_create_signed(SCHAR_MIN);
371 1.1 thorpej prop_number_t n_uchar_max = prop_number_create_unsigned(UCHAR_MAX);
372 1.1 thorpej ATF_REQUIRE(n_schar_max != NULL);
373 1.1 thorpej ATF_REQUIRE(n_schar_min != NULL);
374 1.1 thorpej ATF_REQUIRE(n_uchar_max != NULL);
375 1.1 thorpej
376 1.1 thorpej prop_number_t n_shrt_max = prop_number_create_signed(SHRT_MAX);
377 1.1 thorpej prop_number_t n_shrt_min = prop_number_create_signed(SHRT_MIN);
378 1.1 thorpej prop_number_t n_ushrt_max = prop_number_create_unsigned(USHRT_MAX);
379 1.1 thorpej ATF_REQUIRE(n_shrt_max != NULL);
380 1.1 thorpej ATF_REQUIRE(n_shrt_min != NULL);
381 1.1 thorpej ATF_REQUIRE(n_ushrt_max != NULL);
382 1.1 thorpej
383 1.1 thorpej prop_number_t n_int_max = prop_number_create_signed(INT_MAX);
384 1.1 thorpej prop_number_t n_int_min = prop_number_create_signed(INT_MIN);
385 1.1 thorpej prop_number_t n_uint_max = prop_number_create_unsigned(UINT_MAX);
386 1.1 thorpej ATF_REQUIRE(n_int_max != NULL);
387 1.1 thorpej ATF_REQUIRE(n_int_min != NULL);
388 1.1 thorpej ATF_REQUIRE(n_uint_max != NULL);
389 1.1 thorpej
390 1.1 thorpej prop_number_t n_long_max = prop_number_create_signed(LONG_MAX);
391 1.1 thorpej prop_number_t n_long_min = prop_number_create_signed(LONG_MIN);
392 1.1 thorpej prop_number_t n_ulong_max = prop_number_create_unsigned(ULONG_MAX);
393 1.1 thorpej ATF_REQUIRE(n_long_max != NULL);
394 1.1 thorpej ATF_REQUIRE(n_long_min != NULL);
395 1.1 thorpej ATF_REQUIRE(n_ulong_max != NULL);
396 1.1 thorpej
397 1.1 thorpej prop_number_t n_llong_max = prop_number_create_signed(LLONG_MAX);
398 1.1 thorpej prop_number_t n_llong_min = prop_number_create_signed(LLONG_MIN);
399 1.1 thorpej prop_number_t n_ullong_max = prop_number_create_unsigned(ULLONG_MAX);
400 1.1 thorpej ATF_REQUIRE(n_llong_max != NULL);
401 1.1 thorpej ATF_REQUIRE(n_llong_min != NULL);
402 1.1 thorpej ATF_REQUIRE(n_ullong_max != NULL);
403 1.1 thorpej
404 1.1 thorpej prop_number_t n_intptr_max = prop_number_create_signed(INTPTR_MAX);
405 1.1 thorpej prop_number_t n_intptr_min = prop_number_create_signed(INTPTR_MIN);
406 1.1 thorpej prop_number_t n_uintptr_max = prop_number_create_unsigned(UINTPTR_MAX);
407 1.1 thorpej ATF_REQUIRE(n_intptr_max != NULL);
408 1.1 thorpej ATF_REQUIRE(n_intptr_min != NULL);
409 1.1 thorpej ATF_REQUIRE(n_uintptr_max != NULL);
410 1.1 thorpej
411 1.1 thorpej prop_number_t n_int8_max = prop_number_create_signed(INT8_MAX);
412 1.1 thorpej prop_number_t n_int8_min = prop_number_create_signed(INT8_MIN);
413 1.1 thorpej prop_number_t n_uint8_max = prop_number_create_unsigned(UINT8_MAX);
414 1.1 thorpej ATF_REQUIRE(n_int8_max != NULL);
415 1.1 thorpej ATF_REQUIRE(n_int8_min != NULL);
416 1.1 thorpej ATF_REQUIRE(n_uint8_max != NULL);
417 1.1 thorpej
418 1.1 thorpej prop_number_t n_int16_max = prop_number_create_signed(INT16_MAX);
419 1.1 thorpej prop_number_t n_int16_min = prop_number_create_signed(INT16_MIN);
420 1.1 thorpej prop_number_t n_uint16_max = prop_number_create_unsigned(UINT16_MAX);
421 1.1 thorpej ATF_REQUIRE(n_int16_max != NULL);
422 1.1 thorpej ATF_REQUIRE(n_int16_min != NULL);
423 1.1 thorpej ATF_REQUIRE(n_uint16_max != NULL);
424 1.1 thorpej
425 1.1 thorpej prop_number_t n_int32_max = prop_number_create_signed(INT32_MAX);
426 1.1 thorpej prop_number_t n_int32_min = prop_number_create_signed(INT32_MIN);
427 1.1 thorpej prop_number_t n_uint32_max = prop_number_create_unsigned(UINT32_MAX);
428 1.1 thorpej ATF_REQUIRE(n_int32_max != NULL);
429 1.1 thorpej ATF_REQUIRE(n_int32_min != NULL);
430 1.1 thorpej ATF_REQUIRE(n_uint32_max != NULL);
431 1.1 thorpej
432 1.1 thorpej prop_number_t n_int64_max = prop_number_create_signed(INT64_MAX);
433 1.1 thorpej prop_number_t n_int64_min = prop_number_create_signed(INT64_MIN);
434 1.1 thorpej prop_number_t n_uint64_max = prop_number_create_unsigned(UINT64_MAX);
435 1.1 thorpej ATF_REQUIRE(n_int64_max != NULL);
436 1.1 thorpej ATF_REQUIRE(n_int64_min != NULL);
437 1.1 thorpej ATF_REQUIRE(n_uint64_max != NULL);
438 1.1 thorpej
439 1.1 thorpej /* signed / unsigned char */
440 1.1 thorpej ATF_REQUIRE(prop_number_schar_value(n_schar_max, &val.v_schar) &&
441 1.1 thorpej val.v_schar == SCHAR_MAX);
442 1.1 thorpej ATF_REQUIRE(prop_number_schar_value(n_schar_min, &val.v_schar) &&
443 1.1 thorpej val.v_schar == SCHAR_MIN);
444 1.1 thorpej ATF_REQUIRE(!prop_number_schar_value(n_uchar_max, &val.v_schar));
445 1.1 thorpej
446 1.1 thorpej ATF_REQUIRE(prop_number_uchar_value(n_schar_max, &val.v_uchar) &&
447 1.1 thorpej val.v_uchar == SCHAR_MAX);
448 1.1 thorpej ATF_REQUIRE(!prop_number_uchar_value(n_schar_min, &val.v_uchar));
449 1.1 thorpej ATF_REQUIRE(prop_number_uchar_value(n_uchar_max, &val.v_uchar) &&
450 1.1 thorpej val.v_uchar == UCHAR_MAX);
451 1.1 thorpej
452 1.1 thorpej ATF_REQUIRE(!prop_number_schar_value(n_shrt_min, &val.v_schar));
453 1.1 thorpej ATF_REQUIRE(!prop_number_uchar_value(n_shrt_max, &val.v_uchar));
454 1.1 thorpej
455 1.1 thorpej /* short / unsigned short */
456 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_uchar_max, &val.v_shrt) &&
457 1.1 thorpej val.v_shrt == UCHAR_MAX);
458 1.1 thorpej
459 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_shrt_max, &val.v_shrt) &&
460 1.1 thorpej val.v_shrt == SHRT_MAX);
461 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_shrt_min, &val.v_shrt) &&
462 1.1 thorpej val.v_shrt == SHRT_MIN);
463 1.1 thorpej ATF_REQUIRE(!prop_number_short_value(n_ushrt_max, &val.v_shrt));
464 1.1 thorpej
465 1.1 thorpej ATF_REQUIRE(prop_number_ushort_value(n_shrt_max, &val.v_ushrt) &&
466 1.1 thorpej val.v_ushrt == SHRT_MAX);
467 1.1 thorpej ATF_REQUIRE(!prop_number_ushort_value(n_shrt_min, &val.v_ushrt));
468 1.1 thorpej ATF_REQUIRE(prop_number_ushort_value(n_ushrt_max, &val.v_ushrt) &&
469 1.1 thorpej val.v_ushrt == USHRT_MAX);
470 1.1 thorpej
471 1.1 thorpej ATF_REQUIRE(!prop_number_short_value(n_int_min, &val.v_shrt));
472 1.1 thorpej ATF_REQUIRE(!prop_number_ushort_value(n_int_max, &val.v_ushrt));
473 1.1 thorpej
474 1.1 thorpej /* int / unsigned int */
475 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_ushrt_max, &val.v_int) &&
476 1.1 thorpej val.v_int == USHRT_MAX);
477 1.1 thorpej
478 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_int_max, &val.v_int) &&
479 1.1 thorpej val.v_int == INT_MAX);
480 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_int_min, &val.v_int) &&
481 1.1 thorpej val.v_int == INT_MIN);
482 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_uint_max, &val.v_int));
483 1.1 thorpej
484 1.1 thorpej ATF_REQUIRE(prop_number_uint_value(n_int_max, &val.v_uint) &&
485 1.1 thorpej val.v_uint == INT_MAX);
486 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_int_min, &val.v_uint));
487 1.1 thorpej ATF_REQUIRE(prop_number_uint_value(n_uint_max, &val.v_uint) &&
488 1.1 thorpej val.v_uint == UINT_MAX);
489 1.1 thorpej
490 1.1 thorpej #ifdef _LP64
491 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_long_min, &val.v_int));
492 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_long_max, &val.v_uint));
493 1.1 thorpej #else
494 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_llong_min, &val.v_int));
495 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_llong_max, &val.v_uint));
496 1.1 thorpej #endif /* _LP64 */
497 1.1 thorpej
498 1.1 thorpej /* long / unsigned long */
499 1.1 thorpej #ifdef _LP64
500 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_uint_max, &val.v_long) &&
501 1.1 thorpej val.v_long == UINT_MAX);
502 1.1 thorpej #endif
503 1.1 thorpej
504 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_long_max, &val.v_long) &&
505 1.1 thorpej val.v_long == LONG_MAX);
506 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_long_min, &val.v_long) &&
507 1.1 thorpej val.v_long == LONG_MIN);
508 1.1 thorpej ATF_REQUIRE(!prop_number_long_value(n_ulong_max, &val.v_long));
509 1.1 thorpej
510 1.1 thorpej ATF_REQUIRE(prop_number_ulong_value(n_long_max, &val.v_ulong) &&
511 1.1 thorpej val.v_ulong == LONG_MAX);
512 1.1 thorpej ATF_REQUIRE(!prop_number_ulong_value(n_long_min, &val.v_ulong));
513 1.1 thorpej ATF_REQUIRE(prop_number_ulong_value(n_ulong_max, &val.v_ulong) &&
514 1.1 thorpej val.v_ulong == ULONG_MAX);
515 1.1 thorpej
516 1.1 thorpej #ifndef _LP64
517 1.1 thorpej ATF_REQUIRE(!prop_number_long_value(n_llong_min, &val.v_long));
518 1.1 thorpej ATF_REQUIRE(!prop_number_ulong_value(n_llong_max, &val.v_ulong));
519 1.1 thorpej #endif
520 1.1 thorpej
521 1.1 thorpej /* intptr_t / uintptr_t */
522 1.1 thorpej #ifdef _LP64
523 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_uint_max, &val.v_intptr) &&
524 1.1 thorpej val.v_intptr == UINT_MAX);
525 1.1 thorpej #endif
526 1.1 thorpej
527 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_intptr_max, &val.v_intptr) &&
528 1.1 thorpej val.v_intptr == INTPTR_MAX);
529 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_intptr_min, &val.v_intptr) &&
530 1.1 thorpej val.v_intptr == INTPTR_MIN);
531 1.1 thorpej ATF_REQUIRE(!prop_number_intptr_value(n_uintptr_max, &val.v_intptr));
532 1.1 thorpej
533 1.1 thorpej ATF_REQUIRE(prop_number_uintptr_value(n_intptr_max, &val.v_uintptr) &&
534 1.1 thorpej val.v_uintptr == INTPTR_MAX);
535 1.1 thorpej ATF_REQUIRE(!prop_number_uintptr_value(n_intptr_min, &val.v_uintptr));
536 1.1 thorpej ATF_REQUIRE(prop_number_uintptr_value(n_uintptr_max, &val.v_uintptr) &&
537 1.1 thorpej val.v_uintptr == UINTPTR_MAX);
538 1.1 thorpej
539 1.1 thorpej #ifndef _LP64
540 1.1 thorpej ATF_REQUIRE(!prop_number_intptr_value(n_llong_min, &val.v_intptr));
541 1.1 thorpej ATF_REQUIRE(!prop_number_uintptr_value(n_llong_max, &val.v_uintptr));
542 1.1 thorpej #endif
543 1.1 thorpej
544 1.1 thorpej /* long long / unsigned long long */
545 1.1 thorpej #ifdef _LP64
546 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_uint_max, &val.v_llong) &&
547 1.1 thorpej val.v_llong == UINT_MAX);
548 1.1 thorpej #else
549 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_ulong_max, &val.v_llong) &&
550 1.1 thorpej val.v_llong == ULONG_MAX);
551 1.1 thorpej #endif
552 1.1 thorpej
553 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_llong_max, &val.v_llong) &&
554 1.4 thorpej val.v_llong == LLONG_MAX);
555 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_llong_min, &val.v_llong) &&
556 1.4 thorpej val.v_llong == LLONG_MIN);
557 1.1 thorpej ATF_REQUIRE(!prop_number_longlong_value(n_ullong_max, &val.v_llong));
558 1.1 thorpej
559 1.1 thorpej ATF_REQUIRE(prop_number_ulonglong_value(n_llong_max, &val.v_ullong) &&
560 1.4 thorpej val.v_ullong == LLONG_MAX);
561 1.1 thorpej ATF_REQUIRE(!prop_number_ulonglong_value(n_llong_min, &val.v_ullong));
562 1.1 thorpej ATF_REQUIRE(prop_number_ulonglong_value(n_ullong_max, &val.v_ullong) &&
563 1.4 thorpej val.v_ullong == ULLONG_MAX);
564 1.1 thorpej
565 1.1 thorpej /* int8_t / uint8_t */
566 1.1 thorpej ATF_REQUIRE(prop_number_int8_value(n_int8_max, &val.v_int8) &&
567 1.1 thorpej val.v_int8 == INT8_MAX);
568 1.1 thorpej ATF_REQUIRE(prop_number_int8_value(n_int8_min, &val.v_int8) &&
569 1.1 thorpej val.v_int8 == INT8_MIN);
570 1.1 thorpej ATF_REQUIRE(!prop_number_int8_value(n_uint8_max, &val.v_int8));
571 1.1 thorpej
572 1.1 thorpej ATF_REQUIRE(prop_number_uint8_value(n_int8_max, &val.v_uint8) &&
573 1.1 thorpej val.v_uint8 == INT8_MAX);
574 1.1 thorpej ATF_REQUIRE(!prop_number_uint8_value(n_int8_min, &val.v_uint8));
575 1.1 thorpej ATF_REQUIRE(prop_number_uint8_value(n_uint8_max, &val.v_uint8) &&
576 1.1 thorpej val.v_uint8 == UINT8_MAX);
577 1.1 thorpej
578 1.1 thorpej ATF_REQUIRE(!prop_number_int8_value(n_int16_min, &val.v_int8));
579 1.1 thorpej ATF_REQUIRE(!prop_number_uint8_value(n_int16_max, &val.v_uint8));
580 1.1 thorpej
581 1.1 thorpej /* int16_t / uint16_t */
582 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_uint8_max, &val.v_int16) &&
583 1.1 thorpej val.v_int16 == UINT8_MAX);
584 1.1 thorpej
585 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_int16_max, &val.v_int16) &&
586 1.1 thorpej val.v_int16 == INT16_MAX);
587 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_int16_min, &val.v_int16) &&
588 1.1 thorpej val.v_int16 == INT16_MIN);
589 1.1 thorpej ATF_REQUIRE(!prop_number_int16_value(n_uint16_max, &val.v_int16));
590 1.1 thorpej
591 1.1 thorpej ATF_REQUIRE(prop_number_uint16_value(n_int16_max, &val.v_uint16) &&
592 1.1 thorpej val.v_uint16 == INT16_MAX);
593 1.1 thorpej ATF_REQUIRE(!prop_number_uint16_value(n_int16_min, &val.v_uint16));
594 1.1 thorpej ATF_REQUIRE(prop_number_uint16_value(n_uint16_max, &val.v_uint16) &&
595 1.1 thorpej val.v_uint16 == UINT16_MAX);
596 1.1 thorpej
597 1.1 thorpej ATF_REQUIRE(!prop_number_int16_value(n_int32_min, &val.v_int16));
598 1.1 thorpej ATF_REQUIRE(!prop_number_uint16_value(n_int32_max, &val.v_uint16));
599 1.1 thorpej
600 1.1 thorpej /* int32_t / uint32_t */
601 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_uint16_max, &val.v_int32) &&
602 1.1 thorpej val.v_int32 == UINT16_MAX);
603 1.1 thorpej
604 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_int32_max, &val.v_int32) &&
605 1.1 thorpej val.v_int32 == INT32_MAX);
606 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_int32_min, &val.v_int32) &&
607 1.1 thorpej val.v_int32 == INT32_MIN);
608 1.1 thorpej ATF_REQUIRE(!prop_number_int32_value(n_uint32_max, &val.v_int32));
609 1.1 thorpej
610 1.1 thorpej ATF_REQUIRE(prop_number_uint32_value(n_int32_max, &val.v_uint32) &&
611 1.1 thorpej val.v_uint32 == INT32_MAX);
612 1.1 thorpej ATF_REQUIRE(!prop_number_uint32_value(n_int32_min, &val.v_uint32));
613 1.1 thorpej ATF_REQUIRE(prop_number_uint32_value(n_uint32_max, &val.v_uint32) &&
614 1.1 thorpej val.v_uint32 == UINT32_MAX);
615 1.1 thorpej
616 1.1 thorpej ATF_REQUIRE(!prop_number_int32_value(n_int64_min, &val.v_int32));
617 1.1 thorpej ATF_REQUIRE(!prop_number_uint32_value(n_int64_max, &val.v_uint32));
618 1.1 thorpej
619 1.1 thorpej /* int64_t / uint64_t */
620 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_uint32_max, &val.v_int64) &&
621 1.1 thorpej val.v_int64 == UINT32_MAX);
622 1.1 thorpej
623 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_int64_max, &val.v_int64) &&
624 1.1 thorpej val.v_int64 == INT64_MAX);
625 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_int64_min, &val.v_int64) &&
626 1.1 thorpej val.v_int64 == INT64_MIN);
627 1.1 thorpej ATF_REQUIRE(!prop_number_int64_value(n_uint64_max, &val.v_int64));
628 1.1 thorpej
629 1.1 thorpej ATF_REQUIRE(prop_number_uint64_value(n_int64_max, &val.v_uint64) &&
630 1.1 thorpej val.v_uint64 == INT64_MAX);
631 1.1 thorpej ATF_REQUIRE(!prop_number_uint64_value(n_int64_min, &val.v_uint64));
632 1.1 thorpej ATF_REQUIRE(prop_number_uint64_value(n_uint64_max, &val.v_uint64) &&
633 1.1 thorpej val.v_uint64 == UINT64_MAX);
634 1.1 thorpej
635 1.1 thorpej prop_object_release(n_schar_max);
636 1.1 thorpej prop_object_release(n_schar_min);
637 1.1 thorpej prop_object_release(n_uchar_max);
638 1.1 thorpej
639 1.1 thorpej prop_object_release(n_shrt_max);
640 1.1 thorpej prop_object_release(n_shrt_min);
641 1.1 thorpej prop_object_release(n_ushrt_max);
642 1.1 thorpej
643 1.1 thorpej prop_object_release(n_int_max);
644 1.1 thorpej prop_object_release(n_int_min);
645 1.1 thorpej prop_object_release(n_uint_max);
646 1.1 thorpej
647 1.1 thorpej prop_object_release(n_long_max);
648 1.1 thorpej prop_object_release(n_long_min);
649 1.1 thorpej prop_object_release(n_ulong_max);
650 1.1 thorpej
651 1.1 thorpej prop_object_release(n_llong_max);
652 1.1 thorpej prop_object_release(n_llong_min);
653 1.1 thorpej prop_object_release(n_ullong_max);
654 1.1 thorpej
655 1.1 thorpej prop_object_release(n_intptr_max);
656 1.1 thorpej prop_object_release(n_intptr_min);
657 1.1 thorpej prop_object_release(n_uintptr_max);
658 1.1 thorpej
659 1.1 thorpej prop_object_release(n_int8_max);
660 1.1 thorpej prop_object_release(n_int8_min);
661 1.1 thorpej prop_object_release(n_uint8_max);
662 1.1 thorpej
663 1.1 thorpej prop_object_release(n_int16_max);
664 1.1 thorpej prop_object_release(n_int16_min);
665 1.1 thorpej prop_object_release(n_uint16_max);
666 1.1 thorpej
667 1.1 thorpej prop_object_release(n_int32_max);
668 1.1 thorpej prop_object_release(n_int32_min);
669 1.1 thorpej prop_object_release(n_uint32_max);
670 1.1 thorpej
671 1.1 thorpej prop_object_release(n_int64_max);
672 1.1 thorpej prop_object_release(n_int64_min);
673 1.1 thorpej prop_object_release(n_uint64_max);
674 1.1 thorpej }
675 1.1 thorpej
676 1.1 thorpej ATF_TC(prop_string_basic);
677 1.1 thorpej ATF_TC_HEAD(prop_string_basic, tc)
678 1.1 thorpej {
679 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_string basics");
680 1.1 thorpej }
681 1.1 thorpej ATF_TC_BODY(prop_string_basic, tc)
682 1.1 thorpej {
683 1.1 thorpej prop_string_t s1, s2, s3;
684 1.1 thorpej prop_number_t num;
685 1.1 thorpej char buf[sizeof(const_string1)];
686 1.1 thorpej
687 1.1 thorpej /*
688 1.1 thorpej * This test exercises implementation details, not only
689 1.1 thorpej * API contract.
690 1.1 thorpej */
691 1.1 thorpej
692 1.1 thorpej s1 = prop_string_create_nocopy(const_string1);
693 1.1 thorpej ATF_REQUIRE(s1 != NULL);
694 1.1 thorpej s2 = prop_string_create_copy(const_string1);
695 1.1 thorpej ATF_REQUIRE(s2 != NULL);
696 1.1 thorpej ATF_REQUIRE(s2 == s1);
697 1.1 thorpej ATF_REQUIRE(prop_string_value(s1) == const_string1);
698 1.1 thorpej prop_object_release(s1);
699 1.1 thorpej prop_object_release(s2);
700 1.1 thorpej
701 1.1 thorpej s1 = prop_string_create_copy(const_string1);
702 1.1 thorpej ATF_REQUIRE(s1 != NULL);
703 1.1 thorpej s2 = prop_string_create_nocopy(const_string1);
704 1.1 thorpej ATF_REQUIRE(s2 != NULL);
705 1.1 thorpej ATF_REQUIRE(s2 == s1);
706 1.1 thorpej ATF_REQUIRE(prop_string_value(s1) != const_string1);
707 1.1 thorpej prop_object_release(s1);
708 1.1 thorpej prop_object_release(s2);
709 1.1 thorpej
710 1.1 thorpej s1 = prop_string_create_format("%d-%d", 12345, 67890);
711 1.1 thorpej ATF_REQUIRE(s1 != NULL);
712 1.1 thorpej ATF_REQUIRE(strcmp(prop_string_value(s1), "12345-67890") == 0);
713 1.1 thorpej ATF_REQUIRE(prop_string_equals_string(s1, "12345-67890"));
714 1.1 thorpej prop_object_release(s1);
715 1.1 thorpej
716 1.1 thorpej s1 = prop_string_create_nocopy(const_string1);
717 1.1 thorpej ATF_REQUIRE(s1 != NULL);
718 1.1 thorpej s2 = prop_string_create_nocopy(const_string2);
719 1.1 thorpej ATF_REQUIRE(s2 != NULL);
720 1.1 thorpej ATF_REQUIRE(prop_string_size(s1) == strlen(const_string1));
721 1.1 thorpej ATF_REQUIRE(prop_string_size(s2) == strlen(const_string2));
722 1.1 thorpej ATF_REQUIRE(prop_string_copy_value(s1, buf, sizeof(buf)));
723 1.1 thorpej ATF_REQUIRE(!prop_string_copy_value(s2, buf, sizeof(buf)));
724 1.1 thorpej prop_object_release(s1);
725 1.1 thorpej prop_object_release(s2);
726 1.1 thorpej
727 1.1 thorpej s1 = prop_string_create_copy("a");
728 1.1 thorpej ATF_REQUIRE(s1 != NULL);
729 1.1 thorpej s2 = prop_string_create_copy("b");
730 1.1 thorpej ATF_REQUIRE(s2 != NULL);
731 1.1 thorpej s3 = prop_string_copy(s2);
732 1.1 thorpej ATF_REQUIRE(s3 != NULL);
733 1.1 thorpej ATF_REQUIRE(s3 == s2);
734 1.1 thorpej num = prop_number_create_signed(666);
735 1.1 thorpej ATF_REQUIRE(num != NULL);
736 1.1 thorpej ATF_REQUIRE(!prop_string_equals(s1, s2));
737 1.1 thorpej ATF_REQUIRE(prop_string_equals(s2, s3));
738 1.1 thorpej ATF_REQUIRE(prop_string_compare(s1, s2) < 0);
739 1.1 thorpej ATF_REQUIRE(prop_string_compare(s2, s1) > 0);
740 1.1 thorpej ATF_REQUIRE(prop_string_compare(s2, s3) == 0);
741 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s1, "b") < 0);
742 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s2, "a") > 0);
743 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s3, "b") == 0);
744 1.1 thorpej ATF_REQUIRE(prop_string_compare(s1, (prop_string_t)num) != 0);
745 1.1 thorpej ATF_REQUIRE(prop_string_compare((prop_string_t)num, s1) != 0);
746 1.1 thorpej ATF_REQUIRE(prop_string_compare_string((prop_string_t)num, "666") != 0);
747 1.1 thorpej prop_object_release(s1);
748 1.1 thorpej prop_object_release(s2);
749 1.1 thorpej prop_object_release(s3);
750 1.1 thorpej prop_object_release(num);
751 1.1 thorpej }
752 1.1 thorpej
753 1.1 thorpej ATF_TC(prop_dict_util);
754 1.1 thorpej ATF_TC_HEAD(prop_dict_util, tc)
755 1.1 thorpej {
756 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_dictionary_util basics");
757 1.1 thorpej }
758 1.1 thorpej ATF_TC_BODY(prop_dict_util, tc)
759 1.1 thorpej {
760 1.1 thorpej union {
761 1.1 thorpej signed char v_schar;
762 1.1 thorpej short v_shrt;
763 1.1 thorpej int v_int;
764 1.1 thorpej long v_long;
765 1.1 thorpej long long v_llong;
766 1.1 thorpej intptr_t v_intptr;
767 1.1 thorpej int8_t v_int8;
768 1.1 thorpej int16_t v_int16;
769 1.1 thorpej int32_t v_int32;
770 1.1 thorpej int64_t v_int64;
771 1.1 thorpej
772 1.1 thorpej unsigned char v_uchar;
773 1.1 thorpej unsigned short v_ushrt;
774 1.1 thorpej unsigned int v_uint;
775 1.1 thorpej unsigned long v_ulong;
776 1.1 thorpej unsigned long long v_ullong;
777 1.1 thorpej uintptr_t v_uintptr;
778 1.1 thorpej uint8_t v_uint8;
779 1.1 thorpej uint16_t v_uint16;
780 1.1 thorpej uint32_t v_uint32;
781 1.1 thorpej uint64_t v_uint64;
782 1.1 thorpej } val;
783 1.1 thorpej prop_dictionary_t dict;
784 1.1 thorpej const char *cp;
785 1.1 thorpej const void *v;
786 1.1 thorpej size_t size;
787 1.1 thorpej
788 1.1 thorpej dict = prop_dictionary_create();
789 1.1 thorpej ATF_REQUIRE(dict != NULL);
790 1.1 thorpej
791 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_schar(dict, "schar", SCHAR_MIN));
792 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_schar(dict, "schar", &val.v_schar));
793 1.1 thorpej ATF_REQUIRE(val.v_schar == SCHAR_MIN);
794 1.1 thorpej
795 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_short(dict, "shrt", SHRT_MIN));
796 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_short(dict, "shrt", &val.v_shrt));
797 1.1 thorpej ATF_REQUIRE(val.v_shrt == SHRT_MIN);
798 1.1 thorpej
799 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int(dict, "int", INT_MIN));
800 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int(dict, "int", &val.v_int));
801 1.1 thorpej ATF_REQUIRE(val.v_int == INT_MIN);
802 1.1 thorpej
803 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_long(dict, "long", LONG_MIN));
804 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_long(dict, "long", &val.v_long));
805 1.1 thorpej ATF_REQUIRE(val.v_long == LONG_MIN);
806 1.1 thorpej
807 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_longlong(dict, "longlong", LLONG_MIN));
808 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_longlong(dict, "longlong",
809 1.1 thorpej &val.v_llong));
810 1.1 thorpej ATF_REQUIRE(val.v_llong == LLONG_MIN);
811 1.1 thorpej
812 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_intptr(dict, "intptr", INTPTR_MIN));
813 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_intptr(dict, "intptr", &val.v_intptr));
814 1.1 thorpej ATF_REQUIRE(val.v_intptr == INTPTR_MIN);
815 1.1 thorpej
816 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int8(dict, "int8", INT8_MIN));
817 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int8(dict, "int8", &val.v_int8));
818 1.1 thorpej ATF_REQUIRE(val.v_int8 == INT8_MIN);
819 1.1 thorpej
820 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int16(dict, "int16", INT16_MIN));
821 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int16(dict, "int16", &val.v_int16));
822 1.1 thorpej ATF_REQUIRE(val.v_int16 == INT16_MIN);
823 1.1 thorpej
824 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int32(dict, "int32", INT32_MIN));
825 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int32(dict, "int32", &val.v_int32));
826 1.1 thorpej ATF_REQUIRE(val.v_int32 == INT32_MIN);
827 1.1 thorpej
828 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int64(dict, "int64", INT64_MIN));
829 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int64(dict, "int64", &val.v_int64));
830 1.1 thorpej ATF_REQUIRE(val.v_int64 == INT64_MIN);
831 1.1 thorpej
832 1.1 thorpej
833 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uchar(dict, "uchar", UCHAR_MAX));
834 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uchar(dict, "uchar", &val.v_uchar));
835 1.1 thorpej ATF_REQUIRE(val.v_uchar == UCHAR_MAX);
836 1.1 thorpej
837 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ushort(dict, "ushrt", USHRT_MAX));
838 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ushort(dict, "ushrt", &val.v_ushrt));
839 1.1 thorpej ATF_REQUIRE(val.v_ushrt == USHRT_MAX);
840 1.1 thorpej
841 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint(dict, "uint", UINT_MAX));
842 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint(dict, "uint", &val.v_uint));
843 1.1 thorpej ATF_REQUIRE(val.v_uint == UINT_MAX);
844 1.1 thorpej
845 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ulong(dict, "ulong", ULONG_MAX));
846 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ulong(dict, "ulong", &val.v_ulong));
847 1.1 thorpej ATF_REQUIRE(val.v_ulong == ULONG_MAX);
848 1.1 thorpej
849 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ulonglong(dict, "ulonglong",
850 1.1 thorpej ULLONG_MAX));
851 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ulonglong(dict, "ulonglong",
852 1.1 thorpej &val.v_ullong));
853 1.1 thorpej ATF_REQUIRE(val.v_ullong == ULLONG_MAX);
854 1.1 thorpej
855 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uintptr(dict, "uintptr", UINTPTR_MAX));
856 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uintptr(dict, "uintptr",
857 1.1 thorpej &val.v_uintptr));
858 1.1 thorpej ATF_REQUIRE(val.v_uintptr == UINTPTR_MAX);
859 1.1 thorpej
860 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint8(dict, "uint8", UINT8_MAX));
861 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint8(dict, "uint8", &val.v_uint8));
862 1.1 thorpej ATF_REQUIRE(val.v_uint8 == UINT8_MAX);
863 1.1 thorpej
864 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint16(dict, "uint16", UINT16_MAX));
865 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint16(dict, "uint16", &val.v_uint16));
866 1.1 thorpej ATF_REQUIRE(val.v_uint16 == UINT16_MAX);
867 1.1 thorpej
868 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint32(dict, "uint32", UINT32_MAX));
869 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint32(dict, "uint32", &val.v_uint32));
870 1.1 thorpej ATF_REQUIRE(val.v_uint32 == UINT32_MAX);
871 1.1 thorpej
872 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint64(dict, "uint64", UINT64_MAX));
873 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint64(dict, "uint64", &val.v_uint64));
874 1.1 thorpej ATF_REQUIRE(val.v_uint64 == UINT64_MAX);
875 1.1 thorpej
876 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_string_nocopy(dict, "string",
877 1.1 thorpej const_string1));
878 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_string(dict, "string", &cp));
879 1.1 thorpej ATF_REQUIRE(cp == const_string1);
880 1.1 thorpej prop_dictionary_remove(dict, "string");
881 1.1 thorpej
882 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_string(dict, "string", const_string1));
883 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_string(dict, "string", &cp));
884 1.1 thorpej ATF_REQUIRE(cp != const_string1);
885 1.1 thorpej ATF_REQUIRE(strcmp(cp, const_string1) == 0);
886 1.1 thorpej
887 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_data_nocopy(dict, "data",
888 1.1 thorpej const_data1,
889 1.1 thorpej sizeof(const_data1)));
890 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_data(dict, "data", &v, NULL));
891 1.1 thorpej ATF_REQUIRE(v == const_data1);
892 1.1 thorpej prop_dictionary_remove(dict, "data");
893 1.1 thorpej
894 1.1 thorpej size = 0xdeadbeef;
895 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_data(dict, "data", const_data1,
896 1.1 thorpej sizeof(const_data1)));
897 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_data(dict, "data", &v, &size));
898 1.1 thorpej ATF_REQUIRE(v != const_data1);
899 1.1 thorpej ATF_REQUIRE(size == sizeof(const_data1));
900 1.1 thorpej ATF_REQUIRE(memcmp(v, const_data1, size) == 0);
901 1.1 thorpej
902 1.1 thorpej prop_object_release(dict);
903 1.1 thorpej }
904 1.1 thorpej
905 1.1 thorpej ATF_TP_ADD_TCS(tp)
906 1.1 thorpej {
907 1.1 thorpej
908 1.1 thorpej ATF_TP_ADD_TC(tp, prop_basic);
909 1.1 thorpej ATF_TP_ADD_TC(tp, prop_dictionary_equals);
910 1.1 thorpej ATF_TP_ADD_TC(tp, prop_dict_util);
911 1.1 thorpej ATF_TP_ADD_TC(tp, prop_data_basic);
912 1.1 thorpej ATF_TP_ADD_TC(tp, prop_number_basic);
913 1.1 thorpej ATF_TP_ADD_TC(tp, prop_number_range_check);
914 1.1 thorpej ATF_TP_ADD_TC(tp, prop_string_basic);
915 1.1 thorpej
916 1.1 thorpej return atf_no_error();
917 1.1 thorpej }
918