|
| 1 | +/* |
| 2 | + * source libplist++ regression test |
| 3 | + * |
| 4 | + * Copyright (c) 2021 Sebastien Gonzalve All Rights Reserved. |
| 5 | + * |
| 6 | + * This library is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 2.1 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This library is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with this library; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + */ |
| 20 | + |
| 21 | + |
| 22 | +#include "plist/plist++.h" |
| 23 | +#include <fstream> |
| 24 | +#include <sstream> |
| 25 | +#include <iostream> |
| 26 | + |
| 27 | +int main(int argc, char *argv[]) |
| 28 | +{ |
| 29 | + if (argc != 3) |
| 30 | + { |
| 31 | + printf("Wrong input\n"); |
| 32 | + return 1; |
| 33 | + } |
| 34 | + |
| 35 | + const char* file_in = argv[1]; |
| 36 | + const char* file_out = argv[2]; |
| 37 | + |
| 38 | + //read input file |
| 39 | + std::ifstream iplist; |
| 40 | + iplist.open(file_in); |
| 41 | + |
| 42 | + if (!iplist) |
| 43 | + { |
| 44 | + printf("File does not exists\n"); |
| 45 | + return 2; |
| 46 | + } |
| 47 | + |
| 48 | + std::cout << "File " << file_in << " is open\n"; |
| 49 | + |
| 50 | + std::string plist_xml; |
| 51 | + { |
| 52 | + std::stringstream buffer; |
| 53 | + buffer << iplist.rdbuf(); |
| 54 | + plist_xml = buffer.str(); |
| 55 | + } |
| 56 | + |
| 57 | + iplist.close(); |
| 58 | + |
| 59 | + //convert one format to another |
| 60 | + PList::Structure* root_node1 = PList::Structure::FromXml(plist_xml); |
| 61 | + if (!root_node1) |
| 62 | + { |
| 63 | + std::cout << "PList XML parsing failed\n"; |
| 64 | + return 3; |
| 65 | + } |
| 66 | + |
| 67 | + std::cout << "PList XML parsing succeeded\n"; |
| 68 | + std::vector<char> plist_bin = root_node1->ToBin(); |
| 69 | + // FIXME There is no way to test for success of ToBin for now. |
| 70 | + |
| 71 | + std::cout << "PList BIN writing succeeded\n"; |
| 72 | + PList::Structure* root_node2 = PList::Structure::FromBin(plist_bin); |
| 73 | + if (!root_node2) |
| 74 | + { |
| 75 | + std::cout << "PList BIN parsing failed\n"; |
| 76 | + return 5; |
| 77 | + } |
| 78 | + |
| 79 | + std::cout << "PList BIN parsing succeeded\n"; |
| 80 | + std::string plist_xml2 = root_node2->ToXml(); |
| 81 | + if (plist_xml2.empty()) |
| 82 | + { |
| 83 | + std::cout << "PList XML writing failed\n"; |
| 84 | + return 8; |
| 85 | + } |
| 86 | + |
| 87 | + std::cout << "PList XML writing succeeded\n"; |
| 88 | + { |
| 89 | + std::ofstream oplist; |
| 90 | + oplist.open(file_out); |
| 91 | + oplist << plist_xml2; |
| 92 | + } |
| 93 | + |
| 94 | + if (plist_xml.size() != plist_xml2.size()) |
| 95 | + { |
| 96 | + std::cout << "Size of input and output is different\n" |
| 97 | + << "Input size : " << plist_xml.size() |
| 98 | + << "\nOutput size : " << plist_xml2.size() << '\n'; |
| 99 | + } |
| 100 | + |
| 101 | + return 0; |
| 102 | +} |
| 103 | + |
0 commit comments