diff options
Diffstat (limited to 'test')
56 files changed, 1186 insertions, 114 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 4519de0..a4191c4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,13 +1,42 @@ -AM_CFLAGS = $(GLOBAL_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/libcnary/include +AM_CFLAGS = \ + $(GLOBAL_CFLAGS) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/libcnary/include +AM_CPPFLAGS = $(AM_CFLAGS) + AM_LDFLAGS = -noinst_PROGRAMS = plist_cmp plist_test +noinst_PROGRAMS = \ + plist_cmp \ + plist_test \ + plist_test++ \ + integer_set_test \ + plist_btest \ + plist_jtest \ + plist_otest plist_cmp_SOURCES = plist_cmp.c -plist_cmp_LDADD = $(top_builddir)/src/libplist.la $(top_builddir)/libcnary/libcnary.la +plist_cmp_LDADD = \ + $(top_builddir)/src/libplist-2.0.la \ + $(top_builddir)/libcnary/libcnary.la + +plist_test___SOURCES = plist_test++.cpp +plist_test___LDADD = $(top_builddir)/src/libplist++-2.0.la plist_test_SOURCES = plist_test.c -plist_test_LDADD = $(top_builddir)/src/libplist.la +plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la + +integer_set_test_SOURCES = integer_set.c +integer_set_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 + +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 \ @@ -16,6 +45,12 @@ TESTS = \ large.test \ huge.test \ bigarray.test \ + empty++.test \ + small++.test \ + medium++.test \ + large++.test \ + huge++.test \ + bigarray++.test \ dates.test \ timezone1.test \ timezone2.test \ @@ -32,7 +67,19 @@ TESTS = \ cdata.test \ offsetsize.test \ refsize.test \ - malformed_dict.test + malformed_dict.test \ + uid.test \ + integer_set.test \ + json1.test \ + json2.test \ + json3.test \ + json-invalid-types.test \ + json-int64-min-max.test \ + ostep1.test \ + ostep2.test \ + ostep-strings.test \ + ostep-comments.test \ + ostep-invalid-types.test EXTRA_DIST = \ $(TESTS) \ @@ -75,9 +122,20 @@ EXTRA_DIST = \ data/signedunsigned.bplist \ data/signedunsigned.plist \ data/unsigned.bplist \ - data/unsigned.plist + data/unsigned.plist \ + data/uid.bplist \ + data/data.bplist \ + data/j1.json \ + data/j2.json \ + data/int64_min_max.json \ + data/o1.ostep \ + data/o2.ostep \ + data/o3.ostep \ + data/test.strings -TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) +TESTS_ENVIRONMENT = \ + top_srcdir=$(top_srcdir) \ + top_builddir=$(top_builddir) clean-local: if test -d $(top_builddir)/test/data; then cd $(top_builddir)/test/data && rm -f *.out *.bin *.xml; fi diff --git a/test/amp.test b/test/amp.test index 0815391..3678f27 100755 --- a/test/amp.test +++ b/test/amp.test @@ -1,14 +1,16 @@ ## -*- sh -*- -set -e - DATASRC=$top_srcdir/test/data TESTFILE=amp.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.out +DATAOUT0=$top_builddir/test/data/amp.test.out rm -rf $DATAOUT0 $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 -if test -f $DATAOUT0; then + +# test succeeds if plistutil fails +if [ $? -eq 0 ]; then exit 1 +else + exit 0 fi diff --git a/test/bigarray++.test b/test/bigarray++.test new file mode 100755 index 0000000..78f38ef --- /dev/null +++ b/test/bigarray++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=6.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/bigarray++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/bigarray++.test.out diff --git a/test/bigarray.test b/test/bigarray.test index 4b819f4..1b88d43 100755 --- a/test/bigarray.test +++ b/test/bigarray.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/bigarray.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/bigarray.test.out diff --git a/test/cdata.test b/test/cdata.test index 77e7e45..b4f3ed2 100755 --- a/test/cdata.test +++ b/test/cdata.test @@ -5,7 +5,7 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=cdata.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin +DATAOUT0=$top_builddir/test/data/cdata.test.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/data/data.bplist b/test/data/data.bplist Binary files differnew file mode 100644 index 0000000..955993f --- /dev/null +++ b/test/data/data.bplist diff --git a/test/data/int64_min_max.json b/test/data/int64_min_max.json new file mode 100644 index 0000000..7707090 --- /dev/null +++ b/test/data/int64_min_max.json @@ -0,0 +1 @@ +{"INT64_MIN":-9223372036854775808,"INT64_MAX":9223372036854775807}
\ No newline at end of file diff --git a/test/data/j1.json b/test/data/j1.json new file mode 100644 index 0000000..2fe564d --- /dev/null +++ b/test/data/j1.json @@ -0,0 +1 @@ +{"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":[{"c":-0.25}]}]}]}} diff --git a/test/data/j2.json b/test/data/j2.json new file mode 100644 index 0000000..9d1210e --- /dev/null +++ b/test/data/j2.json @@ -0,0 +1 @@ +{"Some ASCII string":"Test ASCII String","Some UTF8 strings":["àéèçù","日本語","汉语/漢語","한국어/조선말","русский язык","الْعَرَبيّة","עִבְרִית","język polski","हिन्दी"],"Keys & \"entities\"":"hellow world & others <nodes> are \"fun!?'","Boolean":false,"Another Boolean":true,"Some Int":32434543632,"Some String with Unicode entity":"Yeah check this: \u1234 !!!"}
\ No newline at end of file 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/data/uid.bplist b/test/data/uid.bplist Binary files differnew file mode 100644 index 0000000..e1fc6f8 --- /dev/null +++ b/test/data/uid.bplist diff --git a/test/dates.test b/test/dates.test index 2865717..06bf034 100755 --- a/test/dates.test +++ b/test/dates.test @@ -5,8 +5,8 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=7.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE.xml +DATAOUT0=$top_builddir/test/data/dates.test.bin +DATAOUT1=$top_builddir/test/data/dates.test.xml $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 $top_builddir/tools/plistutil -i $DATAOUT0 -o $DATAOUT1 diff --git a/test/empty++.test b/test/empty++.test new file mode 100755 index 0000000..7e3695b --- /dev/null +++ b/test/empty++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=1.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/empty++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/empty++.test.out diff --git a/test/empty.test b/test/empty.test index 0a21f33..bc71562 100755 --- a/test/empty.test +++ b/test/empty.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/empty.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/empty.test.out diff --git a/test/empty_keys.test b/test/empty_keys.test index 4291e8c..19bbb08 100755 --- a/test/empty_keys.test +++ b/test/empty_keys.test @@ -5,7 +5,7 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=empty_keys.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin +DATAOUT0=$top_builddir/test/data/empty_keys.test.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/entities.test b/test/entities.test index b87e4c7..a828e15 100755 --- a/test/entities.test +++ b/test/entities.test @@ -5,7 +5,7 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=entities.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin +DATAOUT0=$top_builddir/test/data/entities.test.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/hex.test b/test/hex.test index 99b88bc..414cdbc 100755 --- a/test/hex.test +++ b/test/hex.test @@ -5,7 +5,7 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=hex.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin +DATAOUT0=$top_builddir/test/data/hex.test.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/huge++.test b/test/huge++.test new file mode 100755 index 0000000..90d3503 --- /dev/null +++ b/test/huge++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=5.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/huge++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/huge++.test.out diff --git a/test/huge.test b/test/huge.test index 8585ed5..560c21f 100755 --- a/test/huge.test +++ b/test/huge.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/huge.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/huge.test.out diff --git a/test/integer_set.c b/test/integer_set.c new file mode 100644 index 0000000..e25648f --- /dev/null +++ b/test/integer_set.c @@ -0,0 +1,130 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> +#include <stdlib.h> + +#include <string.h> +#include <plist/plist.h> + +void print_plist(plist_t pl) +{ + char *xml = NULL; + uint32_t xlen = 0; + plist_to_xml(pl, &xml, &xlen); + if (xml) { + printf("%s\n", xml); + } + free(xml); +} + +int main(int argc, char** argv) +{ + int err = 0; + char *xml = NULL; + uint32_t xlen = 0; + plist_t iii = plist_new_int(0); + + /* test 1 */ + plist_set_uint_val(iii, 0x8000000000000000LL); + plist_to_xml(iii, &xml, &xlen); + const char* match1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>9223372036854775808</integer>\n" + "</plist>\n"; + if (strcmp(xml, match1) != 0) { + printf("ERROR: plist_set_uint_val with 0x8000000000000000LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_uint_val with 0x8000000000000000LL\n"); + } + free(xml); + xml = NULL; + + /* test 2 */ + plist_set_int_val(iii, 0x8000000000000000LL); + plist_to_xml(iii, &xml, &xlen); + const char* match2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>-9223372036854775808</integer>\n" + "</plist>\n"; + if (strcmp(xml, match2) != 0) { + printf("ERROR: plist_set_int_val with 0x8000000000000000LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_int_val with 0x8000000000000000LL\n"); + } + free(xml); + xml = NULL; + + /* test 3 */ + plist_set_uint_val(iii, (uint64_t)-1LL); + plist_to_xml(iii, &xml, &xlen); + const char* match3 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>18446744073709551615</integer>\n" + "</plist>\n"; + if (strcmp(xml, match3) != 0) { + printf("ERROR: plist_set_uint_val with (uint64_t)-1LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_uint_val with (uint64_t)-1LL\n"); + } + free(xml); + xml = NULL; + + /* test 4 */ + plist_set_int_val(iii, -1LL); + plist_to_xml(iii, &xml, &xlen); + const char* match4 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>-1</integer>\n" + "</plist>\n"; + if (strcmp(xml, match4) != 0) { + printf("ERROR: plist_set_int_val with -1LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_int_val with -1LL\n"); + } + free(xml); + xml = NULL; + + /* test 5 */ + plist_set_uint_val(iii, 0x8000000000000001LL); + plist_to_xml(iii, &xml, &xlen); + const char* match5 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>9223372036854775809</integer>\n" + "</plist>\n"; + if (strcmp(xml, match5) != 0) { + printf("ERROR: plist_set_uint_val with 0x8000000000000001LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_uint_val with 0x8000000000000001LL\n"); + } + free(xml); + xml = NULL; + + /* test 6 */ + plist_set_uint_val(iii, 18446744073709551615uLL); + plist_to_xml(iii, &xml, &xlen); + const char* match6 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<integer>18446744073709551615</integer>\n" + "</plist>\n"; + if (strcmp(xml, match6) != 0) { + printf("ERROR: plist_set_uint_val with 0x8000000000000001LL failed\n"); + err++; + } else { + printf("SUCCESS: plist_set_uint_val with 0x8000000000000001LL\n"); + } + free(xml); + xml = NULL; + + return (err > 0) ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/test/integer_set.test b/test/integer_set.test new file mode 100755 index 0000000..b917663 --- /dev/null +++ b/test/integer_set.test @@ -0,0 +1,5 @@ +## -*- sh -*- + +set -e + +$top_builddir/test/integer_set_test diff --git a/test/invalid_tag.test b/test/invalid_tag.test index 079bcdd..5d4da93 100755 --- a/test/invalid_tag.test +++ b/test/invalid_tag.test @@ -1,14 +1,16 @@ ## -*- sh -*- -set -e - DATASRC=$top_srcdir/test/data TESTFILE=invalid_tag.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.out +DATAOUT0=$top_builddir/test/data/invalid_tag.test.out rm -rf $DATAOUT0 $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 -if test -f $DATAOUT0; then + +# test succeeds if plistutil fails +if [ $? -eq 0 ]; then exit 1 +else + exit 0 fi diff --git a/test/json-int64-min-max.test b/test/json-int64-min-max.test new file mode 100755 index 0000000..f3fe61c --- /dev/null +++ b/test/json-int64-min-max.test @@ -0,0 +1,19 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=int64_min_max.json + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +export PLIST_JSON_DEBUG=1 + +echo "Converting" +$top_builddir/test/plist_jtest $DATASRC/$TESTFILE $DATAOUT/json-int64-min-max.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/json-int64-min-max.test.out diff --git a/test/json-invalid-types.test b/test/json-invalid-types.test new file mode 100755 index 0000000..c532316 --- /dev/null +++ b/test/json-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_JSON_DEBUG=1 + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE0 -o /dev/null +if [ $? -neq 2 ]; then + exit 1 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE1 -o /dev/null +if [ $? -neq 2 ]; then + exit 2 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE2 -o /dev/null +if [ $? -neq 2 ]; then + exit 3 +fi + +exit 0 diff --git a/test/json1.test b/test/json1.test new file mode 100755 index 0000000..cc7440f --- /dev/null +++ b/test/json1.test @@ -0,0 +1,19 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=j1.json + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +export PLIST_JSON_DEBUG=1 + +echo "Converting" +$top_builddir/test/plist_jtest $DATASRC/$TESTFILE $DATAOUT/json1.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/json1.test.out diff --git a/test/json2.test b/test/json2.test new file mode 100755 index 0000000..199643c --- /dev/null +++ b/test/json2.test @@ -0,0 +1,19 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=j2.json + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +export PLIST_JSON_DEBUG=1 + +echo "Converting" +$top_builddir/test/plist_jtest $DATASRC/$TESTFILE $DATAOUT/json2.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/json2.test.out diff --git a/test/json3.test b/test/json3.test new file mode 100755 index 0000000..6189e89 --- /dev/null +++ b/test/json3.test @@ -0,0 +1,24 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=entities.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +export PLIST_JSON_DEBUG=1 + +echo "Converting input file to JSON" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE -o $DATAOUT/json3.test.json + +echo "Converting to binary and back to JSON" +$top_builddir/test/plist_jtest $DATAOUT/json3.test.json $DATAOUT/json3.test.json.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/json3.test.json.out + +rm -f $DATAOUT/json3.test.json diff --git a/test/large++.test b/test/large++.test new file mode 100755 index 0000000..f3f4c23 --- /dev/null +++ b/test/large++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=4.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/large++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/large++.test.out diff --git a/test/large.test b/test/large.test index b46743f..d3cce7a 100755 --- a/test/large.test +++ b/test/large.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/large.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/large.test.out diff --git a/test/malformed_dict.test b/test/malformed_dict.test index f45ae7e..1d3ba2b 100755 --- a/test/malformed_dict.test +++ b/test/malformed_dict.test @@ -1,11 +1,15 @@ ## -*- sh -*- -set -e - DATASRC=$top_srcdir/test/data TESTFILE=malformed_dict.bplist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.out +DATAOUT0=$top_builddir/test/data/malformed_dict.test.out $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 +# test succeeds if plistutil fails +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/medium++.test b/test/medium++.test new file mode 100755 index 0000000..6eb453f --- /dev/null +++ b/test/medium++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=3.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/medium++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/medium++.test.out diff --git a/test/medium.test b/test/medium.test index 39213b4..300c016 100755 --- a/test/medium.test +++ b/test/medium.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/medium.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/medium.test.out diff --git a/test/order.test b/test/order.test index f8a7702..bd89b9d 100755 --- a/test/order.test +++ b/test/order.test @@ -6,7 +6,7 @@ DATASRC=$top_srcdir/test/data TESTFILE=order.bplist DATAIN0=$DATASRC/$TESTFILE DATAIN1=$DATASRC/order.plist -DATAOUT0=$top_builddir/test/data/$TESTFILE.out +DATAOUT0=$top_builddir/test/data/order.test.out $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/ostep-comments.test b/test/ostep-comments.test new file mode 100755 index 0000000..68f5242 --- /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/ostep-comments.test.out + +echo "Comparing" +export PLIST_OSTEP_DEBUG=1 +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/ostep-comments.test.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..e3441a3 --- /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/ostep-strings.test.out + +echo "Comparing" +export PLIST_OSTEP_DEBUG=1 +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/ostep-strings.test.out diff --git a/test/ostep1.test b/test/ostep1.test new file mode 100755 index 0000000..998fc54 --- /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/ostep1.test.out + +echo "Comparing" +export PLIST_OSTEP_DEBUG=1 +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/ostep1.test.out diff --git a/test/ostep2.test b/test/ostep2.test new file mode 100755 index 0000000..a5485f8 --- /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/ostep2.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/ostep2.test.out 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/plist_cmp.c b/test/plist_cmp.c index a07452b..c452032 100644 --- a/test/plist_cmp.c +++ b/test/plist_cmp.c @@ -35,12 +35,12 @@ static plist_t plist_get_first_child(plist_t node) { - return (plist_t) node_first_child((node_t*) node); + return (plist_t) node_first_child((node_t) node); } static plist_t plist_get_next_sibling(plist_t node) { - return (plist_t) node_next_sibling((node_t*) node); + return (plist_t) node_next_sibling((node_t) node); } static char compare_plist(plist_t node_l, plist_t node_r) @@ -75,21 +75,12 @@ static char compare_plist(plist_t node_l, plist_t node_r) int main(int argc, char *argv[]) { - FILE *iplist1 = NULL; - FILE *iplist2 = NULL; plist_t root_node1 = NULL; plist_t root_node2 = NULL; - char *plist_1 = NULL; - char *plist_2 = NULL; - int size_in1 = 0; - int size_in2 = 0; char *file_in1 = NULL; char *file_in2 = NULL; int res = 0; - struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat)); - struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat)); - if (argc!= 3) { printf("Wrong input\n"); @@ -99,60 +90,21 @@ int main(int argc, char *argv[]) file_in1 = argv[1]; file_in2 = argv[2]; - //read input file - iplist1 = fopen(file_in1, "rb"); - iplist2 = fopen(file_in2, "rb"); - - if (!iplist1 || !iplist2) - { - printf("File does not exists\n"); - return 2; - } - - stat(file_in1, filestats1); - stat(file_in2, filestats2); - - size_in1 = filestats1->st_size; - size_in2 = filestats2->st_size; - - plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1)); - plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1)); - - fread(plist_1, sizeof(char), size_in1, iplist1); - fread(plist_2, sizeof(char), size_in2, iplist2); - - fclose(iplist1); - fclose(iplist2); - - if (memcmp(plist_1, "bplist00", 8) == 0) - plist_from_bin(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 - plist_from_xml(plist_2, size_in2, &root_node2); + plist_read_from_file(file_in1, &root_node1, NULL); + plist_read_from_file(file_in2, &root_node2, NULL); if (!root_node1 || !root_node2) { printf("PList parsing failed\n"); return 3; } - else - printf("PList parsing succeeded\n"); + printf("PList parsing succeeded\n"); res = compare_plist(root_node1, root_node2); - plist_free(root_node1); plist_free(root_node2); - free(plist_1); - free(plist_2); - free(filestats1); - free(filestats2); - return !res; } diff --git a/test/plist_jtest.c b/test/plist_jtest.c new file mode 100644 index 0000000..130e3c7 --- /dev/null +++ b/test/plist_jtest.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_json = NULL; + char *plist_json2 = 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 = (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_json = (char *) malloc(sizeof(char) * (size_in + 1)); + fread(plist_json, sizeof(char), size_in, iplist); + fclose(iplist); + plist_json[size_in] = 0; + + //convert one format to another + plist_from_json(plist_json, size_in, &root_node1); + if (!root_node1) + { + printf("PList JSON parsing failed\n"); + return 3; + } + + printf("PList JSON 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_json(root_node2, &plist_json2, &size_out2, 0); + if (!plist_json2) + { + printf("PList JSON writing failed\n"); + return 8; + } + + printf("PList JSON writing succeeded\n"); + if (plist_json2) + { + FILE *oplist = NULL; + oplist = fopen(file_out, "wb"); + fwrite(plist_json2, size_out2, sizeof(char), oplist); + fclose(oplist); + } + + plist_free(root_node1); + plist_free(root_node2); + free(plist_bin); + free(plist_json); + free(plist_json2); + 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/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; +} + diff --git a/test/plist_test++.cpp b/test/plist_test++.cpp new file mode 100644 index 0000000..33205c1 --- /dev/null +++ b/test/plist_test++.cpp @@ -0,0 +1,103 @@ +/* + * source libplist++ regression test + * + * Copyright (c) 2021 Sebastien Gonzalve 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 <fstream> +#include <sstream> +#include <iostream> + +int main(int argc, char *argv[]) +{ + if (argc != 3) + { + printf("Wrong input\n"); + return 1; + } + + const char* file_in = argv[1]; + const char* file_out = argv[2]; + + //read input file + std::ifstream iplist; + iplist.open(file_in); + + if (!iplist) + { + printf("File does not exists\n"); + return 2; + } + + std::cout << "File " << file_in << " is open\n"; + + std::string plist_xml; + { + std::stringstream buffer; + buffer << iplist.rdbuf(); + plist_xml = buffer.str(); + } + + iplist.close(); + + //convert one format to another + PList::Structure* root_node1 = PList::Structure::FromXml(plist_xml); + if (!root_node1) + { + std::cout << "PList XML parsing failed\n"; + return 3; + } + + std::cout << "PList XML parsing succeeded\n"; + std::vector<char> plist_bin = root_node1->ToBin(); + // FIXME There is no way to test for success of ToBin for now. + + std::cout << "PList BIN writing succeeded\n"; + PList::Structure* root_node2 = PList::Structure::FromBin(plist_bin); + if (!root_node2) + { + std::cout << "PList BIN parsing failed\n"; + return 5; + } + + std::cout << "PList BIN parsing succeeded\n"; + std::string plist_xml2 = root_node2->ToXml(); + if (plist_xml2.empty()) + { + std::cout << "PList XML writing failed\n"; + return 8; + } + + std::cout << "PList XML writing succeeded\n"; + { + std::ofstream oplist; + oplist.open(file_out); + oplist << plist_xml2; + } + + if (plist_xml.size() != plist_xml2.size()) + { + std::cout << "Size of input and output is different\n" + << "Input size : " << plist_xml.size() + << "\nOutput size : " << plist_xml2.size() << '\n'; + } + + return 0; +} + diff --git a/test/plist_test.c b/test/plist_test.c index b498e1d..6e3947a 100644 --- a/test/plist_test.c +++ b/test/plist_test.c @@ -77,36 +77,32 @@ int main(int argc, char *argv[]) printf("PList XML parsing failed\n"); return 3; } - else - printf("PList XML parsing succeeded\n"); + printf("PList XML parsing succeeded\n"); plist_to_bin(root_node1, &plist_bin, &size_out); if (!plist_bin) { printf("PList BIN writing failed\n"); return 4; } - else - printf("PList BIN writing succeeded\n"); + 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; } - else - printf("PList BIN parsing succeeded\n"); + printf("PList BIN parsing succeeded\n"); plist_to_xml(root_node2, &plist_xml2, &size_out2); if (!plist_xml2) { printf("PList XML writing failed\n"); return 8; } - else - printf("PList XML writing succeeded\n"); + printf("PList XML writing succeeded\n"); if (plist_xml2) { FILE *oplist = NULL; diff --git a/test/recursion.test b/test/recursion.test index 0120a12..97bfb45 100755 --- a/test/recursion.test +++ b/test/recursion.test @@ -1,11 +1,15 @@ ## -*- sh -*- -set -e - DATASRC=$top_srcdir/test/data TESTFILE=recursion.bplist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.out +DATAOUT0=$top_builddir/test/data/recursion.test.out $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 +# test succeeds if plistutil fails +if [ $? -eq 0 ]; then + exit 1 +else + exit 0 +fi diff --git a/test/signedunsigned1.test b/test/signedunsigned1.test index 798de86..52f7080 100755 --- a/test/signedunsigned1.test +++ b/test/signedunsigned1.test @@ -13,8 +13,8 @@ CMPFILE1=unsigned.bplist DATACMP0=$DATASRC/$CMPFILE0 DATACMP1=$DATASRC/$CMPFILE1 -DATAOUT0=$top_builddir/test/data/$TESTFILE0.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE1.bin +DATAOUT0=$top_builddir/test/data/signedunsigned1.test.signed.bin +DATAOUT1=$top_builddir/test/data/signedunsigned1.test.unsigned.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 $top_builddir/tools/plistutil -i $DATAIN1 -o $DATAOUT1 diff --git a/test/signedunsigned2.test b/test/signedunsigned2.test index 2ea8b49..192f1a6 100755 --- a/test/signedunsigned2.test +++ b/test/signedunsigned2.test @@ -13,8 +13,8 @@ CMPFILE1=unsigned.plist DATACMP0=$DATASRC/$CMPFILE0 DATACMP1=$DATASRC/$CMPFILE1 -DATAOUT0=$top_builddir/test/data/$TESTFILE0.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE1.bin +DATAOUT0=$top_builddir/test/data/signedunsigned2.test.signed.bin +DATAOUT1=$top_builddir/test/data/signedunsigned2.test.unsigned.bin $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 $top_builddir/tools/plistutil -i $DATAIN1 -o $DATAOUT1 diff --git a/test/signedunsigned3.test b/test/signedunsigned3.test index d732e72..87bdcbc 100755 --- a/test/signedunsigned3.test +++ b/test/signedunsigned3.test @@ -13,8 +13,8 @@ CMPFILE1=signedunsigned.plist DATACMP0=$DATASRC/$CMPFILE0 DATACMP1=$DATASRC/$CMPFILE1 -DATAOUT0=$top_builddir/test/data/$TESTFILE0.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE1.xml +DATAOUT0=$top_builddir/test/data/signedunsigned3.test.signed.bin +DATAOUT1=$top_builddir/test/data/signedunsigned3.test.unsigned.xml $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 $top_builddir/tools/plistutil -i $DATAIN1 -o $DATAOUT1 diff --git a/test/small++.test b/test/small++.test new file mode 100755 index 0000000..2ceace7 --- /dev/null +++ b/test/small++.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE=2.plist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +echo "Converting" +$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/small++.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/small++.test.out diff --git a/test/small.test b/test/small.test index 8c25e70..dd2faf8 100755 --- a/test/small.test +++ b/test/small.test @@ -9,7 +9,7 @@ if ! test -d "$DATAOUT"; then fi echo "Converting" -$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_test $DATASRC/$TESTFILE $DATAOUT/small.test.out echo "Comparing" -$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/small.test.out diff --git a/test/timezone1.test b/test/timezone1.test index 843b166..5de7cea 100755 --- a/test/timezone1.test +++ b/test/timezone1.test @@ -5,9 +5,9 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=7.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.tz0.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE.tz1.bin -DATAOUT2=$top_builddir/test/data/$TESTFILE.tz2.bin +DATAOUT0=$top_builddir/test/data/timezone1.test.tz0.bin +DATAOUT1=$top_builddir/test/data/timezone1.test.tz1.bin +DATAOUT2=$top_builddir/test/data/timezone1.test.tz2.bin TZ=UTC $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 TZ=Asia/Singapore $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT1 diff --git a/test/timezone2.test b/test/timezone2.test index 57db720..79db523 100755 --- a/test/timezone2.test +++ b/test/timezone2.test @@ -5,10 +5,10 @@ set -e DATASRC=$top_srcdir/test/data TESTFILE=7.plist DATAIN0=$DATASRC/$TESTFILE -DATAOUT0=$top_builddir/test/data/$TESTFILE.bin -DATAOUT1=$top_builddir/test/data/$TESTFILE.tz0.xml -DATAOUT2=$top_builddir/test/data/$TESTFILE.tz1.xml -DATAOUT3=$top_builddir/test/data/$TESTFILE.tz2.xml +DATAOUT0=$top_builddir/test/data/timezone2.test.bin +DATAOUT1=$top_builddir/test/data/timezone2.test.tz0.xml +DATAOUT2=$top_builddir/test/data/timezone2.test.tz1.xml +DATAOUT3=$top_builddir/test/data/timezone2.test.tz2.xml TZ=UTC $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 diff --git a/test/uid.test b/test/uid.test new file mode 100755 index 0000000..a62756f --- /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/uid.test.out + +echo "Comparing" +$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/uid.test.out |