etc/protocols - sync with NetBSD-8
[minix.git] / tests / lib / libprop / t_basic.c
blobfebf29db90098f4618b9f327a0ce25e274dd7133
1 /* $NetBSD: t_basic.c,v 1.4 2011/04/20 20:02:58 martin Exp $ */
3 /*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Written by Jason Thorpe 5/26/2006.
31 * Public domain.
34 #include <sys/cdefs.h>
35 __COPYRIGHT("@(#) Copyright (c) 2008\
36 The NetBSD Foundation, inc. All rights reserved.");
37 __RCSID("$NetBSD: t_basic.c,v 1.4 2011/04/20 20:02:58 martin Exp $");
39 #include <stdlib.h>
40 #include <string.h>
41 #include <prop/proplib.h>
43 #include <atf-c.h>
45 static const char compare1[] =
46 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
47 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
48 "<plist version=\"1.0\">\n"
49 "<dict>\n"
50 " <key>false-val</key>\n"
51 " <false/>\n"
52 " <key>one</key>\n"
53 " <integer>1</integer>\n"
54 " <key>three</key>\n"
55 " <array>\n"
56 " <dict>\n"
57 " <key>one</key>\n"
58 " <integer>1</integer>\n"
59 " <key>two</key>\n"
60 " <string>number-two</string>\n"
61 " </dict>\n"
62 " <dict>\n"
63 " <key>one</key>\n"
64 " <integer>1</integer>\n"
65 " <key>two</key>\n"
66 " <string>number-two</string>\n"
67 " </dict>\n"
68 " <dict>\n"
69 " <key>one</key>\n"
70 " <integer>1</integer>\n"
71 " <key>two</key>\n"
72 " <string>number-two</string>\n"
73 " </dict>\n"
74 " </array>\n"
75 " <key>true-val</key>\n"
76 " <true/>\n"
77 " <key>two</key>\n"
78 " <string>number-two</string>\n"
79 "</dict>\n"
80 "</plist>\n";
82 ATF_TC(prop_basic);
83 ATF_TC_HEAD(prop_basic, tc)
85 atf_tc_set_md_var(tc, "descr", "A basic test of proplib(3)");
88 ATF_TC_BODY(prop_basic, tc)
90 prop_dictionary_t dict;
91 char *ext1;
93 dict = prop_dictionary_create();
94 ATF_REQUIRE(dict != NULL);
97 prop_number_t num = prop_number_create_integer(1);
98 ATF_REQUIRE(num != NULL);
100 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "one", num), true);
101 prop_object_release(num);
105 prop_string_t str = prop_string_create_cstring("number-two");
106 ATF_REQUIRE(str != NULL);
108 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "two", str), true);
109 prop_object_release(str);
113 prop_array_t arr;
114 prop_dictionary_t dict_copy;
115 int i;
117 arr = prop_array_create();
118 ATF_REQUIRE(arr != NULL);
120 for (i = 0; i < 3; ++i) {
121 dict_copy = prop_dictionary_copy(dict);
122 ATF_REQUIRE(dict_copy != NULL);
123 ATF_REQUIRE_EQ(prop_array_add(arr, dict_copy), true);
124 prop_object_release(dict_copy);
127 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "three", arr), true);
128 prop_object_release(arr);
132 prop_bool_t val = prop_bool_create(true);
133 ATF_REQUIRE(val != NULL);
134 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "true-val", val), true);
135 prop_object_release(val);
137 val = prop_bool_create(false);
138 ATF_REQUIRE(val != NULL);
139 ATF_REQUIRE_EQ(prop_dictionary_set(dict, "false-val", val), true);
140 prop_object_release(val);
143 ext1 = prop_dictionary_externalize(dict);
144 ATF_REQUIRE(ext1 != NULL);
145 ATF_REQUIRE_STREQ(compare1, ext1);
148 prop_dictionary_t dict2;
149 char *ext2;
151 dict2 = prop_dictionary_internalize(ext1);
152 ATF_REQUIRE(dict2 != NULL);
153 ext2 = prop_dictionary_externalize(dict2);
154 ATF_REQUIRE(ext2 != NULL);
155 ATF_REQUIRE_STREQ(ext1, ext2);
156 prop_object_release(dict2);
157 free(ext2);
160 prop_object_release(dict);
161 free(ext1);
164 ATF_TC(prop_dictionary_equals);
165 ATF_TC_HEAD(prop_dictionary_equals, tc)
167 atf_tc_set_md_var(tc, "descr", "Test prop_dictionary_equals(3)");
170 ATF_TC_BODY(prop_dictionary_equals, tc)
172 prop_dictionary_t c, d;
175 * Fixed, should not fail any more...
177 atf_tc_expect_death("PR lib/43964");
181 d = prop_dictionary_internalize(compare1);
183 ATF_REQUIRE(d != NULL);
185 c = prop_dictionary_copy(d);
187 ATF_REQUIRE(c != NULL);
189 if (prop_dictionary_equals(c, d) != true)
190 atf_tc_fail("dictionaries are not equal");
192 prop_object_release(c);
193 prop_object_release(d);
196 ATF_TP_ADD_TCS(tp)
199 ATF_TP_ADD_TC(tp, prop_basic);
200 ATF_TP_ADD_TC(tp, prop_dictionary_equals);
202 return atf_no_error();