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