From: <mar...@us...> - 2013-08-20 06:32:12
|
Revision: 6356 http://sourceforge.net/p/freeorion/code/6356 Author: marcel_metz Date: 2013-08-20 06:32:09 +0000 (Tue, 20 Aug 2013) Log Message: ----------- parse/test: Fixed tests. * Added end-of-input token to force tests to consume the whole phrase. * Using now correct object attributes for double parser. * Expecting now ValueRef::Variables<double> instead of ValueRef::StaticCast<int, double> for double statistics. * added throw check for incomplete quoted string. Modified Paths: -------------- trunk/FreeOrion/parse/test/TestEnumParser.cpp trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp trunk/FreeOrion/parse/test/TestValueRefStringParser.cpp trunk/FreeOrion/parse/test/TestValueRefUniverseObjectTypeParser.cpp Modified: trunk/FreeOrion/parse/test/TestEnumParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestEnumParser.cpp 2013-08-20 05:59:10 UTC (rev 6355) +++ trunk/FreeOrion/parse/test/TestEnumParser.cpp 2013-08-20 06:32:09 UTC (rev 6356) @@ -25,6 +25,7 @@ parse::enum_parser_rule<MeterType>::type& rule = parse::non_ship_part_meter_type_enum(); const parse::lexer& lexer = lexer.instance(); boost::spirit::qi::in_state_type in_state; + boost::spirit::qi::eoi_type eoi; boost::spirit::qi::_1_type _1; std::string::const_iterator begin_phrase = phrase.begin(); @@ -33,7 +34,7 @@ return boost::spirit::qi::phrase_parse( lexer.begin(begin_phrase, end_phrase), lexer.end(), - rule[boost::phoenix::ref(result) = _1], + rule[boost::phoenix::ref(result) = _1] > eoi, in_state("WS")[lexer.self] ); } Modified: trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp 2013-08-20 05:59:10 UTC (rev 6355) +++ trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp 2013-08-20 06:32:09 UTC (rev 6356) @@ -44,6 +44,7 @@ parse::value_ref_parser_rule<double>::type& rule = parse::value_ref_parser<double>(); const parse::lexer& lexer = lexer.instance(); boost::spirit::qi::in_state_type in_state; + boost::spirit::qi::eoi_type eoi; boost::spirit::qi::_1_type _1; std::string::const_iterator begin_phrase = phrase.begin(); @@ -52,7 +53,7 @@ return boost::spirit::qi::phrase_parse( lexer.begin(begin_phrase, end_phrase), lexer.end(), - rule[boost::phoenix::ref(result) = _1], + rule[boost::phoenix::ref(result) = _1] > eoi, in_state("WS")[lexer.self] ); } @@ -63,7 +64,7 @@ static const boost::array<ReferenceType, 4> referenceTypes; static const boost::array<StatisticType, 9> statisticTypes; static const boost::array<std::string, 3> containerTypes; - static const boost::array<std::string, 13> attributes; + static const boost::array<std::string, 36> attributes; ValueRef::ValueRefBase<double>* result; const ValueRef::Operation<double>* operation1; @@ -102,20 +103,43 @@ "System" }}; -const boost::array<std::string, 13> ValueRefDoubleFixture::attributes = {{ - "Age", - "CreationTurn", - "DesignID", - "FinalDestinationID", - "FleetID", - "ID", - "NextSystemID", - "NumShips", - "Owner", - "PlanetID", - "PreviousSystemID", - "ProducedByEmpireID", - "SystemID" +const boost::array<std::string, 36> ValueRefDoubleFixture::attributes = {{ + "Industry", + "TargetIndustry", + "Research", + "TargetResearch", + "Trade", + "TargetTrade", + "Construction", + "TargetConstruction", + "Population", + "TargetPopulation", + "TargetHappiness", + "Happiness", + "MaxFuel", + "Fuel", + "MaxShield", + "Shield", + "MaxDefense", + "Defense", + "MaxTroops", + "Troops", + "RebelTroops", + "MaxStructure", + "Structure", + "Supply", + "Stealth", + "Detection", + "BattleSpeed", + "StarlaneSpeed", + "TradeStockpile", + "DistanceToSource", + "X", + "Y", + "SizeAsDouble", + "NextTurnPopGrowth", + "Size", + "DistanceFromOriginalType" }}; BOOST_FIXTURE_TEST_SUITE(ValueRefDoubleParser, ValueRefDoubleFixture) @@ -680,8 +704,8 @@ adobe::name_t(attribute.c_str()) }; - BOOST_CHECK_EQUAL(typeid(ValueRef::StaticCast<int, double>), typeid(*result)); - if(variable = dynamic_cast<const ValueRef::StaticCast<int, double>*>(result)) { + BOOST_CHECK_EQUAL(typeid(ValueRef::Variable<double>), typeid(*result)); + if(variable = dynamic_cast<const ValueRef::Variable<double>*>(result)) { BOOST_CHECK_EQUAL(variable->GetReferenceType(), reference.first); BOOST_CHECK_EQUAL_COLLECTIONS( variable->PropertyName().begin(), variable->PropertyName().end(), @@ -707,8 +731,8 @@ adobe::name_t(attribute.c_str()) }; - BOOST_CHECK_EQUAL(typeid(ValueRef::StaticCast<int, double>), typeid(*result)); - if(variable = dynamic_cast<const ValueRef::StaticCast<int, double>*>(result)) { + BOOST_CHECK_EQUAL(typeid(ValueRef::Variable<double>), typeid(*result)); + if(variable = dynamic_cast<const ValueRef::Variable<double>*>(result)) { BOOST_CHECK_EQUAL(variable->GetReferenceType(), reference.first); BOOST_CHECK_EQUAL_COLLECTIONS( variable->PropertyName().begin(), variable->PropertyName().end(), Modified: trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp 2013-08-20 05:59:10 UTC (rev 6355) +++ trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp 2013-08-20 06:32:09 UTC (rev 6356) @@ -44,6 +44,7 @@ parse::value_ref_parser_rule<int>::type& rule = parse::value_ref_parser<int>(); const parse::lexer& lexer = lexer.instance(); boost::spirit::qi::in_state_type in_state; + boost::spirit::qi::eoi_type eoi; boost::spirit::qi::_1_type _1; std::string::const_iterator begin_phrase = phrase.begin(); @@ -52,7 +53,7 @@ return boost::spirit::qi::phrase_parse( lexer.begin(begin_phrase, end_phrase), lexer.end(), - rule[boost::phoenix::ref(result) = _1], + rule[boost::phoenix::ref(result) = _1] > eoi, in_state("WS")[lexer.self] ); } Modified: trunk/FreeOrion/parse/test/TestValueRefStringParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefStringParser.cpp 2013-08-20 05:59:10 UTC (rev 6355) +++ trunk/FreeOrion/parse/test/TestValueRefStringParser.cpp 2013-08-20 06:32:09 UTC (rev 6356) @@ -17,6 +17,7 @@ parse::value_ref_parser_rule<std::string>::type& rule = parse::value_ref_parser<std::string>(); const parse::lexer& lexer = lexer.instance(); boost::spirit::qi::in_state_type in_state; + boost::spirit::qi::eoi_type eoi; boost::spirit::qi::_1_type _1; std::string::const_iterator begin_phrase = phrase.begin(); @@ -25,7 +26,7 @@ return boost::spirit::qi::phrase_parse( lexer.begin(begin_phrase, end_phrase), lexer.end(), - rule[boost::phoenix::ref(result) = _1], + rule[boost::phoenix::ref(result) = _1] > eoi, in_state("WS")[lexer.self] ); } @@ -134,7 +135,7 @@ } BOOST_AUTO_TEST_CASE(StringLiteralParserMalformed) { - BOOST_CHECK(parse("\"A bit of text with missing quotes, whoops", result)); + BOOST_CHECK_THROW(parse("\"A bit of text with missing quotes, whoops", result), std::runtime_error); BOOST_CHECK(!result); } Modified: trunk/FreeOrion/parse/test/TestValueRefUniverseObjectTypeParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefUniverseObjectTypeParser.cpp 2013-08-20 05:59:10 UTC (rev 6355) +++ trunk/FreeOrion/parse/test/TestValueRefUniverseObjectTypeParser.cpp 2013-08-20 06:32:09 UTC (rev 6356) @@ -17,6 +17,7 @@ parse::value_ref_parser_rule<UniverseObjectType>::type& rule = parse::value_ref_parser<UniverseObjectType>(); const parse::lexer& lexer = lexer.instance(); boost::spirit::qi::in_state_type in_state; + boost::spirit::qi::eoi_type eoi; boost::spirit::qi::_1_type _1; std::string::const_iterator begin_phrase = phrase.begin(); @@ -25,7 +26,7 @@ return boost::spirit::qi::phrase_parse( lexer.begin(begin_phrase, end_phrase), lexer.end(), - rule[boost::phoenix::ref(result) = _1], + rule[boost::phoenix::ref(result) = _1] > eoi, in_state("WS")[lexer.self] ); } |