From: <mar...@us...> - 2013-08-19 08:21:01
|
Revision: 6350 http://sourceforge.net/p/freeorion/code/6350 Author: marcel_metz Date: 2013-08-19 08:20:59 +0000 (Mon, 19 Aug 2013) Log Message: ----------- parse/test: Added printout of AST after failing test. Modified Paths: -------------- trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp Modified: trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp 2013-08-18 10:39:08 UTC (rev 6349) +++ trunk/FreeOrion/parse/test/TestValueRefDoubleParser.cpp 2013-08-19 08:20:59 UTC (rev 6350) @@ -1,18 +1,52 @@ #include <boost/test/unit_test.hpp> +#include <stack> + #include "ValueRefParser.h" #include "universe/ValueRef.h" #include "CommonTest.h" -struct ValueRefDoubleFixture { +struct ValueRefDoubleFixture: boost::unit_test::test_observer { ValueRefDoubleFixture(): - result(0) - {} + result(0) { + boost::unit_test::framework::register_observer(*this); + } ~ValueRefDoubleFixture() { + boost::unit_test::framework::deregister_observer(*this); delete result; } +void assertion_result(bool passed) { + if(!passed && result) { + std::stack<const ValueRef::ValueRefBase<double>*> stack; + stack.push(result); + size_t depth = 0; + + while(!stack.empty()) { + const ValueRef::ValueRefBase<double>* top = stack.top(); + stack.pop(); + if(operation1 = dynamic_cast<const ValueRef::Operation<double>*>(top)) { + std::cout << std::string(depth * 2, ' ') << operation1->GetOpType() << std::endl; + } + + if(value = dynamic_cast<const ValueRef::Constant<double>*>(top)) { + std::cout << std::string(depth * 2, ' ') << value->Value() << std::endl; + } + + if(value && !stack.empty() && !dynamic_cast<const ValueRef::Constant<double>*>(stack.top())) { + depth--; + } + + if(operation1) { + stack.push(operation1->LHS()); + stack.push(operation1->RHS()); + depth++; + } + } + } +} + bool parse(std::string phrase, ValueRef::ValueRefBase<double>*& result) { parse::value_ref_parser_rule<double>::type& rule = parse::value_ref_parser<double>(); const parse::lexer& lexer = lexer.instance(); @@ -57,7 +91,6 @@ std::make_pair(ValueRef::CONDITION_ROOT_CANDIDATE_REFERENCE, "RootCandidate") }}; - const boost::array<ValueRefDoubleFixture::StatisticType, 9> ValueRefDoubleFixture::statisticTypes = {{ std::make_pair(ValueRef::MAX, "Max"), std::make_pair(ValueRef::MEAN, "Mean"), Modified: trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp =================================================================== --- trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp 2013-08-18 10:39:08 UTC (rev 6349) +++ trunk/FreeOrion/parse/test/TestValueRefIntParser.cpp 2013-08-19 08:20:59 UTC (rev 6350) @@ -1,20 +1,54 @@ #include <boost/test/unit_test.hpp> +#include <stack> + #include "ValueRefParser.h" #include "universe/ValueRef.h" #include "CommonTest.h" -struct ValueRefIntFixture { +struct ValueRefIntFixture: boost::unit_test::test_observer { ValueRefIntFixture(): result(0) { + boost::unit_test::framework::register_observer(*this); } ~ValueRefIntFixture() { + boost::unit_test::framework::deregister_observer(*this); delete result; } -bool parse(std::string phrase, ValueRef::ValueRefBase<int>*& result) { - parse::value_ref_parser_rule<int>::type& rule = parse::value_ref_parser<int>(); +void assertion_result(bool passed) { + if(!passed && result) { + std::stack<const ValueRef::ValueRefBase<int>*> stack; + stack.push(result); + size_t depth = 0; + + while(!stack.empty()) { + const ValueRef::ValueRefBase<int>* top = stack.top(); + stack.pop(); + if(operation1 = dynamic_cast<const ValueRef::Operation<int>*>(top)) { + std::cout << std::string(depth * 2, ' ') << operation1->GetOpType() << std::endl; + } + + if(value = dynamic_cast<const ValueRef::Constant<int>*>(top)) { + std::cout << std::string(depth * 2, ' ') << value->Value() << std::endl; + } + + if(value && !stack.empty() && !dynamic_cast<const ValueRef::Constant<int>*>(stack.top())) { + depth--; + } + + if(operation1) { + stack.push(operation1->LHS()); + stack.push(operation1->RHS()); + depth++; + } + } + } +} + + bool parse(std::string phrase, ValueRef::ValueRefBase<int>*& result) { + 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::_1_type _1; |