summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am18
-rw-r--r--test/data/o1.ostep45
-rw-r--r--test/data/o2.ostep17
-rw-r--r--test/data/o3.ostep16
-rw-r--r--test/data/test.strings12
-rwxr-xr-xtest/ostep-comments.test20
-rwxr-xr-xtest/ostep-invalid-types.test33
-rwxr-xr-xtest/ostep-strings.test20
-rwxr-xr-xtest/ostep1.test20
-rwxr-xr-xtest/ostep2.test19
-rw-r--r--test/plist_cmp.c15
-rw-r--r--test/plist_otest.c130
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 = \
plist_cmp \
plist_test \
plist_btest \
- plist_jtest
+ plist_jtest \
+ plist_otest
plist_cmp_SOURCES = plist_cmp.c
plist_cmp_LDADD = \
@@ -25,6 +26,9 @@ plist_btest_LDADD = $(top_builddir)/src/libplist-2.0.la
plist_jtest_SOURCES = plist_jtest.c
plist_jtest_LDADD = $(top_builddir)/src/libplist-2.0.la
+plist_otest_SOURCES = plist_otest.c
+plist_otest_LDADD = $(top_builddir)/src/libplist-2.0.la
+
TESTS = \
empty.test \
small.test \
@@ -54,7 +58,12 @@ TESTS = \
json2.test \
json3.test \
json-invalid-types.test \
- json-int64-min-max.test
+ json-int64-min-max.test \
+ ostep1.test \
+ ostep2.test \
+ ostep-strings.test \
+ ostep-comments.test \
+ ostep-invalid-types.test
EXTRA_DIST = \
$(TESTS) \
@@ -102,7 +111,10 @@ EXTRA_DIST = \
data/data.bplist \
data/j1.json \
data/j2.json \
- data/int64_min_max.json
+ data/int64_min_max.json \
+ data/o1.ostep \
+ data/o2.ostep \
+ data/test.strings
TESTS_ENVIRONMENT = \
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 @@
+{
+ "test" = (1,1);
+ foo = (
+ (-1337),
+ (1),
+ (1),
+ (1),
+ (
+ (1),
+ (1),
+ (1),
+ (1),
+ (
+ (1),
+ (1),
+ (1),
+ (1)
+ )
+ )
+ );
+ more = {
+ "a" = "yo";
+ "b" = (
+ {
+ "c" = 0.25;
+ },
+ {
+ "a" = "yo";
+ "b" = (
+ {
+ "c" = 0.25;
+ },
+ {
+ "a" = "yo";
+ "b" = (
+ {
+ "cd" = -0.25;
+ }
+ );
+ }
+ );
+ }
+ );
+ };
+}
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 @@
+{
+ "Some ASCII string" = "Test ASCII String";
+ "Some UTF8 strings" = (
+ "àéèçù",
+ "日本語",
+ "汉语/漢語",
+ "한국어/조선말",
+ "русский язык",
+ "الْعَرَبيّة",
+ "עִבְרִית",
+ "język polski",
+ "हिन्दी",
+ );
+ "Keys & \"entities\"" = "hello world & others <nodes> are fun!?'";
+ "Some Int" = 32434543632;
+ "Some String with Unicode entity" = "Yeah check this: \U1234 !!!";
+}
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 @@
+(
+ {
+ AFirstKey = "A First Value";
+ ASecondKey = "A Second Value";
+ // this is the last entry
+ },
+ /*{
+ BFirstKey = "B First Value";
+ BSecondKey = "B Second Value";
+ },*/
+ {
+ CFirstKey = "C First Value"; // "C First Unused Value";
+ // now here is another comment
+ CSecondKey = /* "C Second Value";*/ "C Second Corrected Value";
+ }
+)
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 @@
+STRINGS_ENTRY = "Whatever";
+FOO = "BAR";
+BAR = Foo;
+ENTRY0 = "àéèçù";
+ENTRY1 = "日本語";
+ENTRY2 = "汉语/漢語";
+ENTRY3 = "한국어/조선말";
+ENTRY4 = "русский язык";
+ENTRY5 = "الْعَرَبيّة";
+ENTRY6 = "עִבְרִית";
+ENTRY7 = "język polski";
+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 @@
+## -*- sh -*-
+
+set -e
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE=o3.ostep
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+export PLIST_OSTEP_DEBUG=1
+
+echo "Converting"
+$top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
+
+echo "Comparing"
+export PLIST_OSTEP_DEBUG=1
+$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 @@
+## -*- sh -*-
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE0=data.bplist
+TESTFILE1=7.plist
+TESTFILE2=uid.bplist
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+export PLIST_OSTEP_DEBUG=1
+
+echo "Converting (failure expected)"
+$top_builddir/tools/plistutil -f openstep -i $DATASRC/$TESTFILE0 -o /dev/null
+if [ $? -neq 2 ]; then
+ exit 1
+fi
+
+echo "Converting (failure expected)"
+$top_builddir/tools/plistutil -f openstepn -i $DATASRC/$TESTFILE1 -o /dev/null
+if [ $? -neq 2 ]; then
+ exit 2
+fi
+
+echo "Converting (failure expected)"
+$top_builddir/tools/plistutil -f openstep -i $DATASRC/$TESTFILE2 -o /dev/null
+if [ $? -neq 2 ]; then
+ exit 3
+fi
+
+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 @@
+## -*- sh -*-
+
+set -e
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE=test.strings
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+export PLIST_OSTEP_DEBUG=1
+
+echo "Converting"
+$top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
+
+echo "Comparing"
+export PLIST_OSTEP_DEBUG=1
+$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 @@
+## -*- sh -*-
+
+set -e
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE=o1.ostep
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+export PLIST_OSTEP_DEBUG=1
+
+echo "Converting"
+$top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
+
+echo "Comparing"
+export PLIST_OSTEP_DEBUG=1
+$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 @@
+## -*- sh -*-
+
+set -e
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE=o2.ostep
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+export PLIST_OTEST_DEBUG=1
+
+echo "Converting"
+$top_builddir/test/plist_otest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
+
+echo "Comparing"
+$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[])
plist_1[size_in1] = '\0';
plist_2[size_in2] = '\0';
- if (memcmp(plist_1, "bplist00", 8) == 0)
- plist_from_bin(plist_1, size_in1, &root_node1);
- else if (plist_1[0] == '[' || plist_1[0] == '{')
- plist_from_json(plist_1, size_in1, &root_node1);
- else
- plist_from_xml(plist_1, size_in1, &root_node1);
-
- if (memcmp(plist_2, "bplist00", 8) == 0)
- plist_from_bin(plist_2, size_in2, &root_node2);
- else if (plist_2[0] == '[' || plist_2[0] == '{')
- plist_from_json(plist_2, size_in2, &root_node2);
- else
- plist_from_xml(plist_2, size_in2, &root_node2);
+ plist_from_memory(plist_1, size_in1, &root_node1);
+ plist_from_memory(plist_2, size_in2, &root_node2);
if (!root_node1 || !root_node2)
{
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 @@
+/*
+ * plist_otest.c
+ * source libplist regression test
+ *
+ * Copyright (c) 2022 Nikias Bassen, All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include "plist/plist.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#ifdef _MSC_VER
+#pragma warning(disable:4996)
+#endif
+
+
+int main(int argc, char *argv[])
+{
+ FILE *iplist = NULL;
+ plist_t root_node1 = NULL;
+ plist_t root_node2 = NULL;
+ char *plist_ostep = NULL;
+ char *plist_ostep2 = NULL;
+ char *plist_bin = NULL;
+ int size_in = 0;
+ uint32_t size_out = 0;
+ uint32_t size_out2 = 0;
+ char *file_in = NULL;
+ char *file_out = NULL;
+ struct stat filestats;
+ if (argc != 3)
+ {
+ printf("Wrong input\n");
+ return 1;
+ }
+
+ file_in = argv[1];
+ file_out = argv[2];
+ //read input file
+ iplist = fopen(file_in, "rb");
+
+ if (!iplist)
+ {
+ printf("File does not exists\n");
+ return 2;
+ }
+ printf("File %s is open\n", file_in);
+ stat(file_in, &filestats);
+ size_in = filestats.st_size;
+ plist_ostep = (char *) malloc(sizeof(char) * (size_in + 1));
+ fread(plist_ostep, sizeof(char), size_in, iplist);
+ fclose(iplist);
+ plist_ostep[size_in] = 0;
+
+ //convert one format to another
+ plist_from_openstep(plist_ostep, size_in, &root_node1);
+ if (!root_node1)
+ {
+ printf("OpenStep PList parsing failed\n");
+ return 3;
+ }
+
+ printf("OpenStep PList parsing succeeded\n");
+ plist_to_bin(root_node1, &plist_bin, &size_out);
+ if (!plist_bin)
+ {
+ printf("PList BIN writing failed\n");
+ return 4;
+ }
+
+ printf("PList BIN writing succeeded\n");
+ plist_from_bin(plist_bin, size_out, &root_node2);
+ if (!root_node2)
+ {
+ printf("PList BIN parsing failed\n");
+ return 5;
+ }
+
+ printf("PList BIN parsing succeeded\n");
+ plist_to_openstep(root_node2, &plist_ostep2, &size_out2, 0);
+ if (!plist_ostep2)
+ {
+ printf("OpenStep PList writing failed\n");
+ return 8;
+ }
+
+ printf("OpenStep PList writing succeeded\n");
+ if (plist_ostep2)
+ {
+ FILE *oplist = NULL;
+ oplist = fopen(file_out, "wb");
+ fwrite(plist_ostep2, size_out2, sizeof(char), oplist);
+ fclose(oplist);
+ }
+
+ plist_free(root_node1);
+ plist_free(root_node2);
+ free(plist_bin);
+ free(plist_ostep);
+ free(plist_ostep2);
+
+ if ((uint32_t)size_in != size_out2)
+ {
+ printf("Size of input and output is different\n");
+ printf("Input size : %i\n", size_in);
+ printf("Output size : %i\n", size_out2);
+ }
+
+ //success
+ return 0;
+}
+