diff options
Diffstat (limited to 'test/plist_otest.c')
| -rw-r--r-- | test/plist_otest.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/test/plist_otest.c b/test/plist_otest.c new file mode 100644 index 0000000..14168f8 --- /dev/null +++ b/test/plist_otest.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* | ||
| 2 | * plist_otest.c | ||
| 3 | * source libplist regression test | ||
| 4 | * | ||
| 5 | * Copyright (c) 2022 Nikias Bassen, 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 | |||
| 35 | int 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_ostep = NULL; | ||
| 41 | char *plist_ostep2 = NULL; | ||
| 42 | char *plist_bin = 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; | ||
| 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_ostep = (char *) malloc(sizeof(char) * (size_in + 1)); | ||
| 69 | fread(plist_ostep, sizeof(char), size_in, iplist); | ||
| 70 | fclose(iplist); | ||
| 71 | plist_ostep[size_in] = 0; | ||
| 72 | |||
| 73 | //convert one format to another | ||
| 74 | plist_from_openstep(plist_ostep, size_in, &root_node1); | ||
| 75 | if (!root_node1) | ||
| 76 | { | ||
| 77 | printf("OpenStep PList parsing failed\n"); | ||
| 78 | return 3; | ||
| 79 | } | ||
| 80 | |||
| 81 | printf("OpenStep PList parsing succeeded\n"); | ||
| 82 | plist_to_bin(root_node1, &plist_bin, &size_out); | ||
| 83 | if (!plist_bin) | ||
| 84 | { | ||
| 85 | printf("PList BIN writing failed\n"); | ||
| 86 | return 4; | ||
| 87 | } | ||
| 88 | |||
| 89 | printf("PList BIN writing succeeded\n"); | ||
| 90 | plist_from_bin(plist_bin, size_out, &root_node2); | ||
| 91 | if (!root_node2) | ||
| 92 | { | ||
| 93 | printf("PList BIN parsing failed\n"); | ||
| 94 | return 5; | ||
| 95 | } | ||
| 96 | |||
| 97 | printf("PList BIN parsing succeeded\n"); | ||
| 98 | plist_to_openstep(root_node2, &plist_ostep2, &size_out2, 0); | ||
| 99 | if (!plist_ostep2) | ||
| 100 | { | ||
| 101 | printf("OpenStep PList writing failed\n"); | ||
| 102 | return 8; | ||
| 103 | } | ||
| 104 | |||
| 105 | printf("OpenStep PList writing succeeded\n"); | ||
| 106 | if (plist_ostep2) | ||
| 107 | { | ||
| 108 | FILE *oplist = NULL; | ||
| 109 | oplist = fopen(file_out, "wb"); | ||
| 110 | fwrite(plist_ostep2, size_out2, sizeof(char), oplist); | ||
| 111 | fclose(oplist); | ||
| 112 | } | ||
| 113 | |||
| 114 | plist_free(root_node1); | ||
| 115 | plist_free(root_node2); | ||
| 116 | free(plist_bin); | ||
| 117 | free(plist_ostep); | ||
| 118 | free(plist_ostep2); | ||
| 119 | |||
| 120 | if ((uint32_t)size_in != size_out2) | ||
| 121 | { | ||
| 122 | printf("Size of input and output is different\n"); | ||
| 123 | printf("Input size : %i\n", size_in); | ||
| 124 | printf("Output size : %i\n", size_out2); | ||
| 125 | } | ||
| 126 | |||
| 127 | //success | ||
| 128 | return 0; | ||
| 129 | } | ||
| 130 | |||
