diff options
Diffstat (limited to 'test')
66 files changed, 1698 insertions, 124 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 4519de0..2e2b04e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,21 +1,69 @@ -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 \ + date_val_test \ + plist_btest \ + plist_jtest \ + plist_otest \ + xml_behavior_test \ + bplist_behavior_test 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 + +date_val_test_SOURCES = date_val.c +date_val_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 + +bplist_behavior_test_SOURCES = bplist_behavior_test.c +bplist_behavior_test_LDADD = $(top_builddir)/src/libplist-2.0.la TESTS = \ + date_val.test \ 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 \ @@ -32,7 +80,22 @@ 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 \ + xml_behavior.test \ + bplist_behavior.test \ + plistutil-streams.test EXTRA_DIST = \ $(TESTS) \ @@ -75,9 +138,21 @@ 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 \ + data/streams.plist -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/bplist_behavior.test b/test/bplist_behavior.test new file mode 100755 index 0000000..130a6a0 --- /dev/null +++ b/test/bplist_behavior.test @@ -0,0 +1,2 @@ +## -*- sh -*- +$top_builddir/test/bplist_behavior_test diff --git a/test/bplist_behavior_test.c b/test/bplist_behavior_test.c new file mode 100644 index 0000000..f7365f1 --- /dev/null +++ b/test/bplist_behavior_test.c @@ -0,0 +1,199 @@ +/* + * bplist_behavior_test.c + * + * Tests binary plist parser behavior around the object data area: + * + * 1) Arrays and dictionaries are parsed correctly for different + * object reference sizes, including sizes that are not a power of 2. + * + * 2) Objects whose data extends beyond the object data area, i.e. + * into the offset table, must cause parsing to fail. This covers + * strings, extended size markers, array references and dictionary + * key/value references. + * + * The binary plists are assembled in memory with a minimal writer so + * each test case only has to specify the object bytes. + */ + +#include <stdio.h> +#include <string.h> +#include <stdint.h> +#include <inttypes.h> + +#include "plist/plist.h" + +#define MAX_BPLIST_SIZE 256 + +static void put_be64(uint8_t *p, uint64_t v) +{ + int i; + for (i = 7; i >= 0; i--) { + p[i] = (uint8_t)(v & 0xFF); + v >>= 8; + } +} + +/* + * Assemble a binary plist from the given object bytes. offsets[] holds the + * start of each object relative to the beginning of objs. A 1 byte offset + * table is placed directly after the objects, followed by the trailer. + */ +static uint32_t build_bplist(uint8_t *out, const uint8_t *objs, size_t objs_len, const uint8_t *offsets, size_t num_objects, uint8_t ref_size, uint64_t root) +{ + size_t len = 0; + size_t i; + memcpy(out, "bplist00", 8); + len = 8; + memcpy(out + len, objs, objs_len); + len += objs_len; + size_t offset_table_offset = len; + for (i = 0; i < num_objects; i++) { + out[len++] = (uint8_t)(8 + offsets[i]); + } + memset(out + len, 0, 6); + out[len + 6] = 1; /* offset size */ + out[len + 7] = ref_size; + put_be64(out + len + 8, num_objects); + put_be64(out + len + 16, root); + put_be64(out + len + 24, offset_table_offset); + len += 32; + return (uint32_t)len; +} + +static int check_int_item(plist_t item, uint64_t expected, const char *name) +{ + uint64_t val = 0; + if (plist_get_node_type(item) != PLIST_INT) { + fprintf(stderr, "%s: expected PLIST_INT item\n", name); + return 0; + } + plist_get_uint_val(item, &val); + if (val != expected) { + fprintf(stderr, "%s: expected %" PRIu64 ", got %" PRIu64 "\n", name, expected, val); + return 0; + } + return 1; +} + +static int test_array_ref_sizes(void) +{ + /* [ 1, 2 ] with 1 byte object references */ + const uint8_t objs1[] = { 0xA2, 0x01, 0x02, 0x10, 0x01, 0x10, 0x02 }; + const uint8_t offs1[] = { 0, 3, 5 }; + /* [ 1, 2 ] with 3 byte object references */ + const uint8_t objs3[] = { 0xA2, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x10, 0x01, 0x10, 0x02 }; + const uint8_t offs3[] = { 0, 7, 9 }; + struct { + const uint8_t *objs; + size_t objs_len; + const uint8_t *offs; + uint8_t ref_size; + } cases[] = { + { objs1, sizeof(objs1), offs1, 1 }, + { objs3, sizeof(objs3), offs3, 3 }, + }; + size_t i; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + uint8_t buf[MAX_BPLIST_SIZE]; + uint32_t len = build_bplist(buf, cases[i].objs, cases[i].objs_len, cases[i].offs, 3, cases[i].ref_size, 0); + plist_t root = NULL; + plist_err_t err = plist_from_bin((const char*)buf, len, &root); + if (err != PLIST_ERR_SUCCESS || !root) { + fprintf(stderr, "array ref_size %u: plist_from_bin failed (err=%d)\n", cases[i].ref_size, err); + plist_free(root); + return 0; + } + if (plist_get_node_type(root) != PLIST_ARRAY || plist_array_get_size(root) != 2) { + fprintf(stderr, "array ref_size %u: expected array with 2 items\n", cases[i].ref_size); + plist_free(root); + return 0; + } + if (!check_int_item(plist_array_get_item(root, 0), 1, "array item 0") || + !check_int_item(plist_array_get_item(root, 1), 2, "array item 1")) { + plist_free(root); + return 0; + } + plist_free(root); + } + return 1; +} + +static int test_dict_ref_size(void) +{ + /* { "a": 5 } with 2 byte object references */ + const uint8_t objs[] = { 0xD1, 0x00, 0x01, 0x00, 0x02, 0x51, 'a', 0x10, 0x05 }; + const uint8_t offs[] = { 0, 5, 7 }; + uint8_t buf[MAX_BPLIST_SIZE]; + uint32_t len = build_bplist(buf, objs, sizeof(objs), offs, 3, 2, 0); + plist_t root = NULL; + plist_err_t err = plist_from_bin((const char*)buf, len, &root); + if (err != PLIST_ERR_SUCCESS || !root) { + fprintf(stderr, "dict ref_size 2: plist_from_bin failed (err=%d)\n", err); + plist_free(root); + return 0; + } + if (plist_get_node_type(root) != PLIST_DICT || plist_dict_get_size(root) != 1) { + fprintf(stderr, "dict ref_size 2: expected dict with 1 entry\n"); + plist_free(root); + return 0; + } + if (!check_int_item(plist_dict_get_item(root, "a"), 5, "dict value")) { + plist_free(root); + return 0; + } + plist_free(root); + return 1; +} + +static int expect_rejected(const uint8_t *objs, size_t objs_len, const uint8_t *offs, size_t num_objects, uint64_t root_index, const char *name) +{ + uint8_t buf[MAX_BPLIST_SIZE]; + uint32_t len = build_bplist(buf, objs, objs_len, offs, num_objects, 1, root_index); + plist_t root = NULL; + plist_err_t err = plist_from_bin((const char*)buf, len, &root); + if (err == PLIST_ERR_SUCCESS || root != NULL) { + fprintf(stderr, "%s: expected failure, got err=%d root=%p\n", name, err, (void*)root); + plist_free(root); + return 0; + } + return 1; +} + +static int test_data_beyond_object_area_is_rejected(void) +{ + int ok = 1; + + /* string claims 5 bytes, only 2 are present before the offset table */ + const uint8_t str_objs[] = { 0x55, 'a', 'b' }; + const uint8_t str_offs[] = { 0 }; + ok &= expect_rejected(str_objs, sizeof(str_objs), str_offs, 1, 0, "truncated string"); + + /* extended size marker, but no size integer before the offset table */ + const uint8_t ext_objs[] = { 0x5F }; + const uint8_t ext_offs[] = { 0 }; + ok &= expect_rejected(ext_objs, sizeof(ext_objs), ext_offs, 1, 0, "missing size integer"); + + /* array claims 3 references, only 2 are present before the offset table */ + const uint8_t arr_objs[] = { 0x10, 0x01, 0x10, 0x02, 0xA3, 0x00, 0x01 }; + const uint8_t arr_offs[] = { 0, 2, 4 }; + ok &= expect_rejected(arr_objs, sizeof(arr_objs), arr_offs, 3, 2, "truncated array references"); + + /* dict has its key reference, but the value reference is missing */ + const uint8_t dict_objs[] = { 0x51, 'a', 0x10, 0x05, 0xD1, 0x00 }; + const uint8_t dict_offs[] = { 0, 2, 4 }; + ok &= expect_rejected(dict_objs, sizeof(dict_objs), dict_offs, 3, 2, "truncated dict references"); + + return ok; +} + +int main(void) +{ + int ok = 1; + + ok &= test_array_ref_sizes(); + ok &= test_dict_ref_size(); + ok &= test_data_beyond_object_area_is_rejected(); + + return ok ? 0 : 1; +} 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/1.plist b/test/data/1.plist index e6e275d..82a112b 100644 --- a/test/data/1.plist +++ b/test/data/1.plist @@ -23,11 +23,11 @@ <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> 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/empty_keys.plist b/test/data/empty_keys.plist index a0107b4..bbc8ee4 100644 --- a/test/data/empty_keys.plist +++ b/test/data/empty_keys.plist @@ -4,5 +4,10 @@ <string>empty key</string> <key><!-- comment --></key> <string>empty key with comment</string> + <key>self-closing</key> + <dict> + <key/> + <string>self-closing empty key</string> + </dict> </dict> </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/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/streams.plist b/test/data/streams.plist new file mode 100644 index 0000000..b46a4af --- /dev/null +++ b/test/data/streams.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"> +<data>DQoa</data> +</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/date_val.c b/test/date_val.c new file mode 100644 index 0000000..127e194 --- /dev/null +++ b/test/date_val.c @@ -0,0 +1,42 @@ +#include <stdio.h> +#include <stdint.h> +#include <plist/plist.h> + +/* plist_get_date_val must return exactly what plist_set_date_val stored, + * including dates before the epoch (negative seconds). */ + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +static int check(int32_t sec, int32_t usec) +{ + int32_t s = 0, u = 0; + plist_t d = plist_new_date(0, 0); + plist_set_date_val(d, sec, usec); + plist_get_date_val(d, &s, &u); + plist_free(d); + if (s != sec || u != usec) { + printf("set(%d, %d) -> get(%d, %d)\n", sec, usec, s, u); + return 1; + } + return 0; +} + +int main(int argc, char** argv) +{ + int err = 0; + int32_t sec, usec; + + err |= check(5, 6); + err |= check(0, 999999); + err |= check(-3, 250000); + err |= check(-1, 1); + err |= check(1000000000, 123456); + for (sec = -2; sec <= 2 && !err; sec++) { + for (usec = 0; usec < 1000000 && !err; usec += 7) { + err |= check(sec, usec); + } + } + return err; +} diff --git a/test/date_val.test b/test/date_val.test new file mode 100755 index 0000000..9cdf504 --- /dev/null +++ b/test/date_val.test @@ -0,0 +1,5 @@ +## -*- sh -*- + +set -e + +$top_builddir/test/date_val_test 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..07a3cb1 --- /dev/null +++ b/test/integer_set.c @@ -0,0 +1,132 @@ +#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; + + plist_free(iii); + + 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..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 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..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 b498e1d..6e94c57 100644 --- a/test/plist_test.c +++ b/test/plist_test.c @@ -66,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); @@ -77,36 +83,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/plistutil-streams.test b/test/plistutil-streams.test new file mode 100755 index 0000000..ce3c516 --- /dev/null +++ b/test/plistutil-streams.test @@ -0,0 +1,34 @@ +## -*- sh -*- +set -e + +DATASRC=$top_srcdir/test/data +DATAOUT=$top_builddir/test/data +PLISTUTIL=$top_builddir/tools/plistutil +TESTFILE=$DATAOUT/plistutil-streams.test + +mkdir -p "$DATAOUT" + +# The data contains CR, LF and Ctrl-Z, which Windows text streams translate. +"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin -o "$TESTFILE.bin" +"$PLISTUTIL" -i "$TESTFILE.bin" -f xml -o "$TESTFILE.xml" + +echo "Checking binary stdout" +"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin > "$TESTFILE.stdout.out" +cmp "$TESTFILE.bin" "$TESTFILE.stdout.out" +"$PLISTUTIL" -i "$DATASRC/streams.plist" -f bin -o - > "$TESTFILE.stdout.out" +cmp "$TESTFILE.bin" "$TESTFILE.stdout.out" + +echo "Checking binary stdin" +"$PLISTUTIL" -f xml -o "$TESTFILE.stdin.out" < "$TESTFILE.bin" +cmp "$TESTFILE.xml" "$TESTFILE.stdin.out" +cat "$TESTFILE.bin" | "$PLISTUTIL" -i - -f xml -o "$TESTFILE.stdin.out" +cmp "$TESTFILE.xml" "$TESTFILE.stdin.out" + +echo "Checking binary stdin in print mode" +"$PLISTUTIL" -p "$TESTFILE.bin" > "$TESTFILE.print.out" +cat "$TESTFILE.bin" | "$PLISTUTIL" -p - > "$TESTFILE.stdin.out" +cmp "$TESTFILE.print.out" "$TESTFILE.stdin.out" + +echo "Checking XML stdout" +"$PLISTUTIL" -i "$TESTFILE.bin" -f xml > "$TESTFILE.stdout.out" +cmp "$TESTFILE.xml" "$TESTFILE.stdout.out" 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 dc752df..52f7080 100755 --- a/test/signedunsigned1.test +++ b/test/signedunsigned1.test @@ -13,11 +13,11 @@ 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 $DATACMP0 $DATAOUT0 -diff $DATACMP1 $DATAOUT1 +diff --strip-trailing-cr $DATACMP0 $DATAOUT0 +diff --strip-trailing-cr $DATACMP1 $DATAOUT1 diff --git a/test/signedunsigned2.test b/test/signedunsigned2.test index d51219f..192f1a6 100755 --- a/test/signedunsigned2.test +++ b/test/signedunsigned2.test @@ -13,11 +13,11 @@ 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 $DATACMP0 $DATAOUT0 -diff $DATACMP1 $DATAOUT1 +diff --strip-trailing-cr $DATACMP0 $DATAOUT0 +diff --strip-trailing-cr $DATACMP1 $DATAOUT1 diff --git a/test/signedunsigned3.test b/test/signedunsigned3.test index 9bada3e..87bdcbc 100755 --- a/test/signedunsigned3.test +++ b/test/signedunsigned3.test @@ -13,11 +13,11 @@ 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 $DATACMP0 $DATAOUT0 -diff $DATACMP1 $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 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 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; +} |
