summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-12-23 02:08:35 +0100
committerGravatar Nikias Bassen2021-12-23 02:08:35 +0100
commit70002721443dabaa99b56301b537980e137b6249 (patch)
tree0acef227b95a6c820a5611e8f44f0be3a049bf76
parent7aaa371944544bbbfade3c8e17846f8f58711869 (diff)
downloadlibplist-70002721443dabaa99b56301b537980e137b6249.tar.gz
libplist-70002721443dabaa99b56301b537980e137b6249.tar.bz2
test: Add PLIST_UID test case
-rw-r--r--test/Makefile.am12
-rw-r--r--test/data/uid.bplistbin0 -> 43 bytes
-rw-r--r--test/plist_btest.c131
-rwxr-xr-xtest/uid.test15
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 =
noinst_PROGRAMS = \
plist_cmp \
- plist_test
+ plist_test \
+ plist_btest
plist_cmp_SOURCES = plist_cmp.c
plist_cmp_LDADD = \
@@ -17,6 +18,9 @@ plist_cmp_LDADD = \
plist_test_SOURCES = plist_test.c
plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la
+plist_btest_SOURCES = plist_btest.c
+plist_btest_LDADD = $(top_builddir)/src/libplist-2.0.la
+
TESTS = \
empty.test \
small.test \
@@ -40,7 +44,8 @@ TESTS = \
cdata.test \
offsetsize.test \
refsize.test \
- malformed_dict.test
+ malformed_dict.test \
+ uid.test
EXTRA_DIST = \
$(TESTS) \
@@ -83,7 +88,8 @@ EXTRA_DIST = \
data/signedunsigned.bplist \
data/signedunsigned.plist \
data/unsigned.bplist \
- data/unsigned.plist
+ data/unsigned.plist \
+ data/uid.bplist
TESTS_ENVIRONMENT = \
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 @@
+/*
+ * backup_test.c
+ * source libplist regression test
+ *
+ * Copyright (c) 2009 Jonathan Beck 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_bin = NULL;
+ char *plist_bin2 = NULL;
+ char *plist_xml = 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 = (struct stat *) malloc(sizeof(struct stat));
+ 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_bin = (char *) malloc(sizeof(char) * (size_in + 1));
+ fread(plist_bin, sizeof(char), size_in, iplist);
+ fclose(iplist);
+
+
+ //convert one format to another
+ plist_from_bin(plist_bin, size_in, &root_node1);
+ if (!root_node1)
+ {
+ printf("PList BIN parsing failed\n");
+ return 3;
+ }
+
+ printf("PList BIN parsing succeeded\n");
+ plist_to_xml(root_node1, &plist_xml, &size_out);
+ if (!plist_xml)
+ {
+ printf("PList XML writing failed\n");
+ return 4;
+ }
+
+ printf("PList XML writing succeeded\n");
+ plist_from_xml(plist_xml, size_out, &root_node2);
+ if (!root_node2)
+ {
+ printf("PList XML parsing failed\n");
+ return 5;
+ }
+
+ printf("PList XML parsing succeeded\n");
+ plist_to_bin(root_node2, &plist_bin2, &size_out2);
+ if (!plist_bin2)
+ {
+ printf("PList BIN writing failed\n");
+ return 8;
+ }
+
+ printf("PList BIN writing succeeded\n");
+ if (plist_bin2)
+ {
+ FILE *oplist = NULL;
+ oplist = fopen(file_out, "wb");
+ fwrite(plist_bin2, size_out2, sizeof(char), oplist);
+ fclose(oplist);
+ }
+
+ plist_free(root_node1);
+ plist_free(root_node2);
+ free(plist_xml);
+ free(plist_bin);
+ free(plist_bin2);
+ free(filestats);
+
+ 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;
+}
+
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 @@
+## -*- sh -*-
+
+DATASRC=$top_srcdir/test/data
+DATAOUT=$top_builddir/test/data
+TESTFILE=uid.bplist
+
+if ! test -d "$DATAOUT"; then
+ mkdir -p $DATAOUT
+fi
+
+echo "Converting"
+$top_builddir/test/plist_btest $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
+
+echo "Comparing"
+$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out