diff options
author | Jonathan Beck | 2009-02-15 17:15:29 +0100 |
---|---|---|
committer | Jonathan Beck | 2009-02-15 17:15:29 +0100 |
commit | bb3097cb2266b55719b955c93d09a0e2d6f8eccb (patch) | |
tree | 478a6dd7b31b1640d79bc645052fc9843cc74ca1 /test | |
parent | 8e9eb83c2a8cd3b6a6d1943043f1d3b674e82de4 (diff) | |
download | libplist-bb3097cb2266b55719b955c93d09a0e2d6f8eccb.tar.gz libplist-bb3097cb2266b55719b955c93d09a0e2d6f8eccb.tar.bz2 |
Add more regression test and fix Integer and Real type handling.
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 11 | ||||
-rw-r--r-- | test/data/2.plist | 2 | ||||
-rw-r--r-- | test/data/3.plist | 2 | ||||
-rw-r--r-- | test/data/4.plist | 2 | ||||
-rw-r--r-- | test/data/5.plist | 2 | ||||
-rw-r--r-- | test/plist_cmp.c | 138 |
6 files changed, 152 insertions, 5 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b499018..40dc640 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,9 +3,12 @@ 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) @@ -16,3 +19,9 @@ ADD_TEST(Large plist_test data/4.plist) ADD_TEST(Huge plist_test data/5.plist) ADD_TEST(Big_Array plist_test data/6.plist) +ADD_TEST(EmptyCmp plist_cmp data/1.plist data/1.plist.out) +ADD_TEST(SmallCmp plist_cmp data/2.plist data/2.plist.out) +ADD_TEST(MediumCmp plist_cmp data/3.plist data/3.plist.out) +ADD_TEST(LargeCmp plist_cmp data/4.plist data/4.plist.out) +ADD_TEST(HugeCmp plist_cmp data/5.plist data/5.plist.out) +ADD_TEST(Big_ArrayCmp plist_cmp data/6.plist data/6.plist.out) diff --git a/test/data/2.plist b/test/data/2.plist index 7586de0..169b822 100644 --- a/test/data/2.plist +++ b/test/data/2.plist @@ -23,7 +23,7 @@ <key>Some Int</key> <integer>32434543632</integer> <key>Some Real</key> - <real>58654.3476563</real> + <real>58654.347656</real> <key>Some Date</key> <date>2009-02-12T22:23:00Z</date> <key>Some Data</key> diff --git a/test/data/3.plist b/test/data/3.plist index 30d5b3e..6d16191 100644 --- a/test/data/3.plist +++ b/test/data/3.plist @@ -23,7 +23,7 @@ <key>Some Int</key> <integer>32434543632</integer> <key>Some Real</key> - <real>58654.3476563</real> + <real>58654.347656</real> <key>Some Date</key> <date>2009-02-12T22:23:00Z</date> <key>Some Data</key> diff --git a/test/data/4.plist b/test/data/4.plist index 87d6e4c..de7c488 100644 --- a/test/data/4.plist +++ b/test/data/4.plist @@ -23,7 +23,7 @@ <key>Some Int</key> <integer>32434543632</integer> <key>Some Real</key> - <real>58654.3476563</real> + <real>58654.347656</real> <key>Some Date</key> <date>2009-02-12T22:23:00Z</date> <key>Some Data</key> diff --git a/test/data/5.plist b/test/data/5.plist index 388ff85..647c648 100644 --- a/test/data/5.plist +++ b/test/data/5.plist @@ -23,7 +23,7 @@ <key>Some Int</key> <integer>32434543632</integer> <key>Some Real</key> - <real>58654.3476563</real> + <real>58654.347656</real> <key>Some Date</key> <date>2009-02-12T22:23:00Z</date> <key>Some Data</key> diff --git a/test/plist_cmp.c b/test/plist_cmp.c new file mode 100644 index 0000000..1a66119 --- /dev/null +++ b/test/plist_cmp.c @@ -0,0 +1,138 @@ +/* + * 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> + +char compare_plist(plist_t node_l, plist_t node_r) +{ + plist_t cur_l = NULL; + plist_t cur_r = NULL; + int res = 1; + + cur_l = plist_get_first_child(node_l); + cur_r = plist_get_first_child(node_r); + + if ( (!cur_l && cur_r) || (cur_l && !cur_r)) + return 0; + + if ( !cur_l && !cur_r ) + return plist_compare_node_value( node_l, node_r ); + + while(cur_l && cur_r && res) { + + if (!(res = compare_plist(cur_l, cur_r))) + return res; + + cur_l = plist_get_next_sibling(cur_l); + cur_r = plist_get_next_sibling(cur_r); + if ( (!cur_l && cur_r) || (cur_l && !cur_r)) + return 0; + } + + return res; +} + +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"); + return 1; + } + + 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); + + if (!root_node1 || !root_node2) { + printf("PList parsing failed\n"); + return 3; + } + else + 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; +} + |