test_inih.cpp
1 /* 2 EIBD eib bus access and management daemon 3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #include "inifile.h" 21 22 #include <assert.h> 23 #include <iostream> 24 25 main(int argc, const char *argv[]) 26 { 27 if(argc < 2) 28 { 29 std::cerr << "Usage: " << argv[0] << "goodfile badfile…" << std::endl; 30 exit(1); 31 } 32 33 IniData i; 34 int errl = i.parse(argv[1]); 35 if (errl) 36 { 37 std::cerr << "Parse error in '" << argv[1] << "', line" << errl << ". Stop." <<std::endl; 38 exit(2); 39 } 40 41 IniSectionPtr a = i["main"]; 42 if ((*a)["foo"] != "bar") 43 { 44 std::cerr << "in section 'main': foo should be 'bar' but is '" << (*a)["foo"] << "'" << std::endl; 45 exit(1); 46 } 47 if (a->value("baz",99) != 42) 48 { 49 std::cerr << "in section 'main': baz should be 42 but is " << a->value("baz",88) << std::endl; 50 exit(1); 51 } 52 if (!a->value("duh",false)) 53 { 54 std::cerr << "in section 'main': duh should be true" << std::endl; 55 exit(1); 56 }; 57 58 std::cerr << "'Good' test completed. Ignore the following errors." << std::endl; 59 while(argc > 2) 60 { 61 IniData ix; 62 if (!ix.parse(argv[--argc])) 63 { 64 std::cerr << "file '" << argv[argc] << "should not parse cleanly" << std::endl; 65 exit(1); 66 } 67 } 68 std::cerr << "All tests completed correctly." << std::endl; 69 exit(0); 70 }