summaryrefslogtreecommitdiffstats
path: root/test/plist_btest.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-12-23 02:08:35 +0100
committerGravatar Nikias Bassen2021-12-23 02:08:35 +0100
commit70002721443dabaa99b56301b537980e137b6249 (patch)
tree0acef227b95a6c820a5611e8f44f0be3a049bf76 /test/plist_btest.c
parent7aaa371944544bbbfade3c8e17846f8f58711869 (diff)
downloadlibplist-70002721443dabaa99b56301b537980e137b6249.tar.gz
libplist-70002721443dabaa99b56301b537980e137b6249.tar.bz2
test: Add PLIST_UID test case
Diffstat (limited to 'test/plist_btest.c')
-rw-r--r--test/plist_btest.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/test/plist_btest.c b/test/plist_btest.c
new file mode 100644
index 0000000..0f2c1c8
--- /dev/null
+++ b/test/plist_btest.c
@@ -0,0 +1,131 @@
1/*
2 * backup_test.c
3 * source libplist regression test
4 *
5 * Copyright (c) 2009 Jonathan Beck All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
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
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
23#include "plist/plist.h"
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <sys/stat.h>
29
30#ifdef _MSC_VER
31#pragma warning(disable:4996)
32#endif
33
34
35int main(int argc, char *argv[])
36{
37 FILE *iplist = NULL;
38 plist_t root_node1 = NULL;
39 plist_t root_node2 = NULL;
40 char *plist_bin = NULL;
41 char *plist_bin2 = NULL;
42 char *plist_xml = NULL;
43 int size_in = 0;
44 uint32_t size_out = 0;
45 uint32_t size_out2 = 0;
46 char *file_in = NULL;
47 char *file_out = NULL;
48 struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
49 if (argc != 3)
50 {
51 printf("Wrong input\n");
52 return 1;
53 }
54
55 file_in = argv[1];
56 file_out = argv[2];
57 //read input file
58 iplist = fopen(file_in, "rb");
59
60 if (!iplist)
61 {
62 printf("File does not exists\n");
63 return 2;
64 }
65 printf("File %s is open\n", file_in);
66 stat(file_in, filestats);
67 size_in = filestats->st_size;
68 plist_bin = (char *) malloc(sizeof(char) * (size_in + 1));
69 fread(plist_bin, sizeof(char), size_in, iplist);
70 fclose(iplist);
71
72
73 //convert one format to another
74 plist_from_bin(plist_bin, size_in, &root_node1);
75 if (!root_node1)
76 {
77 printf("PList BIN parsing failed\n");
78 return 3;
79 }
80
81 printf("PList BIN parsing succeeded\n");
82 plist_to_xml(root_node1, &plist_xml, &size_out);
83 if (!plist_xml)
84 {
85 printf("PList XML writing failed\n");
86 return 4;
87 }
88
89 printf("PList XML writing succeeded\n");
90 plist_from_xml(plist_xml, size_out, &root_node2);
91 if (!root_node2)
92 {
93 printf("PList XML parsing failed\n");
94 return 5;
95 }
96
97 printf("PList XML parsing succeeded\n");
98 plist_to_bin(root_node2, &plist_bin2, &size_out2);
99 if (!plist_bin2)
100 {
101 printf("PList BIN writing failed\n");
102 return 8;
103 }
104
105 printf("PList BIN writing succeeded\n");
106 if (plist_bin2)
107 {
108 FILE *oplist = NULL;
109 oplist = fopen(file_out, "wb");
110 fwrite(plist_bin2, size_out2, sizeof(char), oplist);
111 fclose(oplist);
112 }
113
114 plist_free(root_node1);
115 plist_free(root_node2);
116 free(plist_xml);
117 free(plist_bin);
118 free(plist_bin2);
119 free(filestats);
120
121 if ((uint32_t)size_in != size_out2)
122 {
123 printf("Size of input and output is different\n");
124 printf("Input size : %i\n", size_in);
125 printf("Output size : %i\n", size_out2);
126 }
127
128 //success
129 return 0;
130}
131