diff options
| author | 2009-02-15 17:15:29 +0100 | |
|---|---|---|
| committer | 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 @@ | |||
| 3 | 3 | ||
| 4 | SET(plist_test_SRC | 4 | SET(plist_test_SRC |
| 5 | plist_test.c) | 5 | plist_test.c) |
| 6 | SET(plist_cmp_SRC | ||
| 7 | plist_cmp.c) | ||
| 6 | ADD_EXECUTABLE(plist_test ${plist_test_SRC}) | 8 | ADD_EXECUTABLE(plist_test ${plist_test_SRC}) |
| 7 | TARGET_LINK_LIBRARIES(plist_test plist) | 9 | TARGET_LINK_LIBRARIES(plist_test plist) |
| 8 | 10 | ADD_EXECUTABLE(plist_cmp ${plist_cmp_SRC}) | |
| 11 | TARGET_LINK_LIBRARIES(plist_cmp plist) | ||
| 9 | 12 | ||
| 10 | INCLUDE(CTest) | 13 | INCLUDE(CTest) |
| 11 | 14 | ||
| @@ -16,3 +19,9 @@ ADD_TEST(Large plist_test data/4.plist) | |||
| 16 | ADD_TEST(Huge plist_test data/5.plist) | 19 | ADD_TEST(Huge plist_test data/5.plist) |
| 17 | ADD_TEST(Big_Array plist_test data/6.plist) | 20 | ADD_TEST(Big_Array plist_test data/6.plist) |
| 18 | 21 | ||
| 22 | ADD_TEST(EmptyCmp plist_cmp data/1.plist data/1.plist.out) | ||
| 23 | ADD_TEST(SmallCmp plist_cmp data/2.plist data/2.plist.out) | ||
| 24 | ADD_TEST(MediumCmp plist_cmp data/3.plist data/3.plist.out) | ||
| 25 | ADD_TEST(LargeCmp plist_cmp data/4.plist data/4.plist.out) | ||
| 26 | ADD_TEST(HugeCmp plist_cmp data/5.plist data/5.plist.out) | ||
| 27 | 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 @@ | |||
| 23 | <key>Some Int</key> | 23 | <key>Some Int</key> |
| 24 | <integer>32434543632</integer> | 24 | <integer>32434543632</integer> |
| 25 | <key>Some Real</key> | 25 | <key>Some Real</key> |
| 26 | <real>58654.3476563</real> | 26 | <real>58654.347656</real> |
| 27 | <key>Some Date</key> | 27 | <key>Some Date</key> |
| 28 | <date>2009-02-12T22:23:00Z</date> | 28 | <date>2009-02-12T22:23:00Z</date> |
| 29 | <key>Some Data</key> | 29 | <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 @@ | |||
| 23 | <key>Some Int</key> | 23 | <key>Some Int</key> |
| 24 | <integer>32434543632</integer> | 24 | <integer>32434543632</integer> |
| 25 | <key>Some Real</key> | 25 | <key>Some Real</key> |
| 26 | <real>58654.3476563</real> | 26 | <real>58654.347656</real> |
| 27 | <key>Some Date</key> | 27 | <key>Some Date</key> |
| 28 | <date>2009-02-12T22:23:00Z</date> | 28 | <date>2009-02-12T22:23:00Z</date> |
| 29 | <key>Some Data</key> | 29 | <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 @@ | |||
| 23 | <key>Some Int</key> | 23 | <key>Some Int</key> |
| 24 | <integer>32434543632</integer> | 24 | <integer>32434543632</integer> |
| 25 | <key>Some Real</key> | 25 | <key>Some Real</key> |
| 26 | <real>58654.3476563</real> | 26 | <real>58654.347656</real> |
| 27 | <key>Some Date</key> | 27 | <key>Some Date</key> |
| 28 | <date>2009-02-12T22:23:00Z</date> | 28 | <date>2009-02-12T22:23:00Z</date> |
| 29 | <key>Some Data</key> | 29 | <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 @@ | |||
| 23 | <key>Some Int</key> | 23 | <key>Some Int</key> |
| 24 | <integer>32434543632</integer> | 24 | <integer>32434543632</integer> |
| 25 | <key>Some Real</key> | 25 | <key>Some Real</key> |
| 26 | <real>58654.3476563</real> | 26 | <real>58654.347656</real> |
| 27 | <key>Some Date</key> | 27 | <key>Some Date</key> |
| 28 | <date>2009-02-12T22:23:00Z</date> | 28 | <date>2009-02-12T22:23:00Z</date> |
| 29 | <key>Some Data</key> | 29 | <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 @@ | |||
| 1 | /* | ||
| 2 | * backup_test.c | ||
| 3 | * source libplist regression test | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | |||
| 23 | #include "plist/plist.h" | ||
| 24 | |||
| 25 | #include <stdio.h> | ||
| 26 | #include <stdlib.h> | ||
| 27 | #include <string.h> | ||
| 28 | #include <sys/stat.h> | ||
| 29 | |||
| 30 | char compare_plist(plist_t node_l, plist_t node_r) | ||
| 31 | { | ||
| 32 | plist_t cur_l = NULL; | ||
| 33 | plist_t cur_r = NULL; | ||
| 34 | int res = 1; | ||
| 35 | |||
| 36 | cur_l = plist_get_first_child(node_l); | ||
| 37 | cur_r = plist_get_first_child(node_r); | ||
| 38 | |||
| 39 | if ( (!cur_l && cur_r) || (cur_l && !cur_r)) | ||
| 40 | return 0; | ||
| 41 | |||
| 42 | if ( !cur_l && !cur_r ) | ||
| 43 | return plist_compare_node_value( node_l, node_r ); | ||
| 44 | |||
| 45 | while(cur_l && cur_r && res) { | ||
| 46 | |||
| 47 | if (!(res = compare_plist(cur_l, cur_r))) | ||
| 48 | return res; | ||
| 49 | |||
| 50 | cur_l = plist_get_next_sibling(cur_l); | ||
| 51 | cur_r = plist_get_next_sibling(cur_r); | ||
| 52 | if ( (!cur_l && cur_r) || (cur_l && !cur_r)) | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | return res; | ||
| 57 | } | ||
| 58 | |||
| 59 | int main(int argc, char *argv[]) | ||
| 60 | { | ||
| 61 | FILE *iplist1 = NULL; | ||
| 62 | FILE *iplist2 = NULL; | ||
| 63 | plist_t root_node1 = NULL; | ||
| 64 | plist_t root_node2 = NULL; | ||
| 65 | char *plist_1 = NULL; | ||
| 66 | char *plist_2 = NULL; | ||
| 67 | int size_in1 = 0; | ||
| 68 | int size_in2 = 0; | ||
| 69 | char *file_in1 = NULL; | ||
| 70 | char *file_in2 = NULL; | ||
| 71 | int res = 0; | ||
| 72 | |||
| 73 | struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat)); | ||
| 74 | struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat)); | ||
| 75 | |||
| 76 | if (argc!= 3) { | ||
| 77 | printf("Wrong input\n"); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | file_in1 = argv[1]; | ||
| 82 | file_in2 = argv[2]; | ||
| 83 | |||
| 84 | //read input file | ||
| 85 | iplist1 = fopen(file_in1, "rb"); | ||
| 86 | iplist2 = fopen(file_in2, "rb"); | ||
| 87 | |||
| 88 | if (!iplist1 || !iplist2) { | ||
| 89 | printf("File does not exists\n"); | ||
| 90 | return 2; | ||
| 91 | } | ||
| 92 | |||
| 93 | stat(file_in1, filestats1); | ||
| 94 | stat(file_in2, filestats2); | ||
| 95 | |||
| 96 | size_in1 = filestats1->st_size; | ||
| 97 | size_in2 = filestats2->st_size; | ||
| 98 | |||
| 99 | plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1)); | ||
| 100 | plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1)); | ||
| 101 | |||
| 102 | fread(plist_1, sizeof(char), size_in1, iplist1); | ||
| 103 | fread(plist_2, sizeof(char), size_in2, iplist2); | ||
| 104 | |||
| 105 | fclose(iplist1); | ||
| 106 | fclose(iplist2); | ||
| 107 | |||
| 108 | if (memcmp(plist_1, "bplist00", 8) == 0) | ||
| 109 | plist_from_bin(plist_1, size_in1, &root_node1); | ||
| 110 | else | ||
| 111 | plist_from_xml(plist_1, size_in1, &root_node1); | ||
| 112 | |||
| 113 | if (memcmp(plist_2, "bplist00", 8) == 0) | ||
| 114 | plist_from_bin(plist_2, size_in2, &root_node2); | ||
| 115 | else | ||
| 116 | plist_from_xml(plist_2, size_in2, &root_node2); | ||
| 117 | |||
| 118 | if (!root_node1 || !root_node2) { | ||
| 119 | printf("PList parsing failed\n"); | ||
| 120 | return 3; | ||
| 121 | } | ||
| 122 | else | ||
| 123 | printf("PList parsing succeeded\n"); | ||
| 124 | |||
| 125 | res = compare_plist(root_node1, root_node2); | ||
| 126 | |||
| 127 | |||
| 128 | plist_free(root_node1); | ||
| 129 | plist_free(root_node2); | ||
| 130 | |||
| 131 | free(plist_1); | ||
| 132 | free(plist_2); | ||
| 133 | free(filestats1); | ||
| 134 | free(filestats2); | ||
| 135 | |||
| 136 | return !res; | ||
| 137 | } | ||
| 138 | |||
