diff options
| author | 2023-01-08 05:29:22 +0100 | |
|---|---|---|
| committer | 2023-01-08 05:29:22 +0100 | |
| commit | 60d291941fadb72b66d11502710add5899e21a2d (patch) | |
| tree | a7ecccf74cd8fb7e2596fd3531fd9cccefa39dcd /test | |
| parent | 3f9360e33c13c22648036da42e36f8668e29fb60 (diff) | |
| download | libplist-60d291941fadb72b66d11502710add5899e21a2d.tar.gz libplist-60d291941fadb72b66d11502710add5899e21a2d.tar.bz2 | |
Add support for OpenStep plist format
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.am | 18 | ||||
| -rw-r--r-- | test/data/o1.ostep | 45 | ||||
| -rw-r--r-- | test/data/o2.ostep | 17 | ||||
| -rw-r--r-- | test/data/o3.ostep | 16 | ||||
| -rw-r--r-- | test/data/test.strings | 12 | ||||
| -rwxr-xr-x | test/ostep-comments.test | 20 | ||||
| -rwxr-xr-x | test/ostep-invalid-types.test | 33 | ||||
| -rwxr-xr-x | test/ostep-strings.test | 20 | ||||
| -rwxr-xr-x | test/ostep1.test | 20 | ||||
| -rwxr-xr-x | test/ostep2.test | 19 | ||||
| -rw-r--r-- | test/plist_cmp.c | 15 | ||||
| -rw-r--r-- | test/plist_otest.c | 130 |
12 files changed, 349 insertions, 16 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index cd3b940..66543ea 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -9,7 +9,8 @@ noinst_PROGRAMS = \ | |||
| 9 | plist_cmp \ | 9 | plist_cmp \ |
| 10 | plist_test \ | 10 | plist_test \ |
| 11 | plist_btest \ | 11 | plist_btest \ |
| 12 | plist_jtest | 12 | plist_jtest \ |
| 13 | plist_otest | ||
| 13 | 14 | ||
| 14 | plist_cmp_SOURCES = plist_cmp.c | 15 | plist_cmp_SOURCES = plist_cmp.c |
| 15 | plist_cmp_LDADD = \ | 16 | plist_cmp_LDADD = \ |
| @@ -25,6 +26,9 @@ plist_btest_LDADD = $(top_builddir)/src/libplist-2.0.la | |||
| 25 | plist_jtest_SOURCES = plist_jtest.c | 26 | plist_jtest_SOURCES = plist_jtest.c |
| 26 | plist_jtest_LDADD = $(top_builddir)/src/libplist-2.0.la | 27 | plist_jtest_LDADD = $(top_builddir)/src/libplist-2.0.la |
| 27 | 28 | ||
| 29 | plist_otest_SOURCES = plist_otest.c | ||
| 30 | plist_otest_LDADD = $(top_builddir)/src/libplist-2.0.la | ||
| 31 | |||
| 28 | TESTS = \ | 32 | TESTS = \ |
| 29 | empty.test \ | 33 | empty.test \ |
| 30 | small.test \ | 34 | small.test \ |
| @@ -54,7 +58,12 @@ TESTS = \ | |||
| 54 | json2.test \ | 58 | json2.test \ |
| 55 | json3.test \ | 59 | json3.test \ |
| 56 | json-invalid-types.test \ | 60 | json-invalid-types.test \ |
| 57 | json-int64-min-max.test | 61 | json-int64-min-max.test \ |
| 62 | ostep1.test \ | ||
| 63 | ostep2.test \ | ||
| 64 | ostep-strings.test \ | ||
| 65 | ostep-comments.test \ | ||
| 66 | ostep-invalid-types.test | ||
| 58 | 67 | ||
| 59 | EXTRA_DIST = \ | 68 | EXTRA_DIST = \ |
| 60 | $(TESTS) \ | 69 | $(TESTS) \ |
| @@ -102,7 +111,10 @@ EXTRA_DIST = \ | |||
| 102 | data/data.bplist \ | 111 | data/data.bplist \ |
| 103 | data/j1.json \ | 112 | data/j1.json \ |
| 104 | data/j2.json \ | 113 | data/j2.json \ |
| 105 | data/int64_min_max.json | 114 | data/int64_min_max.json \ |
| 115 | data/o1.ostep \ | ||
| 116 | data/o2.ostep \ | ||
| 117 | data/test.strings | ||
| 106 | 118 | ||
| 107 | TESTS_ENVIRONMENT = \ | 119 | TESTS_ENVIRONMENT = \ |
| 108 | top_srcdir=$(top_srcdir) \ | 120 | top_srcdir=$(top_srcdir) \ |
diff --git a/test/data/o1.ostep b/test/data/o1.ostep new file mode 100644 index 0000000..074406a --- /dev/null +++ b/test/data/o1.ostep | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | { | ||
| 2 | "test" = (1,1); | ||
| 3 | foo = ( | ||
| 4 | (-1337), | ||
| 5 | (1), | ||
| 6 | (1), | ||
| 7 | (1), | ||
| 8 | ( | ||
| 9 | (1), | ||
| 10 | (1), | ||
| 11 | (1), | ||
| 12 | (1), | ||
| 13 | ( | ||
| 14 | (1), | ||
| 15 | (1), | ||
| 16 | (1), | ||
| 17 | (1) | ||
| 18 | ) | ||
| 19 | ) | ||
| 20 | ); | ||
| 21 | more = { | ||
| 22 | "a" = "yo"; | ||
| 23 | "b" = ( | ||
| 24 | { | ||
| 25 | "c" = 0.25; | ||
| 26 | }, | ||
| 27 | { | ||
| 28 | "a" = "yo"; | ||
| 29 | "b" = ( | ||
| 30 | { | ||
| 31 | "c" = 0.25; | ||
| 32 | }, | ||
| 33 | { | ||
| 34 | "a" = "yo"; | ||
| 35 | "b" = ( | ||
| 36 | { | ||
| 37 | "cd" = -0.25; | ||
| 38 | } | ||
| 39 | ); | ||
| 40 | } | ||
| 41 | ); | ||
| 42 | } | ||
| 43 | ); | ||
| 44 | }; | ||
| 45 | } | ||
diff --git a/test/data/o2.ostep b/test/data/o2.ostep new file mode 100644 index 0000000..5f5f3c2 --- /dev/null +++ b/test/data/o2.ostep | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | { | ||
| 2 | "Some ASCII string" = "Test ASCII String"; | ||
| 3 | "Some UTF8 strings" = ( | ||
| 4 | "àéèçù", | ||
| 5 | "日本語", | ||
| 6 | "汉语/漢語", | ||
| 7 | "한국어/조선말", | ||
| 8 | "русский язык", | ||
| 9 | "الْعَرَبيّة", | ||
| 10 | "עִבְרִית", | ||
| 11 | "język polski", | ||
| 12 | "हिन्दी", | ||
| 13 | ); | ||
| 14 | "Keys & \"entities\"" = "hello world & others <nodes> are fun!?'"; | ||
| 15 | "Some Int" = 32434543632; | ||
| 16 | "Some String with Unicode entity" = "Yeah check this: \U1234 !!!"; | ||
| 17 | } | ||
diff --git a/test/data/o3.ostep b/test/data/o3.ostep new file mode 100644 index 0000000..b80444d --- /dev/null +++ b/test/data/o3.ostep | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | ( | ||
| 2 | { | ||
| 3 | AFirstKey = "A First Value"; | ||
| 4 | ASecondKey = "A Second Value"; | ||
| 5 | // this is the last entry | ||
| 6 | }, | ||
| 7 | /*{ | ||
| 8 | BFirstKey = "B First Value"; | ||
| 9 | BSecondKey = "B Second Value"; | ||
| 10 | },*/ | ||
| 11 | { | ||
| 12 | CFirstKey = "C First Value"; // "C First Unused Value"; | ||
| 13 | // now here is another comment | ||
| 14 | CSecondKey = /* "C Second Value";*/ "C Second Corrected Value"; | ||
| 15 | } | ||
| 16 | ) | ||
diff --git a/test/data/test.strings b/test/data/test.strings new file mode 100644 index 0000000..6d6ee43 --- /dev/null +++ b/test/data/test.strings | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | STRINGS_ENTRY = "Whatever"; | ||
| 2 | FOO = "BAR"; | ||
| 3 | BAR = Foo; | ||
| 4 | ENTRY0 = "àéèçù"; | ||
| 5 | ENTRY1 = "日本語"; | ||
| 6 | ENTRY2 = "汉语/漢語"; | ||
| 7 | ENTRY3 = "한국어/조선말"; | ||
| 8 | ENTRY4 = "русский язык"; | ||
| 9 | ENTRY5 = "الْعَرَبيّة"; | ||
| 10 | ENTRY6 = "עִבְרִית"; | ||
| 11 | ENTRY7 = "język polski"; | ||
| 12 | ENTRY8 = "हिन्दी"; | ||
diff --git a/test/ostep-comments.test b/test/ostep-comments.test new file mode 100755 index 0000000..8f7f629 --- /dev/null +++ b/test/ostep-comments.test | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | set -e | ||
| 4 | |||
| 5 | DATASRC=$top_srcdir/test/data | ||
| 6 | DATAOUT=$top_builddir/test/data | ||
| 7 | TESTFILE=o3.ostep | ||
| 8 | |||
| 9 | if ! test -d "$DATAOUT"; then | ||
| 10 | mkdir -p $DATAOUT | ||
| 11 | fi | ||
| 12 | |||
| 13 | export PLIST_OSTEP_DEBUG=1 | ||
| 14 | |||
| 15 | echo "Converting" | ||
| 16 | $top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
| 17 | |||
| 18 | echo "Comparing" | ||
| 19 | export PLIST_OSTEP_DEBUG=1 | ||
| 20 | $top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
diff --git a/test/ostep-invalid-types.test b/test/ostep-invalid-types.test new file mode 100755 index 0000000..9222394 --- /dev/null +++ b/test/ostep-invalid-types.test | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | DATASRC=$top_srcdir/test/data | ||
| 4 | DATAOUT=$top_builddir/test/data | ||
| 5 | TESTFILE0=data.bplist | ||
| 6 | TESTFILE1=7.plist | ||
| 7 | TESTFILE2=uid.bplist | ||
| 8 | |||
| 9 | if ! test -d "$DATAOUT"; then | ||
| 10 | mkdir -p $DATAOUT | ||
| 11 | fi | ||
| 12 | |||
| 13 | export PLIST_OSTEP_DEBUG=1 | ||
| 14 | |||
| 15 | echo "Converting (failure expected)" | ||
| 16 | $top_builddir/tools/plistutil -f openstep -i $DATASRC/$TESTFILE0 -o /dev/null | ||
| 17 | if [ $? -neq 2 ]; then | ||
| 18 | exit 1 | ||
| 19 | fi | ||
| 20 | |||
| 21 | echo "Converting (failure expected)" | ||
| 22 | $top_builddir/tools/plistutil -f openstepn -i $DATASRC/$TESTFILE1 -o /dev/null | ||
| 23 | if [ $? -neq 2 ]; then | ||
| 24 | exit 2 | ||
| 25 | fi | ||
| 26 | |||
| 27 | echo "Converting (failure expected)" | ||
| 28 | $top_builddir/tools/plistutil -f openstep -i $DATASRC/$TESTFILE2 -o /dev/null | ||
| 29 | if [ $? -neq 2 ]; then | ||
| 30 | exit 3 | ||
| 31 | fi | ||
| 32 | |||
| 33 | exit 0 | ||
diff --git a/test/ostep-strings.test b/test/ostep-strings.test new file mode 100755 index 0000000..5b0a098 --- /dev/null +++ b/test/ostep-strings.test | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | set -e | ||
| 4 | |||
| 5 | DATASRC=$top_srcdir/test/data | ||
| 6 | DATAOUT=$top_builddir/test/data | ||
| 7 | TESTFILE=test.strings | ||
| 8 | |||
| 9 | if ! test -d "$DATAOUT"; then | ||
| 10 | mkdir -p $DATAOUT | ||
| 11 | fi | ||
| 12 | |||
| 13 | export PLIST_OSTEP_DEBUG=1 | ||
| 14 | |||
| 15 | echo "Converting" | ||
| 16 | $top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
| 17 | |||
| 18 | echo "Comparing" | ||
| 19 | export PLIST_OSTEP_DEBUG=1 | ||
| 20 | $top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
diff --git a/test/ostep1.test b/test/ostep1.test new file mode 100755 index 0000000..f0d9b51 --- /dev/null +++ b/test/ostep1.test | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | set -e | ||
| 4 | |||
| 5 | DATASRC=$top_srcdir/test/data | ||
| 6 | DATAOUT=$top_builddir/test/data | ||
| 7 | TESTFILE=o1.ostep | ||
| 8 | |||
| 9 | if ! test -d "$DATAOUT"; then | ||
| 10 | mkdir -p $DATAOUT | ||
| 11 | fi | ||
| 12 | |||
| 13 | export PLIST_OSTEP_DEBUG=1 | ||
| 14 | |||
| 15 | echo "Converting" | ||
| 16 | $top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
| 17 | |||
| 18 | echo "Comparing" | ||
| 19 | export PLIST_OSTEP_DEBUG=1 | ||
| 20 | $top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
diff --git a/test/ostep2.test b/test/ostep2.test new file mode 100755 index 0000000..1b991c3 --- /dev/null +++ b/test/ostep2.test | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | ## -*- sh -*- | ||
| 2 | |||
| 3 | set -e | ||
| 4 | |||
| 5 | DATASRC=$top_srcdir/test/data | ||
| 6 | DATAOUT=$top_builddir/test/data | ||
| 7 | TESTFILE=o2.ostep | ||
| 8 | |||
| 9 | if ! test -d "$DATAOUT"; then | ||
| 10 | mkdir -p $DATAOUT | ||
| 11 | fi | ||
| 12 | |||
| 13 | export PLIST_OTEST_DEBUG=1 | ||
| 14 | |||
| 15 | echo "Converting" | ||
| 16 | $top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
| 17 | |||
| 18 | echo "Comparing" | ||
| 19 | $top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out | ||
diff --git a/test/plist_cmp.c b/test/plist_cmp.c index 2af3f63..1b4a36a 100644 --- a/test/plist_cmp.c +++ b/test/plist_cmp.c | |||
| @@ -127,19 +127,8 @@ int main(int argc, char *argv[]) | |||
| 127 | plist_1[size_in1] = '\0'; | 127 | plist_1[size_in1] = '\0'; |
| 128 | plist_2[size_in2] = '\0'; | 128 | plist_2[size_in2] = '\0'; |
| 129 | 129 | ||
| 130 | if (memcmp(plist_1, "bplist00", 8) == 0) | 130 | plist_from_memory(plist_1, size_in1, &root_node1); |
| 131 | plist_from_bin(plist_1, size_in1, &root_node1); | 131 | plist_from_memory(plist_2, size_in2, &root_node2); |
| 132 | else if (plist_1[0] == '[' || plist_1[0] == '{') | ||
| 133 | plist_from_json(plist_1, size_in1, &root_node1); | ||
| 134 | else | ||
| 135 | plist_from_xml(plist_1, size_in1, &root_node1); | ||
| 136 | |||
| 137 | if (memcmp(plist_2, "bplist00", 8) == 0) | ||
| 138 | plist_from_bin(plist_2, size_in2, &root_node2); | ||
| 139 | else if (plist_2[0] == '[' || plist_2[0] == '{') | ||
| 140 | plist_from_json(plist_2, size_in2, &root_node2); | ||
| 141 | else | ||
| 142 | plist_from_xml(plist_2, size_in2, &root_node2); | ||
| 143 | 132 | ||
| 144 | if (!root_node1 || !root_node2) | 133 | if (!root_node1 || !root_node2) |
| 145 | { | 134 | { |
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 | |||
