| 1 | /* |
| 2 | * MetaParser_unit_test.cpp |
| 3 | * |
| 4 | * Created on: Mar 3, 2019 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #define BOOST_TEST_DYN_LINK |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | |
| 11 | #include "MetaParser.hpp" |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE( vtk_writer_tests ) |
| 14 | |
| 15 | BOOST_AUTO_TEST_CASE( vtk_writer_meta_parser_use ) |
| 16 | { |
| 17 | std::string test_options("time = 5.0" ); |
| 18 | std::string test_options2("time=6.0" ); |
| 19 | std::string test_options3("time =7.0" ); |
| 20 | std::string test_options4("time= 8.0" ); |
| 21 | std::string test_options5("time= 9.0" ); |
| 22 | |
| 23 | double time = 1.0; |
| 24 | |
| 25 | MetaParser_options opts; |
| 26 | opts.add_options() |
| 27 | ("time" , MetaParser_def::value<double>(&time)); |
| 28 | |
| 29 | MetaParser mp(opts); |
| 30 | mp.parse(test_options); |
| 31 | |
| 32 | BOOST_REQUIRE_EQUAL(time,5.0); |
| 33 | |
| 34 | time = 0.0; |
| 35 | bool exist = mp.getOption("time" ,time); |
| 36 | |
| 37 | BOOST_REQUIRE_EQUAL(exist,true); |
| 38 | BOOST_REQUIRE_EQUAL(time,5.0); |
| 39 | |
| 40 | exist = mp.getOption("invalid" ,time); |
| 41 | BOOST_REQUIRE_EQUAL(exist,false); |
| 42 | |
| 43 | // parse another |
| 44 | |
| 45 | mp.clear(); |
| 46 | |
| 47 | time = 0.0; |
| 48 | mp.parse(test_options2); |
| 49 | |
| 50 | BOOST_REQUIRE_EQUAL(time,6.0); |
| 51 | |
| 52 | time = 0.0; |
| 53 | exist = mp.getOption("time" ,time); |
| 54 | |
| 55 | BOOST_REQUIRE_EQUAL(exist,true); |
| 56 | BOOST_REQUIRE_EQUAL(time,6.0); |
| 57 | |
| 58 | exist = mp.getOption("invalid" ,time); |
| 59 | BOOST_REQUIRE_EQUAL(exist,false); |
| 60 | |
| 61 | // parse another |
| 62 | |
| 63 | mp.clear(); |
| 64 | |
| 65 | time = 0.0; |
| 66 | mp.parse(test_options3); |
| 67 | |
| 68 | BOOST_REQUIRE_EQUAL(time,7.0); |
| 69 | |
| 70 | time = 0.0; |
| 71 | exist = mp.getOption("time" ,time); |
| 72 | |
| 73 | BOOST_REQUIRE_EQUAL(exist,true); |
| 74 | BOOST_REQUIRE_EQUAL(time,7.0); |
| 75 | |
| 76 | exist = mp.getOption("invalid" ,time); |
| 77 | BOOST_REQUIRE_EQUAL(exist,false); |
| 78 | |
| 79 | // parse another |
| 80 | |
| 81 | mp.clear(); |
| 82 | |
| 83 | time = 0.0; |
| 84 | mp.parse(test_options4); |
| 85 | |
| 86 | BOOST_REQUIRE_EQUAL(time,8.0); |
| 87 | |
| 88 | time = 0.0; |
| 89 | exist = mp.getOption("time" ,time); |
| 90 | |
| 91 | BOOST_REQUIRE_EQUAL(exist,true); |
| 92 | BOOST_REQUIRE_EQUAL(time,8.0); |
| 93 | |
| 94 | exist = mp.getOption("invalid" ,time); |
| 95 | BOOST_REQUIRE_EQUAL(exist,false); |
| 96 | |
| 97 | // parse another |
| 98 | |
| 99 | mp.clear(); |
| 100 | |
| 101 | time = 0.0; |
| 102 | mp.parse(test_options5); |
| 103 | |
| 104 | BOOST_REQUIRE_EQUAL(time,9.0); |
| 105 | |
| 106 | time = 0.0; |
| 107 | exist = mp.getOption("time" ,time); |
| 108 | |
| 109 | BOOST_REQUIRE_EQUAL(exist,true); |
| 110 | BOOST_REQUIRE_EQUAL(time,9.0); |
| 111 | |
| 112 | exist = mp.getOption("invalid" ,time); |
| 113 | BOOST_REQUIRE_EQUAL(exist,false); |
| 114 | |
| 115 | } |
| 116 | |
| 117 | BOOST_AUTO_TEST_SUITE_END() |
| 118 | |