diff --git a/wrap/ReturnType.h b/wrap/ReturnType.h index 5301e71a6..64ef26991 100644 --- a/wrap/ReturnType.h +++ b/wrap/ReturnType.h @@ -9,6 +9,7 @@ #include "FileWriter.h" #include "TypeAttributesTable.h" #include "utilities.h" +#include #pragma once @@ -17,18 +18,17 @@ namespace wrap { /** * Encapsulates return value of a method or function */ -struct ReturnType: Qualified { +struct ReturnType: public Qualified { bool isPtr; /// Makes a void type - ReturnType(bool ptr = false) : - isPtr(ptr) { + ReturnType() : + isPtr(false) { } /// Constructor, no namespaces - ReturnType(const std::string& name, Qualified::Category c = Qualified::CLASS, - bool ptr = false) : + ReturnType(const std::string& name, Category c = CLASS, bool ptr = false) : Qualified(name, c), isPtr(ptr) { } diff --git a/wrap/tests/testReturnValue.cpp b/wrap/tests/testReturnValue.cpp index be245e75e..3cd7e63ca 100644 --- a/wrap/tests/testReturnValue.cpp +++ b/wrap/tests/testReturnValue.cpp @@ -23,6 +23,32 @@ using namespace std; using namespace wrap; +//****************************************************************************** +TEST( ReturnType, Constructor1 ) { + ReturnType actual("Point2"); + EXPECT(actual.namespaces().empty()); + EXPECT(actual.name()=="Point2"); + EXPECT(actual.category==Qualified::CLASS); + EXPECT(!actual.isPtr); +} + +//****************************************************************************** +TEST( ReturnType, Constructor2 ) { + ReturnType actual("Point3",Qualified::CLASS, true); + EXPECT(actual.namespaces().empty()); + EXPECT(actual.name()=="Point3"); + EXPECT(actual.category==Qualified::CLASS); + EXPECT(actual.isPtr); +} + +//****************************************************************************** +TEST( ReturnValue, Constructor ) { + ReturnValue actual(ReturnType("Point2"), ReturnType("Point3")); + EXPECT(actual.type1==Qualified("Point2")); + EXPECT(actual.type2==Qualified("Point3")); + EXPECT(actual.isPair); +} + //****************************************************************************** // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html struct ReturnValueGrammar: public classic::grammar { @@ -38,15 +64,12 @@ struct ReturnValueGrammar: public classic::grammar { /// Definition of type grammar template - struct definition: basic_rules { + struct definition { - typedef classic::rule Rule; - - Rule pair_p, returnValue_p; + classic::rule pair_p, returnValue_p; definition(ReturnValueGrammar const& self) { - using namespace wrap; using namespace classic; pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ',' @@ -55,7 +78,7 @@ struct ReturnValueGrammar: public classic::grammar { returnValue_p = pair_p | self.returnType1_g; } - Rule const& start() const { + classic::rule const& start() const { return returnValue_p; } @@ -72,8 +95,13 @@ TEST( ReturnValue, grammar ) { ReturnValue actual; ReturnValueGrammar g(actual); + EXPECT(parse("pair", g, space_p).full); + EXPECT( actual==ReturnValue(ReturnType("Point2"),ReturnType("Point3"))); + cout << actual << endl; + actual.clear(); + EXPECT(parse("VectorNotEigen", g, space_p).full); - EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen",Qualified::CLASS))); + EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen"))); actual.clear(); EXPECT(parse("double", g, space_p).full); diff --git a/wrap/tests/testType.cpp b/wrap/tests/testType.cpp index f61e81c62..abf3cf65f 100644 --- a/wrap/tests/testType.cpp +++ b/wrap/tests/testType.cpp @@ -22,6 +22,22 @@ using namespace std; using namespace wrap; +//****************************************************************************** +TEST( Type, Constructor1 ) { + Qualified actual("Point2"); + EXPECT(actual.namespaces().empty()); + EXPECT(actual.name()=="Point2"); + EXPECT(actual.category==Qualified::CLASS); +} + +//****************************************************************************** +TEST( Type, Constructor2 ) { + Qualified actual("Point3",Qualified::CLASS); + EXPECT(actual.namespaces().empty()); + EXPECT(actual.name()=="Point3"); + EXPECT(actual.category==Qualified::CLASS); +} + //****************************************************************************** TEST( Type, grammar ) {