t_proplib.c revision 1.1 1 1.1 thorpej /* $NetBSD: t_proplib.c,v 1.1 2020/06/06 21:26:00 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.1 thorpej __RCSID("$NetBSD: t_proplib.c,v 1.1 2020/06/06 21:26:00 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.1 thorpej prop_number_t num = prop_number_create_integer(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.1 thorpej prop_string_t str = prop_string_create_cstring("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.1 thorpej d1 = prop_data_create_nocopy(const_data1, sizeof(const_data1));
228 1.1 thorpej ATF_REQUIRE(d1 != NULL);
229 1.1 thorpej ATF_REQUIRE(prop_data_value(d1) == const_data1);
230 1.1 thorpej d2 = prop_data_copy(d1);
231 1.1 thorpej ATF_REQUIRE(d2 != NULL);
232 1.1 thorpej ATF_REQUIRE(d2 == d1);
233 1.1 thorpej prop_object_release(d1);
234 1.1 thorpej prop_object_release(d2);
235 1.1 thorpej
236 1.1 thorpej d1 = prop_data_create_copy(const_data1, sizeof(const_data1));
237 1.1 thorpej ATF_REQUIRE(d1 != NULL);
238 1.1 thorpej ATF_REQUIRE(prop_data_value(d1) != const_data1);
239 1.1 thorpej d2 = prop_data_copy(d1);
240 1.1 thorpej ATF_REQUIRE(d2 != NULL);
241 1.1 thorpej ATF_REQUIRE(d2 == d1);
242 1.1 thorpej ATF_REQUIRE(prop_data_equals(d1, d2));
243 1.1 thorpej prop_object_release(d2);
244 1.1 thorpej
245 1.1 thorpej d2 = prop_data_create_copy(const_data2, sizeof(const_data2));
246 1.1 thorpej ATF_REQUIRE(d2 != NULL);
247 1.1 thorpej ATF_REQUIRE(prop_data_value(d2) != const_data2);
248 1.1 thorpej ATF_REQUIRE(!prop_data_equals(d1, d2));
249 1.1 thorpej
250 1.1 thorpej ATF_REQUIRE(prop_data_size(d1) == sizeof(const_data1));
251 1.1 thorpej ATF_REQUIRE(prop_data_size(d2) == sizeof(const_data2));
252 1.1 thorpej
253 1.1 thorpej ATF_REQUIRE(prop_data_copy_value(d1, buf, sizeof(buf)));
254 1.1 thorpej ATF_REQUIRE(memcmp(buf, const_data1, sizeof(buf)) == 0);
255 1.1 thorpej ATF_REQUIRE(!prop_data_copy_value(d2, buf, sizeof(buf)));
256 1.1 thorpej
257 1.1 thorpej prop_object_release(d1);
258 1.1 thorpej prop_object_release(d2);
259 1.1 thorpej }
260 1.1 thorpej
261 1.1 thorpej ATF_TC(prop_number_basic);
262 1.1 thorpej ATF_TC_HEAD(prop_number_basic, tc)
263 1.1 thorpej {
264 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_number basics");
265 1.1 thorpej }
266 1.1 thorpej ATF_TC_BODY(prop_number_basic, tc)
267 1.1 thorpej {
268 1.1 thorpej prop_number_t s1, s2, u1, u2, u3, u4;
269 1.1 thorpej
270 1.1 thorpej /*
271 1.1 thorpej * This test exercises implementation details, not only
272 1.1 thorpej * API contract.
273 1.1 thorpej */
274 1.1 thorpej
275 1.1 thorpej s1 = prop_number_create_signed(INTMAX_MAX);
276 1.1 thorpej ATF_REQUIRE(s1 != NULL);
277 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(s1) == false);
278 1.1 thorpej ATF_REQUIRE(prop_number_signed_value(s1) == INTMAX_MAX);
279 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(s1) == INTMAX_MAX);
280 1.1 thorpej ATF_REQUIRE(prop_number_equals_signed(s1, INTMAX_MAX) == true);
281 1.1 thorpej
282 1.1 thorpej s2 = prop_number_create_signed(INTMAX_MAX);
283 1.1 thorpej ATF_REQUIRE(s2 == s1);
284 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(s2) == false);
285 1.1 thorpej
286 1.1 thorpej u1 = prop_number_create_unsigned(UINTMAX_MAX);
287 1.1 thorpej ATF_REQUIRE(u1 != NULL);
288 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u1) == true);
289 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u1) == UINTMAX_MAX);
290 1.1 thorpej ATF_REQUIRE(prop_number_equals_unsigned(u1, UINTMAX_MAX) == true);
291 1.1 thorpej
292 1.1 thorpej u2 = prop_number_create_unsigned(0);
293 1.1 thorpej ATF_REQUIRE(u2 != NULL);
294 1.1 thorpej ATF_REQUIRE(u2 != u1);
295 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u2) == true);
296 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u2) == 0);
297 1.1 thorpej
298 1.1 thorpej u3 = prop_number_copy(u1);
299 1.1 thorpej ATF_REQUIRE(u3 == u1);
300 1.1 thorpej ATF_REQUIRE(prop_number_unsigned(u3) == true);
301 1.1 thorpej ATF_REQUIRE(prop_number_unsigned_value(u3) == UINTMAX_MAX);
302 1.1 thorpej
303 1.1 thorpej u4 = prop_number_create_unsigned(INTMAX_MAX);
304 1.1 thorpej ATF_REQUIRE(u4 != NULL);
305 1.1 thorpej ATF_REQUIRE(u4 != s1);
306 1.1 thorpej ATF_REQUIRE(prop_number_equals_signed(u4, INTMAX_MAX) == true);
307 1.1 thorpej ATF_REQUIRE(prop_number_equals_unsigned(u4, INTMAX_MAX) == true);
308 1.1 thorpej
309 1.1 thorpej prop_object_release(s1);
310 1.1 thorpej prop_object_release(s2);
311 1.1 thorpej
312 1.1 thorpej prop_object_release(u1);
313 1.1 thorpej prop_object_release(u2);
314 1.1 thorpej prop_object_release(u3);
315 1.1 thorpej prop_object_release(u4);
316 1.1 thorpej }
317 1.1 thorpej
318 1.1 thorpej ATF_TC(prop_number_range_check);
319 1.1 thorpej ATF_TC_HEAD(prop_number_range_check, tc)
320 1.1 thorpej {
321 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_number range checking");
322 1.1 thorpej }
323 1.1 thorpej ATF_TC_BODY(prop_number_range_check, tc)
324 1.1 thorpej {
325 1.1 thorpej union {
326 1.1 thorpej signed char v_schar;
327 1.1 thorpej short v_shrt;
328 1.1 thorpej int v_int;
329 1.1 thorpej long v_long;
330 1.1 thorpej long long v_llong;
331 1.1 thorpej intptr_t v_intptr;
332 1.1 thorpej int8_t v_int8;
333 1.1 thorpej int16_t v_int16;
334 1.1 thorpej int32_t v_int32;
335 1.1 thorpej int64_t v_int64;
336 1.1 thorpej
337 1.1 thorpej unsigned char v_uchar;
338 1.1 thorpej unsigned short v_ushrt;
339 1.1 thorpej unsigned int v_uint;
340 1.1 thorpej unsigned long v_ulong;
341 1.1 thorpej unsigned long long v_ullong;
342 1.1 thorpej uintptr_t v_uintptr;
343 1.1 thorpej uint8_t v_uint8;
344 1.1 thorpej uint16_t v_uint16;
345 1.1 thorpej uint32_t v_uint32;
346 1.1 thorpej uint64_t v_uint64;
347 1.1 thorpej } val;
348 1.1 thorpej
349 1.1 thorpej prop_number_t n_schar_max = prop_number_create_signed(SCHAR_MAX);
350 1.1 thorpej prop_number_t n_schar_min = prop_number_create_signed(SCHAR_MIN);
351 1.1 thorpej prop_number_t n_uchar_max = prop_number_create_unsigned(UCHAR_MAX);
352 1.1 thorpej ATF_REQUIRE(n_schar_max != NULL);
353 1.1 thorpej ATF_REQUIRE(n_schar_min != NULL);
354 1.1 thorpej ATF_REQUIRE(n_uchar_max != NULL);
355 1.1 thorpej
356 1.1 thorpej prop_number_t n_shrt_max = prop_number_create_signed(SHRT_MAX);
357 1.1 thorpej prop_number_t n_shrt_min = prop_number_create_signed(SHRT_MIN);
358 1.1 thorpej prop_number_t n_ushrt_max = prop_number_create_unsigned(USHRT_MAX);
359 1.1 thorpej ATF_REQUIRE(n_shrt_max != NULL);
360 1.1 thorpej ATF_REQUIRE(n_shrt_min != NULL);
361 1.1 thorpej ATF_REQUIRE(n_ushrt_max != NULL);
362 1.1 thorpej
363 1.1 thorpej prop_number_t n_int_max = prop_number_create_signed(INT_MAX);
364 1.1 thorpej prop_number_t n_int_min = prop_number_create_signed(INT_MIN);
365 1.1 thorpej prop_number_t n_uint_max = prop_number_create_unsigned(UINT_MAX);
366 1.1 thorpej ATF_REQUIRE(n_int_max != NULL);
367 1.1 thorpej ATF_REQUIRE(n_int_min != NULL);
368 1.1 thorpej ATF_REQUIRE(n_uint_max != NULL);
369 1.1 thorpej
370 1.1 thorpej prop_number_t n_long_max = prop_number_create_signed(LONG_MAX);
371 1.1 thorpej prop_number_t n_long_min = prop_number_create_signed(LONG_MIN);
372 1.1 thorpej prop_number_t n_ulong_max = prop_number_create_unsigned(ULONG_MAX);
373 1.1 thorpej ATF_REQUIRE(n_long_max != NULL);
374 1.1 thorpej ATF_REQUIRE(n_long_min != NULL);
375 1.1 thorpej ATF_REQUIRE(n_ulong_max != NULL);
376 1.1 thorpej
377 1.1 thorpej prop_number_t n_llong_max = prop_number_create_signed(LLONG_MAX);
378 1.1 thorpej prop_number_t n_llong_min = prop_number_create_signed(LLONG_MIN);
379 1.1 thorpej prop_number_t n_ullong_max = prop_number_create_unsigned(ULLONG_MAX);
380 1.1 thorpej ATF_REQUIRE(n_llong_max != NULL);
381 1.1 thorpej ATF_REQUIRE(n_llong_min != NULL);
382 1.1 thorpej ATF_REQUIRE(n_ullong_max != NULL);
383 1.1 thorpej
384 1.1 thorpej prop_number_t n_intptr_max = prop_number_create_signed(INTPTR_MAX);
385 1.1 thorpej prop_number_t n_intptr_min = prop_number_create_signed(INTPTR_MIN);
386 1.1 thorpej prop_number_t n_uintptr_max = prop_number_create_unsigned(UINTPTR_MAX);
387 1.1 thorpej ATF_REQUIRE(n_intptr_max != NULL);
388 1.1 thorpej ATF_REQUIRE(n_intptr_min != NULL);
389 1.1 thorpej ATF_REQUIRE(n_uintptr_max != NULL);
390 1.1 thorpej
391 1.1 thorpej prop_number_t n_int8_max = prop_number_create_signed(INT8_MAX);
392 1.1 thorpej prop_number_t n_int8_min = prop_number_create_signed(INT8_MIN);
393 1.1 thorpej prop_number_t n_uint8_max = prop_number_create_unsigned(UINT8_MAX);
394 1.1 thorpej ATF_REQUIRE(n_int8_max != NULL);
395 1.1 thorpej ATF_REQUIRE(n_int8_min != NULL);
396 1.1 thorpej ATF_REQUIRE(n_uint8_max != NULL);
397 1.1 thorpej
398 1.1 thorpej prop_number_t n_int16_max = prop_number_create_signed(INT16_MAX);
399 1.1 thorpej prop_number_t n_int16_min = prop_number_create_signed(INT16_MIN);
400 1.1 thorpej prop_number_t n_uint16_max = prop_number_create_unsigned(UINT16_MAX);
401 1.1 thorpej ATF_REQUIRE(n_int16_max != NULL);
402 1.1 thorpej ATF_REQUIRE(n_int16_min != NULL);
403 1.1 thorpej ATF_REQUIRE(n_uint16_max != NULL);
404 1.1 thorpej
405 1.1 thorpej prop_number_t n_int32_max = prop_number_create_signed(INT32_MAX);
406 1.1 thorpej prop_number_t n_int32_min = prop_number_create_signed(INT32_MIN);
407 1.1 thorpej prop_number_t n_uint32_max = prop_number_create_unsigned(UINT32_MAX);
408 1.1 thorpej ATF_REQUIRE(n_int32_max != NULL);
409 1.1 thorpej ATF_REQUIRE(n_int32_min != NULL);
410 1.1 thorpej ATF_REQUIRE(n_uint32_max != NULL);
411 1.1 thorpej
412 1.1 thorpej prop_number_t n_int64_max = prop_number_create_signed(INT64_MAX);
413 1.1 thorpej prop_number_t n_int64_min = prop_number_create_signed(INT64_MIN);
414 1.1 thorpej prop_number_t n_uint64_max = prop_number_create_unsigned(UINT64_MAX);
415 1.1 thorpej ATF_REQUIRE(n_int64_max != NULL);
416 1.1 thorpej ATF_REQUIRE(n_int64_min != NULL);
417 1.1 thorpej ATF_REQUIRE(n_uint64_max != NULL);
418 1.1 thorpej
419 1.1 thorpej /* signed / unsigned char */
420 1.1 thorpej ATF_REQUIRE(prop_number_schar_value(n_schar_max, &val.v_schar) &&
421 1.1 thorpej val.v_schar == SCHAR_MAX);
422 1.1 thorpej ATF_REQUIRE(prop_number_schar_value(n_schar_min, &val.v_schar) &&
423 1.1 thorpej val.v_schar == SCHAR_MIN);
424 1.1 thorpej ATF_REQUIRE(!prop_number_schar_value(n_uchar_max, &val.v_schar));
425 1.1 thorpej
426 1.1 thorpej ATF_REQUIRE(prop_number_uchar_value(n_schar_max, &val.v_uchar) &&
427 1.1 thorpej val.v_uchar == SCHAR_MAX);
428 1.1 thorpej ATF_REQUIRE(!prop_number_uchar_value(n_schar_min, &val.v_uchar));
429 1.1 thorpej ATF_REQUIRE(prop_number_uchar_value(n_uchar_max, &val.v_uchar) &&
430 1.1 thorpej val.v_uchar == UCHAR_MAX);
431 1.1 thorpej
432 1.1 thorpej ATF_REQUIRE(!prop_number_schar_value(n_shrt_min, &val.v_schar));
433 1.1 thorpej ATF_REQUIRE(!prop_number_uchar_value(n_shrt_max, &val.v_uchar));
434 1.1 thorpej
435 1.1 thorpej /* short / unsigned short */
436 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_uchar_max, &val.v_shrt) &&
437 1.1 thorpej val.v_shrt == UCHAR_MAX);
438 1.1 thorpej
439 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_shrt_max, &val.v_shrt) &&
440 1.1 thorpej val.v_shrt == SHRT_MAX);
441 1.1 thorpej ATF_REQUIRE(prop_number_short_value(n_shrt_min, &val.v_shrt) &&
442 1.1 thorpej val.v_shrt == SHRT_MIN);
443 1.1 thorpej ATF_REQUIRE(!prop_number_short_value(n_ushrt_max, &val.v_shrt));
444 1.1 thorpej
445 1.1 thorpej ATF_REQUIRE(prop_number_ushort_value(n_shrt_max, &val.v_ushrt) &&
446 1.1 thorpej val.v_ushrt == SHRT_MAX);
447 1.1 thorpej ATF_REQUIRE(!prop_number_ushort_value(n_shrt_min, &val.v_ushrt));
448 1.1 thorpej ATF_REQUIRE(prop_number_ushort_value(n_ushrt_max, &val.v_ushrt) &&
449 1.1 thorpej val.v_ushrt == USHRT_MAX);
450 1.1 thorpej
451 1.1 thorpej ATF_REQUIRE(!prop_number_short_value(n_int_min, &val.v_shrt));
452 1.1 thorpej ATF_REQUIRE(!prop_number_ushort_value(n_int_max, &val.v_ushrt));
453 1.1 thorpej
454 1.1 thorpej /* int / unsigned int */
455 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_ushrt_max, &val.v_int) &&
456 1.1 thorpej val.v_int == USHRT_MAX);
457 1.1 thorpej
458 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_int_max, &val.v_int) &&
459 1.1 thorpej val.v_int == INT_MAX);
460 1.1 thorpej ATF_REQUIRE(prop_number_int_value(n_int_min, &val.v_int) &&
461 1.1 thorpej val.v_int == INT_MIN);
462 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_uint_max, &val.v_int));
463 1.1 thorpej
464 1.1 thorpej ATF_REQUIRE(prop_number_uint_value(n_int_max, &val.v_uint) &&
465 1.1 thorpej val.v_uint == INT_MAX);
466 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_int_min, &val.v_uint));
467 1.1 thorpej ATF_REQUIRE(prop_number_uint_value(n_uint_max, &val.v_uint) &&
468 1.1 thorpej val.v_uint == UINT_MAX);
469 1.1 thorpej
470 1.1 thorpej #ifdef _LP64
471 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_long_min, &val.v_int));
472 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_long_max, &val.v_uint));
473 1.1 thorpej #else
474 1.1 thorpej ATF_REQUIRE(!prop_number_int_value(n_llong_min, &val.v_int));
475 1.1 thorpej ATF_REQUIRE(!prop_number_uint_value(n_llong_max, &val.v_uint));
476 1.1 thorpej #endif /* _LP64 */
477 1.1 thorpej
478 1.1 thorpej /* long / unsigned long */
479 1.1 thorpej #ifdef _LP64
480 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_uint_max, &val.v_long) &&
481 1.1 thorpej val.v_long == UINT_MAX);
482 1.1 thorpej #endif
483 1.1 thorpej
484 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_long_max, &val.v_long) &&
485 1.1 thorpej val.v_long == LONG_MAX);
486 1.1 thorpej ATF_REQUIRE(prop_number_long_value(n_long_min, &val.v_long) &&
487 1.1 thorpej val.v_long == LONG_MIN);
488 1.1 thorpej ATF_REQUIRE(!prop_number_long_value(n_ulong_max, &val.v_long));
489 1.1 thorpej
490 1.1 thorpej ATF_REQUIRE(prop_number_ulong_value(n_long_max, &val.v_ulong) &&
491 1.1 thorpej val.v_ulong == LONG_MAX);
492 1.1 thorpej ATF_REQUIRE(!prop_number_ulong_value(n_long_min, &val.v_ulong));
493 1.1 thorpej ATF_REQUIRE(prop_number_ulong_value(n_ulong_max, &val.v_ulong) &&
494 1.1 thorpej val.v_ulong == ULONG_MAX);
495 1.1 thorpej
496 1.1 thorpej #ifndef _LP64
497 1.1 thorpej ATF_REQUIRE(!prop_number_long_value(n_llong_min, &val.v_long));
498 1.1 thorpej ATF_REQUIRE(!prop_number_ulong_value(n_llong_max, &val.v_ulong));
499 1.1 thorpej #endif
500 1.1 thorpej
501 1.1 thorpej /* intptr_t / uintptr_t */
502 1.1 thorpej #ifdef _LP64
503 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_uint_max, &val.v_intptr) &&
504 1.1 thorpej val.v_intptr == UINT_MAX);
505 1.1 thorpej #endif
506 1.1 thorpej
507 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_intptr_max, &val.v_intptr) &&
508 1.1 thorpej val.v_intptr == INTPTR_MAX);
509 1.1 thorpej ATF_REQUIRE(prop_number_intptr_value(n_intptr_min, &val.v_intptr) &&
510 1.1 thorpej val.v_intptr == INTPTR_MIN);
511 1.1 thorpej ATF_REQUIRE(!prop_number_intptr_value(n_uintptr_max, &val.v_intptr));
512 1.1 thorpej
513 1.1 thorpej ATF_REQUIRE(prop_number_uintptr_value(n_intptr_max, &val.v_uintptr) &&
514 1.1 thorpej val.v_uintptr == INTPTR_MAX);
515 1.1 thorpej ATF_REQUIRE(!prop_number_uintptr_value(n_intptr_min, &val.v_uintptr));
516 1.1 thorpej ATF_REQUIRE(prop_number_uintptr_value(n_uintptr_max, &val.v_uintptr) &&
517 1.1 thorpej val.v_uintptr == UINTPTR_MAX);
518 1.1 thorpej
519 1.1 thorpej #ifndef _LP64
520 1.1 thorpej ATF_REQUIRE(!prop_number_intptr_value(n_llong_min, &val.v_intptr));
521 1.1 thorpej ATF_REQUIRE(!prop_number_uintptr_value(n_llong_max, &val.v_uintptr));
522 1.1 thorpej #endif
523 1.1 thorpej
524 1.1 thorpej /* long long / unsigned long long */
525 1.1 thorpej #ifdef _LP64
526 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_uint_max, &val.v_llong) &&
527 1.1 thorpej val.v_llong == UINT_MAX);
528 1.1 thorpej #else
529 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_ulong_max, &val.v_llong) &&
530 1.1 thorpej val.v_llong == ULONG_MAX);
531 1.1 thorpej #endif
532 1.1 thorpej
533 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_llong_max, &val.v_llong) &&
534 1.1 thorpej val.v_llong == INTPTR_MAX);
535 1.1 thorpej ATF_REQUIRE(prop_number_longlong_value(n_llong_min, &val.v_llong) &&
536 1.1 thorpej val.v_llong == INTPTR_MIN);
537 1.1 thorpej ATF_REQUIRE(!prop_number_longlong_value(n_ullong_max, &val.v_llong));
538 1.1 thorpej
539 1.1 thorpej ATF_REQUIRE(prop_number_ulonglong_value(n_llong_max, &val.v_ullong) &&
540 1.1 thorpej val.v_ullong == INTPTR_MAX);
541 1.1 thorpej ATF_REQUIRE(!prop_number_ulonglong_value(n_llong_min, &val.v_ullong));
542 1.1 thorpej ATF_REQUIRE(prop_number_ulonglong_value(n_ullong_max, &val.v_ullong) &&
543 1.1 thorpej val.v_ullong == UINTPTR_MAX);
544 1.1 thorpej
545 1.1 thorpej /* int8_t / uint8_t */
546 1.1 thorpej ATF_REQUIRE(prop_number_int8_value(n_int8_max, &val.v_int8) &&
547 1.1 thorpej val.v_int8 == INT8_MAX);
548 1.1 thorpej ATF_REQUIRE(prop_number_int8_value(n_int8_min, &val.v_int8) &&
549 1.1 thorpej val.v_int8 == INT8_MIN);
550 1.1 thorpej ATF_REQUIRE(!prop_number_int8_value(n_uint8_max, &val.v_int8));
551 1.1 thorpej
552 1.1 thorpej ATF_REQUIRE(prop_number_uint8_value(n_int8_max, &val.v_uint8) &&
553 1.1 thorpej val.v_uint8 == INT8_MAX);
554 1.1 thorpej ATF_REQUIRE(!prop_number_uint8_value(n_int8_min, &val.v_uint8));
555 1.1 thorpej ATF_REQUIRE(prop_number_uint8_value(n_uint8_max, &val.v_uint8) &&
556 1.1 thorpej val.v_uint8 == UINT8_MAX);
557 1.1 thorpej
558 1.1 thorpej ATF_REQUIRE(!prop_number_int8_value(n_int16_min, &val.v_int8));
559 1.1 thorpej ATF_REQUIRE(!prop_number_uint8_value(n_int16_max, &val.v_uint8));
560 1.1 thorpej
561 1.1 thorpej /* int16_t / uint16_t */
562 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_uint8_max, &val.v_int16) &&
563 1.1 thorpej val.v_int16 == UINT8_MAX);
564 1.1 thorpej
565 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_int16_max, &val.v_int16) &&
566 1.1 thorpej val.v_int16 == INT16_MAX);
567 1.1 thorpej ATF_REQUIRE(prop_number_int16_value(n_int16_min, &val.v_int16) &&
568 1.1 thorpej val.v_int16 == INT16_MIN);
569 1.1 thorpej ATF_REQUIRE(!prop_number_int16_value(n_uint16_max, &val.v_int16));
570 1.1 thorpej
571 1.1 thorpej ATF_REQUIRE(prop_number_uint16_value(n_int16_max, &val.v_uint16) &&
572 1.1 thorpej val.v_uint16 == INT16_MAX);
573 1.1 thorpej ATF_REQUIRE(!prop_number_uint16_value(n_int16_min, &val.v_uint16));
574 1.1 thorpej ATF_REQUIRE(prop_number_uint16_value(n_uint16_max, &val.v_uint16) &&
575 1.1 thorpej val.v_uint16 == UINT16_MAX);
576 1.1 thorpej
577 1.1 thorpej ATF_REQUIRE(!prop_number_int16_value(n_int32_min, &val.v_int16));
578 1.1 thorpej ATF_REQUIRE(!prop_number_uint16_value(n_int32_max, &val.v_uint16));
579 1.1 thorpej
580 1.1 thorpej /* int32_t / uint32_t */
581 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_uint16_max, &val.v_int32) &&
582 1.1 thorpej val.v_int32 == UINT16_MAX);
583 1.1 thorpej
584 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_int32_max, &val.v_int32) &&
585 1.1 thorpej val.v_int32 == INT32_MAX);
586 1.1 thorpej ATF_REQUIRE(prop_number_int32_value(n_int32_min, &val.v_int32) &&
587 1.1 thorpej val.v_int32 == INT32_MIN);
588 1.1 thorpej ATF_REQUIRE(!prop_number_int32_value(n_uint32_max, &val.v_int32));
589 1.1 thorpej
590 1.1 thorpej ATF_REQUIRE(prop_number_uint32_value(n_int32_max, &val.v_uint32) &&
591 1.1 thorpej val.v_uint32 == INT32_MAX);
592 1.1 thorpej ATF_REQUIRE(!prop_number_uint32_value(n_int32_min, &val.v_uint32));
593 1.1 thorpej ATF_REQUIRE(prop_number_uint32_value(n_uint32_max, &val.v_uint32) &&
594 1.1 thorpej val.v_uint32 == UINT32_MAX);
595 1.1 thorpej
596 1.1 thorpej ATF_REQUIRE(!prop_number_int32_value(n_int64_min, &val.v_int32));
597 1.1 thorpej ATF_REQUIRE(!prop_number_uint32_value(n_int64_max, &val.v_uint32));
598 1.1 thorpej
599 1.1 thorpej /* int64_t / uint64_t */
600 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_uint32_max, &val.v_int64) &&
601 1.1 thorpej val.v_int64 == UINT32_MAX);
602 1.1 thorpej
603 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_int64_max, &val.v_int64) &&
604 1.1 thorpej val.v_int64 == INT64_MAX);
605 1.1 thorpej ATF_REQUIRE(prop_number_int64_value(n_int64_min, &val.v_int64) &&
606 1.1 thorpej val.v_int64 == INT64_MIN);
607 1.1 thorpej ATF_REQUIRE(!prop_number_int64_value(n_uint64_max, &val.v_int64));
608 1.1 thorpej
609 1.1 thorpej ATF_REQUIRE(prop_number_uint64_value(n_int64_max, &val.v_uint64) &&
610 1.1 thorpej val.v_uint64 == INT64_MAX);
611 1.1 thorpej ATF_REQUIRE(!prop_number_uint64_value(n_int64_min, &val.v_uint64));
612 1.1 thorpej ATF_REQUIRE(prop_number_uint64_value(n_uint64_max, &val.v_uint64) &&
613 1.1 thorpej val.v_uint64 == UINT64_MAX);
614 1.1 thorpej
615 1.1 thorpej prop_object_release(n_schar_max);
616 1.1 thorpej prop_object_release(n_schar_min);
617 1.1 thorpej prop_object_release(n_uchar_max);
618 1.1 thorpej
619 1.1 thorpej prop_object_release(n_shrt_max);
620 1.1 thorpej prop_object_release(n_shrt_min);
621 1.1 thorpej prop_object_release(n_ushrt_max);
622 1.1 thorpej
623 1.1 thorpej prop_object_release(n_int_max);
624 1.1 thorpej prop_object_release(n_int_min);
625 1.1 thorpej prop_object_release(n_uint_max);
626 1.1 thorpej
627 1.1 thorpej prop_object_release(n_long_max);
628 1.1 thorpej prop_object_release(n_long_min);
629 1.1 thorpej prop_object_release(n_ulong_max);
630 1.1 thorpej
631 1.1 thorpej prop_object_release(n_llong_max);
632 1.1 thorpej prop_object_release(n_llong_min);
633 1.1 thorpej prop_object_release(n_ullong_max);
634 1.1 thorpej
635 1.1 thorpej prop_object_release(n_intptr_max);
636 1.1 thorpej prop_object_release(n_intptr_min);
637 1.1 thorpej prop_object_release(n_uintptr_max);
638 1.1 thorpej
639 1.1 thorpej prop_object_release(n_int8_max);
640 1.1 thorpej prop_object_release(n_int8_min);
641 1.1 thorpej prop_object_release(n_uint8_max);
642 1.1 thorpej
643 1.1 thorpej prop_object_release(n_int16_max);
644 1.1 thorpej prop_object_release(n_int16_min);
645 1.1 thorpej prop_object_release(n_uint16_max);
646 1.1 thorpej
647 1.1 thorpej prop_object_release(n_int32_max);
648 1.1 thorpej prop_object_release(n_int32_min);
649 1.1 thorpej prop_object_release(n_uint32_max);
650 1.1 thorpej
651 1.1 thorpej prop_object_release(n_int64_max);
652 1.1 thorpej prop_object_release(n_int64_min);
653 1.1 thorpej prop_object_release(n_uint64_max);
654 1.1 thorpej }
655 1.1 thorpej
656 1.1 thorpej ATF_TC(prop_string_basic);
657 1.1 thorpej ATF_TC_HEAD(prop_string_basic, tc)
658 1.1 thorpej {
659 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_string basics");
660 1.1 thorpej }
661 1.1 thorpej ATF_TC_BODY(prop_string_basic, tc)
662 1.1 thorpej {
663 1.1 thorpej prop_string_t s1, s2, s3;
664 1.1 thorpej prop_number_t num;
665 1.1 thorpej char buf[sizeof(const_string1)];
666 1.1 thorpej
667 1.1 thorpej /*
668 1.1 thorpej * This test exercises implementation details, not only
669 1.1 thorpej * API contract.
670 1.1 thorpej */
671 1.1 thorpej
672 1.1 thorpej s1 = prop_string_create_nocopy(const_string1);
673 1.1 thorpej ATF_REQUIRE(s1 != NULL);
674 1.1 thorpej s2 = prop_string_create_copy(const_string1);
675 1.1 thorpej ATF_REQUIRE(s2 != NULL);
676 1.1 thorpej ATF_REQUIRE(s2 == s1);
677 1.1 thorpej ATF_REQUIRE(prop_string_value(s1) == const_string1);
678 1.1 thorpej prop_object_release(s1);
679 1.1 thorpej prop_object_release(s2);
680 1.1 thorpej
681 1.1 thorpej s1 = prop_string_create_copy(const_string1);
682 1.1 thorpej ATF_REQUIRE(s1 != NULL);
683 1.1 thorpej s2 = prop_string_create_nocopy(const_string1);
684 1.1 thorpej ATF_REQUIRE(s2 != NULL);
685 1.1 thorpej ATF_REQUIRE(s2 == s1);
686 1.1 thorpej ATF_REQUIRE(prop_string_value(s1) != const_string1);
687 1.1 thorpej prop_object_release(s1);
688 1.1 thorpej prop_object_release(s2);
689 1.1 thorpej
690 1.1 thorpej s1 = prop_string_create_format("%d-%d", 12345, 67890);
691 1.1 thorpej ATF_REQUIRE(s1 != NULL);
692 1.1 thorpej ATF_REQUIRE(strcmp(prop_string_value(s1), "12345-67890") == 0);
693 1.1 thorpej ATF_REQUIRE(prop_string_equals_string(s1, "12345-67890"));
694 1.1 thorpej prop_object_release(s1);
695 1.1 thorpej
696 1.1 thorpej s1 = prop_string_create_nocopy(const_string1);
697 1.1 thorpej ATF_REQUIRE(s1 != NULL);
698 1.1 thorpej s2 = prop_string_create_nocopy(const_string2);
699 1.1 thorpej ATF_REQUIRE(s2 != NULL);
700 1.1 thorpej ATF_REQUIRE(prop_string_size(s1) == strlen(const_string1));
701 1.1 thorpej ATF_REQUIRE(prop_string_size(s2) == strlen(const_string2));
702 1.1 thorpej ATF_REQUIRE(prop_string_copy_value(s1, buf, sizeof(buf)));
703 1.1 thorpej ATF_REQUIRE(!prop_string_copy_value(s2, buf, sizeof(buf)));
704 1.1 thorpej prop_object_release(s1);
705 1.1 thorpej prop_object_release(s2);
706 1.1 thorpej
707 1.1 thorpej s1 = prop_string_create_copy("a");
708 1.1 thorpej ATF_REQUIRE(s1 != NULL);
709 1.1 thorpej s2 = prop_string_create_copy("b");
710 1.1 thorpej ATF_REQUIRE(s2 != NULL);
711 1.1 thorpej s3 = prop_string_copy(s2);
712 1.1 thorpej ATF_REQUIRE(s3 != NULL);
713 1.1 thorpej ATF_REQUIRE(s3 == s2);
714 1.1 thorpej num = prop_number_create_signed(666);
715 1.1 thorpej ATF_REQUIRE(num != NULL);
716 1.1 thorpej ATF_REQUIRE(!prop_string_equals(s1, s2));
717 1.1 thorpej ATF_REQUIRE(prop_string_equals(s2, s3));
718 1.1 thorpej ATF_REQUIRE(prop_string_compare(s1, s2) < 0);
719 1.1 thorpej ATF_REQUIRE(prop_string_compare(s2, s1) > 0);
720 1.1 thorpej ATF_REQUIRE(prop_string_compare(s2, s3) == 0);
721 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s1, "b") < 0);
722 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s2, "a") > 0);
723 1.1 thorpej ATF_REQUIRE(prop_string_compare_string(s3, "b") == 0);
724 1.1 thorpej ATF_REQUIRE(prop_string_compare(s1, (prop_string_t)num) != 0);
725 1.1 thorpej ATF_REQUIRE(prop_string_compare((prop_string_t)num, s1) != 0);
726 1.1 thorpej ATF_REQUIRE(prop_string_compare_string((prop_string_t)num, "666") != 0);
727 1.1 thorpej prop_object_release(s1);
728 1.1 thorpej prop_object_release(s2);
729 1.1 thorpej prop_object_release(s3);
730 1.1 thorpej prop_object_release(num);
731 1.1 thorpej }
732 1.1 thorpej
733 1.1 thorpej ATF_TC(prop_dict_util);
734 1.1 thorpej ATF_TC_HEAD(prop_dict_util, tc)
735 1.1 thorpej {
736 1.1 thorpej atf_tc_set_md_var(tc, "descr", "tests prop_dictionary_util basics");
737 1.1 thorpej }
738 1.1 thorpej ATF_TC_BODY(prop_dict_util, tc)
739 1.1 thorpej {
740 1.1 thorpej union {
741 1.1 thorpej signed char v_schar;
742 1.1 thorpej short v_shrt;
743 1.1 thorpej int v_int;
744 1.1 thorpej long v_long;
745 1.1 thorpej long long v_llong;
746 1.1 thorpej intptr_t v_intptr;
747 1.1 thorpej int8_t v_int8;
748 1.1 thorpej int16_t v_int16;
749 1.1 thorpej int32_t v_int32;
750 1.1 thorpej int64_t v_int64;
751 1.1 thorpej
752 1.1 thorpej unsigned char v_uchar;
753 1.1 thorpej unsigned short v_ushrt;
754 1.1 thorpej unsigned int v_uint;
755 1.1 thorpej unsigned long v_ulong;
756 1.1 thorpej unsigned long long v_ullong;
757 1.1 thorpej uintptr_t v_uintptr;
758 1.1 thorpej uint8_t v_uint8;
759 1.1 thorpej uint16_t v_uint16;
760 1.1 thorpej uint32_t v_uint32;
761 1.1 thorpej uint64_t v_uint64;
762 1.1 thorpej } val;
763 1.1 thorpej prop_dictionary_t dict;
764 1.1 thorpej const char *cp;
765 1.1 thorpej const void *v;
766 1.1 thorpej size_t size;
767 1.1 thorpej
768 1.1 thorpej dict = prop_dictionary_create();
769 1.1 thorpej ATF_REQUIRE(dict != NULL);
770 1.1 thorpej
771 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_schar(dict, "schar", SCHAR_MIN));
772 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_schar(dict, "schar", &val.v_schar));
773 1.1 thorpej ATF_REQUIRE(val.v_schar == SCHAR_MIN);
774 1.1 thorpej
775 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_short(dict, "shrt", SHRT_MIN));
776 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_short(dict, "shrt", &val.v_shrt));
777 1.1 thorpej ATF_REQUIRE(val.v_shrt == SHRT_MIN);
778 1.1 thorpej
779 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int(dict, "int", INT_MIN));
780 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int(dict, "int", &val.v_int));
781 1.1 thorpej ATF_REQUIRE(val.v_int == INT_MIN);
782 1.1 thorpej
783 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_long(dict, "long", LONG_MIN));
784 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_long(dict, "long", &val.v_long));
785 1.1 thorpej ATF_REQUIRE(val.v_long == LONG_MIN);
786 1.1 thorpej
787 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_longlong(dict, "longlong", LLONG_MIN));
788 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_longlong(dict, "longlong",
789 1.1 thorpej &val.v_llong));
790 1.1 thorpej ATF_REQUIRE(val.v_llong == LLONG_MIN);
791 1.1 thorpej
792 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_intptr(dict, "intptr", INTPTR_MIN));
793 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_intptr(dict, "intptr", &val.v_intptr));
794 1.1 thorpej ATF_REQUIRE(val.v_intptr == INTPTR_MIN);
795 1.1 thorpej
796 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int8(dict, "int8", INT8_MIN));
797 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int8(dict, "int8", &val.v_int8));
798 1.1 thorpej ATF_REQUIRE(val.v_int8 == INT8_MIN);
799 1.1 thorpej
800 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int16(dict, "int16", INT16_MIN));
801 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int16(dict, "int16", &val.v_int16));
802 1.1 thorpej ATF_REQUIRE(val.v_int16 == INT16_MIN);
803 1.1 thorpej
804 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int32(dict, "int32", INT32_MIN));
805 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int32(dict, "int32", &val.v_int32));
806 1.1 thorpej ATF_REQUIRE(val.v_int32 == INT32_MIN);
807 1.1 thorpej
808 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_int64(dict, "int64", INT64_MIN));
809 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_int64(dict, "int64", &val.v_int64));
810 1.1 thorpej ATF_REQUIRE(val.v_int64 == INT64_MIN);
811 1.1 thorpej
812 1.1 thorpej
813 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uchar(dict, "uchar", UCHAR_MAX));
814 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uchar(dict, "uchar", &val.v_uchar));
815 1.1 thorpej ATF_REQUIRE(val.v_uchar == UCHAR_MAX);
816 1.1 thorpej
817 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ushort(dict, "ushrt", USHRT_MAX));
818 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ushort(dict, "ushrt", &val.v_ushrt));
819 1.1 thorpej ATF_REQUIRE(val.v_ushrt == USHRT_MAX);
820 1.1 thorpej
821 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint(dict, "uint", UINT_MAX));
822 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint(dict, "uint", &val.v_uint));
823 1.1 thorpej ATF_REQUIRE(val.v_uint == UINT_MAX);
824 1.1 thorpej
825 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ulong(dict, "ulong", ULONG_MAX));
826 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ulong(dict, "ulong", &val.v_ulong));
827 1.1 thorpej ATF_REQUIRE(val.v_ulong == ULONG_MAX);
828 1.1 thorpej
829 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_ulonglong(dict, "ulonglong",
830 1.1 thorpej ULLONG_MAX));
831 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_ulonglong(dict, "ulonglong",
832 1.1 thorpej &val.v_ullong));
833 1.1 thorpej ATF_REQUIRE(val.v_ullong == ULLONG_MAX);
834 1.1 thorpej
835 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uintptr(dict, "uintptr", UINTPTR_MAX));
836 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uintptr(dict, "uintptr",
837 1.1 thorpej &val.v_uintptr));
838 1.1 thorpej ATF_REQUIRE(val.v_uintptr == UINTPTR_MAX);
839 1.1 thorpej
840 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint8(dict, "uint8", UINT8_MAX));
841 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint8(dict, "uint8", &val.v_uint8));
842 1.1 thorpej ATF_REQUIRE(val.v_uint8 == UINT8_MAX);
843 1.1 thorpej
844 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint16(dict, "uint16", UINT16_MAX));
845 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint16(dict, "uint16", &val.v_uint16));
846 1.1 thorpej ATF_REQUIRE(val.v_uint16 == UINT16_MAX);
847 1.1 thorpej
848 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint32(dict, "uint32", UINT32_MAX));
849 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint32(dict, "uint32", &val.v_uint32));
850 1.1 thorpej ATF_REQUIRE(val.v_uint32 == UINT32_MAX);
851 1.1 thorpej
852 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_uint64(dict, "uint64", UINT64_MAX));
853 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_uint64(dict, "uint64", &val.v_uint64));
854 1.1 thorpej ATF_REQUIRE(val.v_uint64 == UINT64_MAX);
855 1.1 thorpej
856 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_string_nocopy(dict, "string",
857 1.1 thorpej const_string1));
858 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_string(dict, "string", &cp));
859 1.1 thorpej ATF_REQUIRE(cp == const_string1);
860 1.1 thorpej prop_dictionary_remove(dict, "string");
861 1.1 thorpej
862 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_string(dict, "string", const_string1));
863 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_string(dict, "string", &cp));
864 1.1 thorpej ATF_REQUIRE(cp != const_string1);
865 1.1 thorpej ATF_REQUIRE(strcmp(cp, const_string1) == 0);
866 1.1 thorpej
867 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_data_nocopy(dict, "data",
868 1.1 thorpej const_data1,
869 1.1 thorpej sizeof(const_data1)));
870 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_data(dict, "data", &v, NULL));
871 1.1 thorpej ATF_REQUIRE(v == const_data1);
872 1.1 thorpej prop_dictionary_remove(dict, "data");
873 1.1 thorpej
874 1.1 thorpej size = 0xdeadbeef;
875 1.1 thorpej ATF_REQUIRE(prop_dictionary_set_data(dict, "data", const_data1,
876 1.1 thorpej sizeof(const_data1)));
877 1.1 thorpej ATF_REQUIRE(prop_dictionary_get_data(dict, "data", &v, &size));
878 1.1 thorpej ATF_REQUIRE(v != const_data1);
879 1.1 thorpej ATF_REQUIRE(size == sizeof(const_data1));
880 1.1 thorpej ATF_REQUIRE(memcmp(v, const_data1, size) == 0);
881 1.1 thorpej
882 1.1 thorpej prop_object_release(dict);
883 1.1 thorpej }
884 1.1 thorpej
885 1.1 thorpej ATF_TP_ADD_TCS(tp)
886 1.1 thorpej {
887 1.1 thorpej
888 1.1 thorpej ATF_TP_ADD_TC(tp, prop_basic);
889 1.1 thorpej ATF_TP_ADD_TC(tp, prop_dictionary_equals);
890 1.1 thorpej ATF_TP_ADD_TC(tp, prop_dict_util);
891 1.1 thorpej ATF_TP_ADD_TC(tp, prop_data_basic);
892 1.1 thorpej ATF_TP_ADD_TC(tp, prop_number_basic);
893 1.1 thorpej ATF_TP_ADD_TC(tp, prop_number_range_check);
894 1.1 thorpej ATF_TP_ADD_TC(tp, prop_string_basic);
895 1.1 thorpej
896 1.1 thorpej return atf_no_error();
897 1.1 thorpej }
898