diff options
Diffstat (limited to 'test')
100 files changed, 1934 insertions, 99 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 1b3d2f7..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ - -#build the test executable -INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/libcnary/include ) - -SET(plist_test_SRC - plist_test.c) -SET(plist_cmp_SRC - plist_cmp.c) -ADD_EXECUTABLE(plist_test ${plist_test_SRC}) -TARGET_LINK_LIBRARIES(plist_test plist) -ADD_EXECUTABLE(plist_cmp ${plist_cmp_SRC}) -TARGET_LINK_LIBRARIES(plist_cmp plist) - -INCLUDE(CTest) - -SET(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -ADD_TEST(Empty plist_test ${TEST_DATA_DIR}/data/1.plist) -ADD_TEST(Small plist_test ${TEST_DATA_DIR}/data/2.plist) -ADD_TEST(Medium plist_test ${TEST_DATA_DIR}/data/3.plist) -ADD_TEST(Large plist_test ${TEST_DATA_DIR}/data/4.plist) -ADD_TEST(Huge plist_test ${TEST_DATA_DIR}/data/5.plist) -ADD_TEST(Big_Array plist_test ${TEST_DATA_DIR}/data/6.plist) - -ADD_TEST(EmptyCmp plist_cmp ${TEST_DATA_DIR}/data/1.plist ${TEST_DATA_DIR}/data/1.plist.out) -ADD_TEST(SmallCmp plist_cmp ${TEST_DATA_DIR}/data/2.plist ${TEST_DATA_DIR}/data/2.plist.out) -ADD_TEST(MediumCmp plist_cmp ${TEST_DATA_DIR}/data/3.plist ${TEST_DATA_DIR}/data/3.plist.out) -ADD_TEST(LargeCmp plist_cmp ${TEST_DATA_DIR}/data/4.plist ${TEST_DATA_DIR}/data/4.plist.out) -ADD_TEST(HugeCmp plist_cmp ${TEST_DATA_DIR}/data/5.plist ${TEST_DATA_DIR}/data/5.plist.out) -ADD_TEST(Big_ArrayCmp plist_cmp ${TEST_DATA_DIR}/data/6.plist ${TEST_DATA_DIR}/data/6.plist.out) diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..f9f21e4 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,146 @@ +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 \ + plist_test++ \ + integer_set_test \ + plist_btest \ + plist_jtest \ + plist_otest \ + xml_behavior_test + +plist_cmp_SOURCES = plist_cmp.c +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-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 + +xml_behavior_test_SOURCES = xml_behavior_test.c +xml_behavior_test_LDADD = $(top_builddir)/src/libplist-2.0.la + +TESTS = \ + empty.test \ + small.test \ + medium.test \ + large.test \ + huge.test \ + bigarray.test \ + empty++.test \ + small++.test \ + medium++.test \ + large++.test \ + huge++.test \ + bigarray++.test \ + dates.test \ + timezone1.test \ + timezone2.test \ + signedunsigned1.test \ + signedunsigned2.test \ + signedunsigned3.test \ + hex.test \ + order.test \ + recursion.test \ + entities.test \ + empty_keys.test \ + amp.test \ + invalid_tag.test \ + cdata.test \ + offsetsize.test \ + refsize.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 \ + xml_behavior.test + +EXTRA_DIST = \ + $(TESTS) \ + data/1.plist \ + data/2.plist \ + data/3.plist \ + data/4.plist \ + data/5.plist \ + data/6.plist \ + data/7.plist \ + data/amp.plist \ + data/cdata.plist \ + data/dictref1byte.bplist \ + data/dictref2bytes.bplist \ + data/dictref3bytes.bplist \ + data/dictref4bytes.bplist \ + data/dictref5bytes.bplist \ + data/dictref6bytes.bplist \ + data/dictref7bytes.bplist \ + data/dictref8bytes.bplist \ + data/empty_keys.plist \ + data/entities.plist \ + data/hex.plist \ + data/invalid_tag.plist \ + data/malformed_dict.bplist \ + data/off1byte.bplist \ + data/off2bytes.bplist \ + data/off3bytes.bplist \ + data/off4bytes.bplist \ + data/off5bytes.bplist \ + data/off6bytes.bplist \ + data/off7bytes.bplist \ + data/off8bytes.bplist \ + data/offxml.plist \ + data/order.bplist \ + data/order.plist \ + data/recursion.bplist \ + data/signed.bplist \ + data/signed.plist \ + data/signedunsigned.bplist \ + data/signedunsigned.plist \ + data/unsigned.bplist \ + 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) + +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 new file mode 100755 index 0000000..3678f27 --- /dev/null +++ b/test/amp.test @@ -0,0 +1,16 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +TESTFILE=amp.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/amp.test.out + +rm -rf $DATAOUT0 +$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/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 new file mode 100755 index 0000000..1b88d43 --- /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/cdata.test b/test/cdata.test new file mode 100755 index 0000000..b4f3ed2 --- /dev/null +++ b/test/cdata.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=cdata.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/cdata.test.bin + +$top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 + +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT0 diff --git a/test/data/1.plist b/test/data/1.plist index c7135e9..82a112b 100644 --- a/test/data/1.plist +++ b/test/data/1.plist @@ -16,20 +16,20 @@ <string></string> <string></string> </array> + <key>Keys & "entities"</key> + <string/> <key>Boolean</key> <false/> <key>Another Boolean</key> <true/> <key>Some Int</key> - <integer></integer> + <integer>0</integer> <key>Some Real</key> - <real></real> + <real>1e4</real> <key>Some Date</key> - <date></date> + <date>1970-01-01T00:00:00Z</date> <key>Some Data</key> <data> </data> - <key>Some Entities</key> - <string>hellow world & others <nodes> are "fun!?'</string> </dict> </plist> diff --git a/test/data/2.plist b/test/data/2.plist index 169b822..7c62067 100644 --- a/test/data/2.plist +++ b/test/data/2.plist @@ -16,6 +16,8 @@ <string>język polski</string> <string>हिन्दी</string> </array> + <key>Keys & "entities"</key> + <string>hellow world & others <nodes> are "fun!?'</string> <key>Boolean</key> <false/> <key>Another Boolean</key> diff --git a/test/data/3.plist b/test/data/3.plist index 6d16191..249e7ce 100644 --- a/test/data/3.plist +++ b/test/data/3.plist @@ -16,6 +16,8 @@ <string>język polski</string> <string>हिन्दी</string> </array> + <key>Keys & "entities"</key> + <string>hellow world & others <nodes> are "fun!?'</string> <key>Boolean</key> <false/> <key>Another Boolean</key> diff --git a/test/data/4.plist b/test/data/4.plist index de7c488..a04a292 100644 --- a/test/data/4.plist +++ b/test/data/4.plist @@ -16,6 +16,8 @@ <string>język polski</string> <string>हिन्दी</string> </array> + <key>Keys & "entities"</key> + <string>hellow world & others <nodes> are "fun!?'</string> <key>Boolean</key> <false/> <key>Another Boolean</key> diff --git a/test/data/5.plist b/test/data/5.plist index 647c648..9dc9109 100644 --- a/test/data/5.plist +++ b/test/data/5.plist @@ -16,6 +16,8 @@ <string>język polski</string> <string>हिन्दी</string> </array> + <key>Keys & "entities"</key> + <string>hellow world & others <nodes> are "fun!?'</string> <key>Boolean</key> <false/> <key>Another Boolean</key> diff --git a/test/data/7.plist b/test/data/7.plist new file mode 100644 index 0000000..d8b441d --- /dev/null +++ b/test/data/7.plist @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>Time1</key> + <date>2010-11-12T13:14:15Z</date> + <key>Time2</key> + <date>2008-07-06T05:04:03Z</date> + <key>Time3</key> + <date>1869-01-03T08:16:32Z</date> + <key>Time4</key> + <date>2199-08-20T01:10:11Z</date> +</dict> +</plist> diff --git a/test/data/amp.plist b/test/data/amp.plist new file mode 100644 index 0000000..ce9e7ac --- /dev/null +++ b/test/data/amp.plist @@ -0,0 +1,6 @@ +<plist version="1.0"> +<dict> + <key>test&</key> + <string>value</string> +</dict> +</plist> diff --git a/test/data/cdata.plist b/test/data/cdata.plist new file mode 100644 index 0000000..dcd015f --- /dev/null +++ b/test/data/cdata.plist @@ -0,0 +1,6 @@ +<plist version="1.0"> +<dict> + <key><![CDATA[cdata&key]]></key> + <string>string with cdata content: <![CDATA[ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~]]> !!!</string> +</dict> +</plist> 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/dictref1byte.bplist b/test/data/dictref1byte.bplist Binary files differnew file mode 100644 index 0000000..c33d70b --- /dev/null +++ b/test/data/dictref1byte.bplist diff --git a/test/data/dictref2bytes.bplist b/test/data/dictref2bytes.bplist Binary files differnew file mode 100644 index 0000000..2a5225f --- /dev/null +++ b/test/data/dictref2bytes.bplist diff --git a/test/data/dictref3bytes.bplist b/test/data/dictref3bytes.bplist Binary files differnew file mode 100644 index 0000000..fb34258 --- /dev/null +++ b/test/data/dictref3bytes.bplist diff --git a/test/data/dictref4bytes.bplist b/test/data/dictref4bytes.bplist Binary files differnew file mode 100644 index 0000000..5845107 --- /dev/null +++ b/test/data/dictref4bytes.bplist diff --git a/test/data/dictref5bytes.bplist b/test/data/dictref5bytes.bplist Binary files differnew file mode 100644 index 0000000..6ced9de --- /dev/null +++ b/test/data/dictref5bytes.bplist diff --git a/test/data/dictref6bytes.bplist b/test/data/dictref6bytes.bplist Binary files differnew file mode 100644 index 0000000..2ed5f34 --- /dev/null +++ b/test/data/dictref6bytes.bplist diff --git a/test/data/dictref7bytes.bplist b/test/data/dictref7bytes.bplist Binary files differnew file mode 100644 index 0000000..cbb9368 --- /dev/null +++ b/test/data/dictref7bytes.bplist diff --git a/test/data/dictref8bytes.bplist b/test/data/dictref8bytes.bplist Binary files differnew file mode 100644 index 0000000..ffb4292 --- /dev/null +++ b/test/data/dictref8bytes.bplist diff --git a/test/data/empty_keys.plist b/test/data/empty_keys.plist new file mode 100644 index 0000000..a0107b4 --- /dev/null +++ b/test/data/empty_keys.plist @@ -0,0 +1,8 @@ +<plist version="1.0"> +<dict> + <key></key> + <string>empty key</string> + <key><!-- comment --></key> + <string>empty key with comment</string> +</dict> +</plist> diff --git a/test/data/entities.plist b/test/data/entities.plist new file mode 100644 index 0000000..d7655d6 --- /dev/null +++ b/test/data/entities.plist @@ -0,0 +1,57 @@ +<plist version="1.0"> +<dict> + <key>some test entitites</key> + <dict> + <key>copyright</key> + <string>©</string> + <key>multiple entitites</key> + <string>⼠⼡⼢</string> + <key>multiple entitites with characters inbetween</key> + <string>a⼣b⼤c⼥d</string> + </dict> + <key>one byte entity</key> + <dict> + <key>one byte entity</key> + <string>@</string> + <key>one byte entity with text after</key> + <string>@z</string> + <key>one byte entity with text before</key> + <string>a@</string> + <key>one byte entity with text before & after</key> + <string>a@z</string> + </dict> + <key>two-byte utf-8</key> + <dict> + <key>two-byte utf-8</key> + <string>Ä</string> + <key>two-byte utf-8 with text after</key> + <string>Ëyz</string> + <key>two-byte utf-8 with text before</key> + <string>abÖ</string> + <key>two-byte utf-8 with text before & after</key> + <string>abÜyz</string> + </dict> + <key>three byte utf-8</key> + <dict> + <key>three byte utf-8</key> + <string>¢</string> + <key>three byte utf-8 with text after</key> + <string>£xyz</string> + <key>three byte utf-8 with text before</key> + <string>abc¥</string> + <key>three byte utf-8 with text before & after</key> + <string>abc₩xyz</string> + </dict> + <key>four byte utf-8</key> + <dict> + <key>four byte utf-8</key> + <string>𝕢</string> + <key>four byte utf-8 with text after</key> + <string>𝕣wxyz</string> + <key>four byte utf-8 with text before</key> + <string>abcd𝕤</string> + <key>four byte utf-8 with text before & after</key> + <string>abcd𝕥wxyz</string> + </dict> +</dict> +</plist> diff --git a/test/data/hex.plist b/test/data/hex.plist new file mode 100644 index 0000000..ae2d2b0 --- /dev/null +++ b/test/data/hex.plist @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<integer>0x73709551615</integer> +</plist> 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/invalid_tag.plist b/test/data/invalid_tag.plist new file mode 100644 index 0000000..feb770f --- /dev/null +++ b/test/data/invalid_tag.plist @@ -0,0 +1,6 @@ +<plist version="1.0"> +<dict> + <key>test<!test></key> + <string>value</string> +</dict> +</plist> 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/malformed_dict.bplist b/test/data/malformed_dict.bplist Binary files differnew file mode 100644 index 0000000..0de4cd7 --- /dev/null +++ b/test/data/malformed_dict.bplist 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/off1byte.bplist b/test/data/off1byte.bplist Binary files differnew file mode 100644 index 0000000..c33d70b --- /dev/null +++ b/test/data/off1byte.bplist diff --git a/test/data/off2bytes.bplist b/test/data/off2bytes.bplist Binary files differnew file mode 100644 index 0000000..f080738 --- /dev/null +++ b/test/data/off2bytes.bplist diff --git a/test/data/off3bytes.bplist b/test/data/off3bytes.bplist Binary files differnew file mode 100644 index 0000000..a2f926b --- /dev/null +++ b/test/data/off3bytes.bplist diff --git a/test/data/off4bytes.bplist b/test/data/off4bytes.bplist Binary files differnew file mode 100644 index 0000000..35897be --- /dev/null +++ b/test/data/off4bytes.bplist diff --git a/test/data/off5bytes.bplist b/test/data/off5bytes.bplist Binary files differnew file mode 100644 index 0000000..9df03cd --- /dev/null +++ b/test/data/off5bytes.bplist diff --git a/test/data/off6bytes.bplist b/test/data/off6bytes.bplist Binary files differnew file mode 100644 index 0000000..3d78a47 --- /dev/null +++ b/test/data/off6bytes.bplist diff --git a/test/data/off7bytes.bplist b/test/data/off7bytes.bplist Binary files differnew file mode 100644 index 0000000..150c277 --- /dev/null +++ b/test/data/off7bytes.bplist diff --git a/test/data/off8bytes.bplist b/test/data/off8bytes.bplist Binary files differnew file mode 100644 index 0000000..f01114e --- /dev/null +++ b/test/data/off8bytes.bplist diff --git a/test/data/offxml.plist b/test/data/offxml.plist new file mode 100644 index 0000000..c3c1e10 --- /dev/null +++ b/test/data/offxml.plist @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>A</key> + <string>B</string> +</dict> +</plist> diff --git a/test/data/order.bplist b/test/data/order.bplist Binary files differnew file mode 100644 index 0000000..5ea86f8 --- /dev/null +++ b/test/data/order.bplist diff --git a/test/data/order.plist b/test/data/order.plist new file mode 100644 index 0000000..b2cbdcb --- /dev/null +++ b/test/data/order.plist @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>test</key> + <array> + <integer>1</integer> + <integer>1</integer> + </array> + <key>foo</key> + <array> + <array> + <integer>1</integer> + </array> + <dict> + <key>test</key> + <string>foo</string> + </dict> + <array> + <integer>1</integer> + </array> + <array> + <integer>1</integer> + </array> + </array> +</dict> +</plist> diff --git a/test/data/recursion.bplist b/test/data/recursion.bplist Binary files differnew file mode 100644 index 0000000..3f4b42a --- /dev/null +++ b/test/data/recursion.bplist diff --git a/test/data/signed.bplist b/test/data/signed.bplist Binary files differnew file mode 100644 index 0000000..89bf362 --- /dev/null +++ b/test/data/signed.bplist diff --git a/test/data/signed.plist b/test/data/signed.plist new file mode 100644 index 0000000..c7d2991 --- /dev/null +++ b/test/data/signed.plist @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<integer>-1</integer> +</plist> diff --git a/test/data/signedunsigned.bplist b/test/data/signedunsigned.bplist Binary files differnew file mode 100644 index 0000000..f361063 --- /dev/null +++ b/test/data/signedunsigned.bplist diff --git a/test/data/signedunsigned.plist b/test/data/signedunsigned.plist new file mode 100644 index 0000000..2942529 --- /dev/null +++ b/test/data/signedunsigned.plist @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<array> + <integer>-1</integer> + <integer>18446744073709551615</integer> + <integer>9223372036854775807</integer> + <integer>-9223372036854775808</integer> + <integer>9223372036854775808</integer> +</array> +</plist> 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/data/unsigned.bplist b/test/data/unsigned.bplist Binary files differnew file mode 100644 index 0000000..2b0a807 --- /dev/null +++ b/test/data/unsigned.bplist diff --git a/test/data/unsigned.plist b/test/data/unsigned.plist new file mode 100644 index 0000000..f08d1b7 --- /dev/null +++ b/test/data/unsigned.plist @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<integer>18446744073709551615</integer> +</plist> diff --git a/test/dates.test b/test/dates.test new file mode 100755 index 0000000..06bf034 --- /dev/null +++ b/test/dates.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=7.plist +DATAIN0=$DATASRC/$TESTFILE +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 + +$top_builddir/test/plist_cmp $DATAOUT0 $DATAIN0 +$top_builddir/test/plist_cmp $DATAOUT1 $DATAIN0 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 new file mode 100755 index 0000000..bc71562 --- /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_keys.test b/test/empty_keys.test new file mode 100755 index 0000000..19bbb08 --- /dev/null +++ b/test/empty_keys.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=empty_keys.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/empty_keys.test.bin + +$top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 + +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT0 diff --git a/test/entities.test b/test/entities.test new file mode 100755 index 0000000..a828e15 --- /dev/null +++ b/test/entities.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=entities.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/entities.test.bin + +$top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 + +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT0 diff --git a/test/hex.test b/test/hex.test new file mode 100755 index 0000000..414cdbc --- /dev/null +++ b/test/hex.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=hex.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/hex.test.bin + +$top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 + +$top_builddir/test/plist_cmp $DATAIN0 $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 new file mode 100755 index 0000000..560c21f --- /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/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 new file mode 100755 index 0000000..5d4da93 --- /dev/null +++ b/test/invalid_tag.test @@ -0,0 +1,16 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +TESTFILE=invalid_tag.plist +DATAIN0=$DATASRC/$TESTFILE +DATAOUT0=$top_builddir/test/data/invalid_tag.test.out + +rm -rf $DATAOUT0 +$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/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..a21fcd9 --- /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 [ $? -ne 2 ]; then + exit 1 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE1 -o /dev/null +if [ $? -ne 2 ]; then + exit 2 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f json -i $DATASRC/$TESTFILE2 -o /dev/null +if [ $? -ne 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 new file mode 100755 index 0000000..d3cce7a --- /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/malformed_dict.test b/test/malformed_dict.test new file mode 100755 index 0000000..1d3ba2b --- /dev/null +++ b/test/malformed_dict.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +TESTFILE=malformed_dict.bplist +DATAIN0=$DATASRC/$TESTFILE +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 new file mode 100755 index 0000000..300c016 --- /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/offsetsize.test b/test/offsetsize.test new file mode 100755 index 0000000..d548d88 --- /dev/null +++ b/test/offsetsize.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILES="off1byte.bplist off2bytes.bplist off3bytes.bplist off4bytes.bplist off5bytes.bplist off6bytes.bplist off7bytes.bplist off8bytes.bplist" +CMPFILE=offxml.plist + +for I in $TESTFILES; do + echo "* checking $I" + $top_builddir/test/plist_cmp $DATASRC/$I $DATASRC/$CMPFILE +done diff --git a/test/order.test b/test/order.test new file mode 100755 index 0000000..bd89b9d --- /dev/null +++ b/test/order.test @@ -0,0 +1,13 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=order.bplist +DATAIN0=$DATASRC/$TESTFILE +DATAIN1=$DATASRC/order.plist +DATAOUT0=$top_builddir/test/data/order.test.out + +$top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT0 + +$top_builddir/test/plist_cmp $DATAIN1 $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..3ae376c --- /dev/null +++ b/test/ostep-invalid-types.test @@ -0,0 +1,32 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +TESTFILE1=7.plist +TESTFILE2=uid.bplist + +if ! test -d "$DATAOUT"; then + mkdir -p $DATAOUT +fi + +export PLIST_OSTEP_DEBUG=1 + +echo "Converting (failure expected)" +echo '[true]' |$top_builddir/tools/plistutil -f openstep -i - -o /dev/null +if [ $? -ne 2 ]; then + exit 1 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f openstepn -i $DATASRC/$TESTFILE1 -o /dev/null +if [ $? -ne 2 ]; then + exit 2 +fi + +echo "Converting (failure expected)" +$top_builddir/tools/plistutil -f openstep -i $DATASRC/$TESTFILE2 -o /dev/null +if [ $? -ne 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..32ba364 --- /dev/null +++ b/test/plist_btest.c @@ -0,0 +1,137 @@ +/* + * 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)); + if (fread(plist_bin, sizeof(char), size_in, iplist) != (size_t)size_in) { + printf("Failed to read input file\n"); + fclose(iplist); + free(plist_bin); + free(filestats); + return 3; + } + 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..570886d --- /dev/null +++ b/test/plist_jtest.c @@ -0,0 +1,137 @@ +/* + * 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)); + if (fread(plist_json, sizeof(char), size_in, iplist) != (size_t)size_in) { + printf("Failed to read input file\n"); + fclose(iplist); + free(plist_json); + free(filestats); + return 3; + } + 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..b2d1c94 --- /dev/null +++ b/test/plist_otest.c @@ -0,0 +1,135 @@ +/* + * 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)); + if (fread(plist_ostep, sizeof(char), size_in, iplist) != (size_t)size_in) { + printf("Failed to read input file\n"); + fclose(iplist); + free(plist_ostep); + return 3; + } + 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 17be11a..6e94c57 100644 --- a/test/plist_test.c +++ b/test/plist_test.c @@ -44,14 +44,16 @@ int main(int argc, char *argv[]) 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!= 2) + 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"); @@ -64,7 +66,13 @@ int main(int argc, char *argv[]) stat(file_in, filestats); size_in = filestats->st_size; plist_xml = (char *) malloc(sizeof(char) * (size_in + 1)); - fread(plist_xml, sizeof(char), size_in, iplist); + if (fread(plist_xml, sizeof(char), size_in, iplist) != (size_t)size_in) { + printf("Failed to read input file\n"); + fclose(iplist); + free(plist_xml); + free(filestats); + return 3; + } fclose(iplist); @@ -75,41 +83,35 @@ 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; - char file_out[512]; - sprintf(file_out, "%s.out", file_in); oplist = fopen(file_out, "wb"); fwrite(plist_xml2, size_out2, sizeof(char), oplist); fclose(oplist); diff --git a/test/recursion.test b/test/recursion.test new file mode 100755 index 0000000..97bfb45 --- /dev/null +++ b/test/recursion.test @@ -0,0 +1,15 @@ +## -*- sh -*- + +DATASRC=$top_srcdir/test/data +TESTFILE=recursion.bplist +DATAIN0=$DATASRC/$TESTFILE +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/refsize.test b/test/refsize.test new file mode 100755 index 0000000..379b7fb --- /dev/null +++ b/test/refsize.test @@ -0,0 +1,12 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILES="dictref1byte.bplist dictref2bytes.bplist dictref3bytes.bplist dictref4bytes.bplist dictref5bytes.bplist dictref6bytes.bplist dictref7bytes.bplist dictref8bytes.bplist" +CMPFILE=offxml.plist + +for I in $TESTFILES; do + echo "* checking $I" + $top_builddir/test/plist_cmp $DATASRC/$I $DATASRC/$CMPFILE +done diff --git a/test/signedunsigned1.test b/test/signedunsigned1.test new file mode 100755 index 0000000..52f7080 --- /dev/null +++ b/test/signedunsigned1.test @@ -0,0 +1,23 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE0=signed.plist +TESTFILE1=unsigned.plist +DATAIN0=$DATASRC/$TESTFILE0 +DATAIN1=$DATASRC/$TESTFILE1 + +CMPFILE0=signed.bplist +CMPFILE1=unsigned.bplist +DATACMP0=$DATASRC/$CMPFILE0 +DATACMP1=$DATASRC/$CMPFILE1 + +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 --strip-trailing-cr $DATACMP0 $DATAOUT0 +diff --strip-trailing-cr $DATACMP1 $DATAOUT1 diff --git a/test/signedunsigned2.test b/test/signedunsigned2.test new file mode 100755 index 0000000..192f1a6 --- /dev/null +++ b/test/signedunsigned2.test @@ -0,0 +1,23 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE0=signed.bplist +TESTFILE1=unsigned.bplist +DATAIN0=$DATASRC/$TESTFILE0 +DATAIN1=$DATASRC/$TESTFILE1 + +CMPFILE0=signed.plist +CMPFILE1=unsigned.plist +DATACMP0=$DATASRC/$CMPFILE0 +DATACMP1=$DATASRC/$CMPFILE1 + +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 --strip-trailing-cr $DATACMP0 $DATAOUT0 +diff --strip-trailing-cr $DATACMP1 $DATAOUT1 diff --git a/test/signedunsigned3.test b/test/signedunsigned3.test new file mode 100755 index 0000000..87bdcbc --- /dev/null +++ b/test/signedunsigned3.test @@ -0,0 +1,23 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE0=signedunsigned.plist +TESTFILE1=signedunsigned.bplist +DATAIN0=$DATASRC/$TESTFILE0 +DATAIN1=$DATASRC/$TESTFILE1 + +CMPFILE0=signedunsigned.bplist +CMPFILE1=signedunsigned.plist +DATACMP0=$DATASRC/$CMPFILE0 +DATACMP1=$DATASRC/$CMPFILE1 + +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 --strip-trailing-cr $DATACMP0 $DATAOUT0 +diff --strip-trailing-cr $DATACMP1 $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 new file mode 100755 index 0000000..dd2faf8 --- /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/timezone1.test b/test/timezone1.test new file mode 100755 index 0000000..5de7cea --- /dev/null +++ b/test/timezone1.test @@ -0,0 +1,17 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=7.plist +DATAIN0=$DATASRC/$TESTFILE +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 +TZ=US/Pacific $top_builddir/tools/plistutil -i $DATAIN0 -o $DATAOUT2 + +$top_builddir/test/plist_cmp $DATAOUT0 $DATAOUT1 +$top_builddir/test/plist_cmp $DATAOUT0 $DATAOUT2 diff --git a/test/timezone2.test b/test/timezone2.test new file mode 100755 index 0000000..79db523 --- /dev/null +++ b/test/timezone2.test @@ -0,0 +1,21 @@ +## -*- sh -*- + +set -e + +DATASRC=$top_srcdir/test/data +TESTFILE=7.plist +DATAIN0=$DATASRC/$TESTFILE +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 + +TZ=UTC $top_builddir/tools/plistutil -i $DATAOUT0 -o $DATAOUT1 +TZ=Asia/Singapore $top_builddir/tools/plistutil -i $DATAOUT0 -o $DATAOUT2 +TZ=US/Pacific $top_builddir/tools/plistutil -i $DATAOUT0 -o $DATAOUT3 + +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT1 +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT2 +$top_builddir/test/plist_cmp $DATAIN0 $DATAOUT3 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 diff --git a/test/xml_behavior.test b/test/xml_behavior.test new file mode 100755 index 0000000..81d8dd0 --- /dev/null +++ b/test/xml_behavior.test @@ -0,0 +1,2 @@ +## -*- sh -*- +$top_builddir/test/xml_behavior_test diff --git a/test/xml_behavior_test.c b/test/xml_behavior_test.c new file mode 100644 index 0000000..94d8a7f --- /dev/null +++ b/test/xml_behavior_test.c @@ -0,0 +1,167 @@ +/* + * xml_behavior_test.c + * + * Tests XML parser behavior for correctness and specification compliance: + * + * 1) A <plist> element must contain exactly one root value node. + * Any additional value nodes after the first root object must + * cause parsing to fail. + * + * 2) Dictionaries of the form: + * <dict> + * <key>CF$UID</key> + * <integer>...</integer> + * </dict> + * must be converted to PLIST_UID nodes during XML parsing, + * including when they appear nested inside other containers. + * + * These tests ensure proper root handling and UID node conversion + * when parsing XML property lists. + */ + +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <inttypes.h> + +#include "plist/plist.h" + +static int test_nested_cfuid_converts_to_uid(void) +{ + const char *xml = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " + "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" + "<plist version=\"1.0\">" + " <dict>" + " <key>obj</key>" + " <dict>" + " <key>CF$UID</key>" + " <integer>7</integer>" + " </dict>" + " </dict>" + "</plist>"; + + plist_t root = NULL; + plist_err_t err = plist_from_xml(xml, (uint32_t)strlen(xml), &root); + if (err != PLIST_ERR_SUCCESS || !root) { + fprintf(stderr, "nested CF$UID: plist_from_xml failed (err=%d)\n", err); + plist_free(root); + return 0; + } + + if (plist_get_node_type(root) != PLIST_DICT) { + fprintf(stderr, "nested CF$UID: root is not dict\n"); + plist_free(root); + return 0; + } + + plist_t obj = plist_dict_get_item(root, "obj"); + if (!obj) { + fprintf(stderr, "nested CF$UID: missing key 'obj'\n"); + plist_free(root); + return 0; + } + + if (plist_get_node_type(obj) != PLIST_UID) { + fprintf(stderr, "nested CF$UID: expected PLIST_UID, got %d\n", + plist_get_node_type(obj)); + plist_free(root); + return 0; + } + + uint64_t uid = 0; + plist_get_uid_val(obj, &uid); + if (uid != 7) { + fprintf(stderr, "nested CF$UID: expected uid=7, got %" PRIu64 "\n", uid); + plist_free(root); + return 0; + } + + plist_free(root); + return 1; +} + +static int test_extra_root_value_is_rejected(void) +{ + /* Two root values inside <plist> must be rejected */ + const char *xml = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<plist version=\"1.0\">" + " <string>one</string>" + " <string>two</string>" + "</plist>"; + + plist_t root = NULL; + plist_err_t err = plist_from_xml(xml, (uint32_t)strlen(xml), &root); + + /* Must fail, and root must be NULL (consistent with other parsers) */ + if (err == PLIST_ERR_SUCCESS || root != NULL) { + fprintf(stderr, "extra root value: expected failure, got err=%d root=%p\n", + err, (void*)root); + plist_free(root); + return 0; + } + return 1; +} + +static int test_scalar_then_extra_node_is_rejected(void) +{ + /* Scalar root followed by another node must be rejected */ + const char *xml = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<plist version=\"1.0\">" + " <true/>" + " <dict><key>A</key><string>x</string></dict>" + "</plist>"; + + plist_t root = NULL; + plist_err_t err = plist_from_xml(xml, (uint32_t)strlen(xml), &root); + + if (err == PLIST_ERR_SUCCESS || root != NULL) { + fprintf(stderr, "scalar then extra node: expected failure, got err=%d root=%p\n", + err, (void*)root); + plist_free(root); + return 0; + } + return 1; +} + +static int test_scalar_with_comment_is_ok(void) +{ + /* Comment after the single root value is not an extra value node */ + const char *xml = + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<plist version=\"1.0\">" + " <string>ok</string>" + " <!-- trailing comment -->" + "</plist>"; + + plist_t root = NULL; + plist_err_t err = plist_from_xml(xml, (uint32_t)strlen(xml), &root); + if (err != PLIST_ERR_SUCCESS || !root) { + fprintf(stderr, "scalar + comment: expected success, got err=%d\n", err); + plist_free(root); + return 0; + } + if (plist_get_node_type(root) != PLIST_STRING) { + fprintf(stderr, "scalar + comment: expected root string, got %d\n", + plist_get_node_type(root)); + plist_free(root); + return 0; + } + plist_free(root); + return 1; +} + +int main(void) +{ + int ok = 1; + + ok &= test_nested_cfuid_converts_to_uid(); + ok &= test_extra_root_value_is_rejected(); + ok &= test_scalar_then_extra_node_is_rejected(); + ok &= test_scalar_with_comment_is_ok(); + + return ok ? 0 : 1; +} |
