1 /* $NetBSD: proptest.c,v 1.2 2007/07/16 19:04:18 joerg Exp $ */
4 * Test basic proplib functionality.
6 * Written by Jason Thorpe 5/26/2006.
15 #include <prop/proplib.h>
17 static const char compare1
[] =
18 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
19 "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
20 "<plist version=\"1.0\">\n"
22 " <key>false-val</key>\n"
25 " <integer>1</integer>\n"
30 " <integer>1</integer>\n"
32 " <string>number-two</string>\n"
36 " <integer>1</integer>\n"
38 " <string>number-two</string>\n"
42 " <integer>1</integer>\n"
44 " <string>number-two</string>\n"
47 " <key>true-val</key>\n"
50 " <string>number-two</string>\n"
55 main(int argc
, char *argv
[])
57 prop_dictionary_t dict
;
61 dict
= prop_dictionary_create();
65 prop_number_t num
= prop_number_create_integer(1);
68 assert(prop_dictionary_set(dict
, "one", num
) == true);
69 prop_object_release(num
);
73 prop_string_t str
= prop_string_create_cstring("number-two");
76 assert(prop_dictionary_set(dict
, "two", str
) == true);
77 prop_object_release(str
);
82 prop_dictionary_t dict_copy
;
84 arr
= prop_array_create();
87 dict_copy
= prop_dictionary_copy(dict
);
88 assert(dict_copy
!= NULL
);
89 assert(prop_array_add(arr
, dict_copy
) == true);
90 prop_object_release(dict_copy
);
92 dict_copy
= prop_dictionary_copy(dict
);
93 assert(dict_copy
!= NULL
);
94 assert(prop_array_add(arr
, dict_copy
) == true);
95 prop_object_release(dict_copy
);
97 dict_copy
= prop_dictionary_copy(dict
);
98 assert(dict_copy
!= NULL
);
99 assert(prop_array_add(arr
, dict_copy
) == true);
100 prop_object_release(dict_copy
);
102 assert(prop_dictionary_set(dict
, "three", arr
) == true);
103 prop_object_release(arr
);
107 prop_bool_t val
= prop_bool_create(true);
109 assert(prop_dictionary_set(dict
, "true-val", val
) == true);
110 prop_object_release(val
);
112 val
= prop_bool_create(false);
114 assert(prop_dictionary_set(dict
, "false-val", val
) == true);
115 prop_object_release(val
);
118 ext1
= prop_dictionary_externalize(dict
);
119 assert(ext1
!= NULL
);
121 printf("REFERENCE:\n%s\n", compare1
);
122 printf("GENERATED:\n%s\n", ext1
);
124 for (idx
= 0; idx
< strlen(ext1
); idx
++) {
125 if (compare1
[idx
] != ext1
[idx
]) {
126 printf("Strings differ at byte %zu\n", idx
);
127 printf("REFERENCE:\n%s\n", &compare1
[idx
]);
128 printf("GENERATED:\n%s\n", &ext1
[idx
]);
133 assert(strlen(compare1
) == strlen(ext1
));
134 assert(strcmp(ext1
, compare1
) == 0);
137 prop_dictionary_t dict2
;
140 dict2
= prop_dictionary_internalize(ext1
);
141 assert(dict2
!= NULL
);
142 ext2
= prop_dictionary_externalize(dict2
);
143 assert(ext2
!= NULL
);
144 assert(strcmp(ext1
, ext2
) == 0);
145 prop_object_release(dict2
);
149 prop_object_release(dict
);