Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libprop / proptest.c
blob36fd4207c8b1888d3dca6d56ccce60b8553c0f50
1 /* $NetBSD: proptest.c,v 1.2 2007/07/16 19:04:18 joerg Exp $ */
3 /*
4 * Test basic proplib functionality.
6 * Written by Jason Thorpe 5/26/2006.
7 * Public domain.
8 */
10 #include <assert.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
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"
21 "<dict>\n"
22 " <key>false-val</key>\n"
23 " <false/>\n"
24 " <key>one</key>\n"
25 " <integer>1</integer>\n"
26 " <key>three</key>\n"
27 " <array>\n"
28 " <dict>\n"
29 " <key>one</key>\n"
30 " <integer>1</integer>\n"
31 " <key>two</key>\n"
32 " <string>number-two</string>\n"
33 " </dict>\n"
34 " <dict>\n"
35 " <key>one</key>\n"
36 " <integer>1</integer>\n"
37 " <key>two</key>\n"
38 " <string>number-two</string>\n"
39 " </dict>\n"
40 " <dict>\n"
41 " <key>one</key>\n"
42 " <integer>1</integer>\n"
43 " <key>two</key>\n"
44 " <string>number-two</string>\n"
45 " </dict>\n"
46 " </array>\n"
47 " <key>true-val</key>\n"
48 " <true/>\n"
49 " <key>two</key>\n"
50 " <string>number-two</string>\n"
51 "</dict>\n"
52 "</plist>\n";
54 int
55 main(int argc, char *argv[])
57 prop_dictionary_t dict;
58 char *ext1;
59 size_t idx;
61 dict = prop_dictionary_create();
62 assert(dict != NULL);
65 prop_number_t num = prop_number_create_integer(1);
66 assert(num != NULL);
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");
74 assert(str != NULL);
76 assert(prop_dictionary_set(dict, "two", str) == true);
77 prop_object_release(str);
81 prop_array_t arr;
82 prop_dictionary_t dict_copy;
84 arr = prop_array_create();
85 assert(arr != NULL);
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);
108 assert(val != NULL);
109 assert(prop_dictionary_set(dict, "true-val", val) == true);
110 prop_object_release(val);
112 val = prop_bool_create(false);
113 assert(val != NULL);
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]);
129 break;
133 assert(strlen(compare1) == strlen(ext1));
134 assert(strcmp(ext1, compare1) == 0);
137 prop_dictionary_t dict2;
138 char *ext2;
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);
146 free(ext2);
149 prop_object_release(dict);
150 free(ext1);
152 exit(0);