diff options
| author | 2021-12-23 02:08:35 +0100 | |
|---|---|---|
| committer | 2021-12-23 02:08:35 +0100 | |
| commit | 70002721443dabaa99b56301b537980e137b6249 (patch) | |
| tree | 0acef227b95a6c820a5611e8f44f0be3a049bf76 | |
| parent | 7aaa371944544bbbfade3c8e17846f8f58711869 (diff) | |
| download | libplist-70002721443dabaa99b56301b537980e137b6249.tar.gz libplist-70002721443dabaa99b56301b537980e137b6249.tar.bz2 | |
test: Add PLIST_UID test case
| -rw-r--r-- | test/Makefile.am | 12 | ||||
| -rw-r--r-- | test/data/uid.bplist | bin | 0 -> 43 bytes | |||
| -rw-r--r-- | test/plist_btest.c | 131 | ||||
| -rwxr-xr-x | test/uid.test | 15 |
4 files changed, 155 insertions, 3 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 6b3b901..3fca55f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -7,7 +7,8 @@ AM_LDFLAGS = | |||
| 7 | 7 | ||
| 8 | noinst_PROGRAMS = \ | 8 | noinst_PROGRAMS = \ |
| 9 | plist_cmp \ | 9 | plist_cmp \ |
| 10 | plist_test | 10 | plist_test \ |
| 11 | plist_btest | ||
| 11 | 12 | ||
| 12 | plist_cmp_SOURCES = plist_cmp.c | 13 | plist_cmp_SOURCES = plist_cmp.c |
| 13 | plist_cmp_LDADD = \ | 14 | plist_cmp_LDADD = \ |
| @@ -17,6 +18,9 @@ plist_cmp_LDADD = \ | |||
| 17 | plist_test_SOURCES = plist_test.c | 18 | plist_test_SOURCES = plist_test.c |
| 18 | plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la | 19 | plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la |
| 19 | 20 | ||
| 21 | plist_btest_SOURCES = plist_btest.c | ||
| 22 | plist_btest_LDADD = $(top_builddir)/src/libplist-2.0.la | ||
| 23 | |||
| 20 | TESTS = \ | 24 | TESTS = \ |
| 21 | empty.test \ | 25 | empty.test \ |
| 22 | small.test \ | 26 | small.test \ |
| @@ -40,7 +44,8 @@ TESTS = \ | |||
| 40 | cdata.test \ | 44 | cdata.test \ |
| 41 | offsetsize.test \ | 45 | offsetsize.test \ |
| 42 | refsize.test \ | 46 | refsize.test \ |
| 43 | malformed_dict.test | 47 | malformed_dict.test \ |
| 48 | uid.test | ||
| 44 | 49 | ||
| 45 | EXTRA_DIST = \ | 50 | EXTRA_DIST = \ |
| 46 | $(TESTS) \ | 51 | $(TESTS) \ |
| @@ -83,7 +88,8 @@ EXTRA_DIST = \ | |||
| 83 | data/signedunsigned.bplist \ | 88 | data/signedunsigned.bplist \ |
| 84 | data/signedunsigned.plist \ | 89 | data/signedunsigned.plist \ |
| 85 | data/unsigned.bplist \ | 90 | data/unsigned.bplist \ |
| 86 | data/unsigned.plist | 91 | data/unsigned.plist \ |
| 92 | data/uid.bplist | ||
| 87 | 93 | ||
| 88 | TESTS_ENVIRONMENT = \ | 94 | TESTS_ENVIRONMENT = \ |
| 89 | top_srcdir=$(top_srcdir) \ | 95 | top_srcdir=$(top_srcdir) \ |
diff --git a/test/data/uid.bplist b/test/data/uid.bplist new file mode 100644 index 0000000..e1fc6f8 --- /dev/null +++ b/test/data/uid.bplist | |||
| Binary files differ | |||
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 | |||
| 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_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 | |||
diff --git a/test/uid.test b/test/uid.test new file mode 100755 index 0000000..f131c6d --- /dev/null +++ b/test/uid.test | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | DATASRC=$top_srcdir/test/data | ||
| 4 | DATAOUT=$top_builddir/test/data | ||
| 5 | TESTFILE=uid.bplist | ||
| 6 | |||
| 7 | if ! test -d "$DATAOUT"; then | ||
| 8 | mkdir -p $DATAOUT | ||
| 9 | fi | ||
| 10 | |||
| 11 | echo "Converting" | ||
| 12 | $top_builddir/test/plist_btest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
| 13 | |||
| 14 | echo "Comparing" | ||
| 15 | $top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
