summaryrefslogtreecommitdiffstats
path: root/test/plist_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/plist_test.c')
-rw-r--r--test/plist_test.c196
1 files changed, 102 insertions, 94 deletions
diff --git a/test/plist_test.c b/test/plist_test.c
index 069701e..a0344e9 100644
--- a/test/plist_test.c
+++ b/test/plist_test.c
@@ -8,15 +8,15 @@
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details. 15 * Lesser General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Lesser General Public 17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22 22
@@ -34,95 +34,103 @@
34 34
35int main(int argc, char *argv[]) 35int main(int argc, char *argv[])
36{ 36{
37 FILE *iplist = NULL; 37 FILE *iplist = NULL;
38 FILE *oplist = NULL; 38 FILE *oplist = NULL;
39 plist_t root_node1 = NULL; 39 plist_t root_node1 = NULL;
40 plist_t root_node2 = NULL; 40 plist_t root_node2 = NULL;
41 char *plist_xml = NULL; 41 char *plist_xml = NULL;
42 char *plist_xml2 = NULL; 42 char *plist_xml2 = NULL;
43 char *plist_bin = NULL; 43 char *plist_bin = NULL;
44 int size_in = 0; 44 int size_in = 0;
45 int size_out = 0; 45 int size_out = 0;
46 int size_out2 = 0; 46 int size_out2 = 0;
47 char *file_in = NULL; 47 char *file_in = NULL;
48 struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); 48 struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
49 if (argc!= 2) { 49 if (argc!= 2)
50 printf("Wrong input\n"); 50 {
51 return 1; 51 printf("Wrong input\n");
52 } 52 return 1;
53 53 }
54 file_in = argv[1]; 54
55 //read input file 55 file_in = argv[1];
56 iplist = fopen(file_in, "rb"); 56 //read input file
57 57 iplist = fopen(file_in, "rb");
58 if (!iplist) { 58
59 printf("File does not exists\n"); 59 if (!iplist)
60 return 2; 60 {
61 } 61 printf("File does not exists\n");
62 printf("File %s is open\n", file_in); 62 return 2;
63 stat(file_in, filestats); 63 }
64 size_in = filestats->st_size; 64 printf("File %s is open\n", file_in);
65 plist_xml = (char *) malloc(sizeof(char) * (size_in + 1)); 65 stat(file_in, filestats);
66 fread(plist_xml, sizeof(char), size_in, iplist); 66 size_in = filestats->st_size;
67 fclose(iplist); 67 plist_xml = (char *) malloc(sizeof(char) * (size_in + 1));
68 68 fread(plist_xml, sizeof(char), size_in, iplist);
69 69 fclose(iplist);
70 //convert one format to another 70
71 plist_from_xml(plist_xml, size_in, &root_node1); 71
72 if (!root_node1) { 72 //convert one format to another
73 printf("PList XML parsing failed\n"); 73 plist_from_xml(plist_xml, size_in, &root_node1);
74 return 3; 74 if (!root_node1)
75 } 75 {
76 else 76 printf("PList XML parsing failed\n");
77 printf("PList XML parsing succeeded\n"); 77 return 3;
78 78 }
79 plist_to_bin(root_node1, &plist_bin, &size_out); 79 else
80 if (!plist_bin) { 80 printf("PList XML parsing succeeded\n");
81 printf("PList BIN writing failed\n"); 81
82 return 4; 82 plist_to_bin(root_node1, &plist_bin, &size_out);
83 } 83 if (!plist_bin)
84 else 84 {
85 printf("PList BIN writing succeeded\n"); 85 printf("PList BIN writing failed\n");
86 86 return 4;
87 plist_from_bin(plist_bin, size_out, &root_node2); 87 }
88 if (!root_node2) { 88 else
89 printf("PList BIN parsing failed\n"); 89 printf("PList BIN writing succeeded\n");
90 return 5; 90
91 } 91 plist_from_bin(plist_bin, size_out, &root_node2);
92 else 92 if (!root_node2)
93 printf("PList BIN parsing succeeded\n"); 93 {
94 94 printf("PList BIN parsing failed\n");
95 plist_to_xml(root_node2, &plist_xml2, &size_out2); 95 return 5;
96 if (!plist_xml2) { 96 }
97 printf("PList XML writing failed\n"); 97 else
98 return 8; 98 printf("PList BIN parsing succeeded\n");
99 } 99
100 else 100 plist_to_xml(root_node2, &plist_xml2, &size_out2);
101 printf("PList XML writing succeeded\n"); 101 if (!plist_xml2)
102 102 {
103 if (plist_xml2) { 103 printf("PList XML writing failed\n");
104 FILE *oplist = NULL; 104 return 8;
105 char file_out[512]; 105 }
106 sprintf(file_out, "%s.out", file_in); 106 else
107 oplist = fopen(file_out, "wb"); 107 printf("PList XML writing succeeded\n");
108 fwrite(plist_xml2, size_out2, sizeof(char), oplist); 108
109 fclose(oplist); 109 if (plist_xml2)
110 } 110 {
111 111 FILE *oplist = NULL;
112 plist_free(root_node1); 112 char file_out[512];
113 plist_free(root_node2); 113 sprintf(file_out, "%s.out", file_in);
114 free(plist_bin); 114 oplist = fopen(file_out, "wb");
115 free(plist_xml); 115 fwrite(plist_xml2, size_out2, sizeof(char), oplist);
116 free(plist_xml2); 116 fclose(oplist);
117 free(filestats); 117 }
118 118
119 if (size_in != size_out2) { 119 plist_free(root_node1);
120 printf("Size of input and output is different\n"); 120 plist_free(root_node2);
121 printf("Input size : %i\n", size_in); 121 free(plist_bin);
122 printf("Output size : %i\n", size_out2); 122 free(plist_xml);
123 } 123 free(plist_xml2);
124 124 free(filestats);
125 //success 125
126 return 0; 126 if (size_in != size_out2)
127 {
128 printf("Size of input and output is different\n");
129 printf("Input size : %i\n", size_in);
130 printf("Output size : %i\n", size_out2);
131 }
132
133 //success
134 return 0;
127} 135}
128 136