From 6710f4bfb980dd0fe6e75e4d6cba75532cde30e8 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Wed, 28 Oct 2009 18:31:34 +0100 Subject: Format sources to ANSI style using AStyle (astyle --style=ansi). --- test/plist_cmp.c | 200 ++++++++++++++++++++++++++++-------------------------- test/plist_test.c | 196 +++++++++++++++++++++++++++------------------------- 2 files changed, 204 insertions(+), 192 deletions(-) (limited to 'test') diff --git a/test/plist_cmp.c b/test/plist_cmp.c index 386264a..709e8d0 100644 --- a/test/plist_cmp.c +++ b/test/plist_cmp.c @@ -8,15 +8,15 @@ * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,110 +33,114 @@ char compare_plist(plist_t node_l, plist_t node_r) { - plist_t cur_l = NULL; - plist_t cur_r = NULL; - int res = 1; + 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); + 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) || (cur_l && !cur_r)) + return 0; - if ( !cur_l && !cur_r ) - return plist_compare_node_value( node_l, node_r ); + if ( !cur_l && !cur_r ) + return plist_compare_node_value( node_l, node_r ); - while(cur_l && cur_r && res) { + while (cur_l && cur_r && res) + { - if (!(res = compare_plist(cur_l, cur_r))) - return 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; - } + 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; + 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; + 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; } - + diff --git a/test/plist_test.c b/test/plist_test.c index 069701e..a0344e9 100644 --- a/test/plist_test.c +++ b/test/plist_test.c @@ -8,15 +8,15 @@ * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -34,95 +34,103 @@ int main(int argc, char *argv[]) { - FILE *iplist = NULL; - FILE *oplist = NULL; - plist_t root_node1 = NULL; - plist_t root_node2 = NULL; - char *plist_xml = NULL; - char *plist_xml2 = NULL; - char *plist_bin = NULL; - int size_in = 0; - int size_out = 0; - int size_out2 = 0; - char *file_in = NULL; - struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); - if (argc!= 2) { - printf("Wrong input\n"); - return 1; - } - - file_in = argv[1]; - //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_xml = (char *) malloc(sizeof(char) * (size_in + 1)); - fread(plist_xml, sizeof(char), size_in, iplist); - fclose(iplist); - - - //convert one format to another - plist_from_xml(plist_xml, size_in, &root_node1); - if (!root_node1) { - printf("PList XML parsing failed\n"); - return 3; - } - else - 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"); - - 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"); - - 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"); - - 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); - } - - plist_free(root_node1); - plist_free(root_node2); - free(plist_bin); - free(plist_xml); - free(plist_xml2); - free(filestats); - - if (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; + FILE *iplist = NULL; + FILE *oplist = NULL; + plist_t root_node1 = NULL; + plist_t root_node2 = NULL; + char *plist_xml = NULL; + char *plist_xml2 = NULL; + char *plist_bin = NULL; + int size_in = 0; + int size_out = 0; + int size_out2 = 0; + char *file_in = NULL; + struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); + if (argc!= 2) + { + printf("Wrong input\n"); + return 1; + } + + file_in = argv[1]; + //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_xml = (char *) malloc(sizeof(char) * (size_in + 1)); + fread(plist_xml, sizeof(char), size_in, iplist); + fclose(iplist); + + + //convert one format to another + plist_from_xml(plist_xml, size_in, &root_node1); + if (!root_node1) + { + printf("PList XML parsing failed\n"); + return 3; + } + else + 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"); + + 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"); + + 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"); + + 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); + } + + plist_free(root_node1); + plist_free(root_node2); + free(plist_bin); + free(plist_xml); + free(plist_xml2); + free(filestats); + + if (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; } - + -- cgit v1.1-32-gdbae