diff options
Diffstat (limited to 'test/plist_test.c')
| -rw-r--r-- | test/plist_test.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/plist_test.c b/test/plist_test.c new file mode 100644 index 0000000..a4dd714 --- /dev/null +++ b/test/plist_test.c | |||
| @@ -0,0 +1,124 @@ | |||
| 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 | int main(int argc, char *argv[]) | ||
| 31 | { | ||
| 32 | FILE *iplist = NULL; | ||
| 33 | FILE *oplist = NULL; | ||
| 34 | plist_t root_node1 = NULL; | ||
| 35 | plist_t root_node2 = NULL; | ||
| 36 | char *plist_xml = NULL; | ||
| 37 | char *plist_xml2 = NULL; | ||
| 38 | char *plist_bin = NULL; | ||
| 39 | int size_in = 0; | ||
| 40 | int size_out = 0; | ||
| 41 | int size_out2 = 0; | ||
| 42 | char *file_in = NULL; | ||
| 43 | char *file_out[512]; | ||
| 44 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | ||
| 45 | if (argc!= 2) { | ||
| 46 | printf("Wrong input\n"); | ||
| 47 | return 1; | ||
| 48 | } | ||
| 49 | |||
| 50 | file_in = argv[1]; | ||
| 51 | //read input file | ||
| 52 | iplist = fopen(file_in, "rb"); | ||
| 53 | |||
| 54 | if (!iplist) { | ||
| 55 | printf("File does not exists\n"); | ||
| 56 | return 2; | ||
| 57 | } | ||
| 58 | printf("File %s is open\n", file_in); | ||
| 59 | stat(file_in, filestats); | ||
| 60 | size_in = filestats->st_size; | ||
| 61 | plist_xml = (char *) malloc(sizeof(char) * (size_in + 1)); | ||
| 62 | fread(plist_xml, sizeof(char), size_in, iplist); | ||
| 63 | fclose(iplist); | ||
| 64 | |||
| 65 | |||
| 66 | //convert one format to another | ||
| 67 | plist_from_xml(plist_xml, size_in, &root_node1); | ||
| 68 | if (!root_node1) { | ||
| 69 | printf("PList XML parsing failed\n"); | ||
| 70 | return 3; | ||
| 71 | } | ||
| 72 | else | ||
| 73 | printf("PList XML parsing succeeded\n"); | ||
| 74 | |||
| 75 | plist_to_bin(root_node1, &plist_bin, &size_out); | ||
| 76 | if (!plist_bin) { | ||
| 77 | printf("PList BIN writing failed\n"); | ||
| 78 | return 4; | ||
| 79 | } | ||
| 80 | else | ||
| 81 | printf("PList BIN writing succeeded\n"); | ||
| 82 | |||
| 83 | plist_from_bin(plist_bin, size_out, &root_node2); | ||
| 84 | if (!root_node2) { | ||
| 85 | printf("PList BIN parsing failed\n"); | ||
| 86 | return 5; | ||
| 87 | } | ||
| 88 | else | ||
| 89 | printf("PList BIN parsing succeeded\n"); | ||
| 90 | |||
| 91 | plist_to_xml(root_node2, &plist_xml2, &size_out2); | ||
| 92 | if (!plist_xml2) { | ||
| 93 | printf("PList XML writing failed\n"); | ||
| 94 | return 8; | ||
| 95 | } | ||
| 96 | else | ||
| 97 | printf("PList XML writing succeeded\n"); | ||
| 98 | |||
| 99 | if (plist_xml2) { | ||
| 100 | FILE *oplist = NULL; | ||
| 101 | char file_out[512]; | ||
| 102 | sprintf(file_out, "%s.out", file_in); | ||
| 103 | oplist = fopen(file_out, "wb"); | ||
| 104 | fwrite(plist_xml2, size_out2, sizeof(char), oplist); | ||
| 105 | fclose(oplist); | ||
| 106 | } | ||
| 107 | |||
| 108 | plist_free(root_node1); | ||
| 109 | plist_free(root_node2); | ||
| 110 | free(plist_bin); | ||
| 111 | free(plist_xml); | ||
| 112 | free(plist_xml2); | ||
| 113 | free(filestats); | ||
| 114 | |||
| 115 | if (size_in != size_out2) { | ||
| 116 | printf("Size of input and output is different\n"); | ||
| 117 | printf("Input size : %i\n", size_in); | ||
| 118 | printf("Output size : %i\n", size_out2); | ||
| 119 | } | ||
| 120 | |||
| 121 | //success | ||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | |||
