Some more tests

release/4.3a0
dellaert 2014-11-30 23:02:23 +01:00
parent 58806b75d2
commit dc42773f1e
3 changed files with 56 additions and 12 deletions

View File

@ -9,6 +9,7 @@
#include "FileWriter.h" #include "FileWriter.h"
#include "TypeAttributesTable.h" #include "TypeAttributesTable.h"
#include "utilities.h" #include "utilities.h"
#include <iostream>
#pragma once #pragma once
@ -17,18 +18,17 @@ namespace wrap {
/** /**
* Encapsulates return value of a method or function * Encapsulates return value of a method or function
*/ */
struct ReturnType: Qualified { struct ReturnType: public Qualified {
bool isPtr; bool isPtr;
/// Makes a void type /// Makes a void type
ReturnType(bool ptr = false) : ReturnType() :
isPtr(ptr) { isPtr(false) {
} }
/// Constructor, no namespaces /// Constructor, no namespaces
ReturnType(const std::string& name, Qualified::Category c = Qualified::CLASS, ReturnType(const std::string& name, Category c = CLASS, bool ptr = false) :
bool ptr = false) :
Qualified(name, c), isPtr(ptr) { Qualified(name, c), isPtr(ptr) {
} }

View File

@ -23,6 +23,32 @@
using namespace std; using namespace std;
using namespace wrap; 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 // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> { struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
@ -38,15 +64,12 @@ struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
/// Definition of type grammar /// Definition of type grammar
template<typename ScannerT> template<typename ScannerT>
struct definition: basic_rules<ScannerT> { struct definition {
typedef classic::rule<ScannerT> Rule; classic::rule<ScannerT> pair_p, returnValue_p;
Rule pair_p, returnValue_p;
definition(ReturnValueGrammar const& self) { definition(ReturnValueGrammar const& self) {
using namespace wrap;
using namespace classic; using namespace classic;
pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ',' pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ','
@ -55,7 +78,7 @@ struct ReturnValueGrammar: public classic::grammar<ReturnValueGrammar> {
returnValue_p = pair_p | self.returnType1_g; returnValue_p = pair_p | self.returnType1_g;
} }
Rule const& start() const { classic::rule<ScannerT> const& start() const {
return returnValue_p; return returnValue_p;
} }
@ -72,8 +95,13 @@ TEST( ReturnValue, grammar ) {
ReturnValue actual; ReturnValue actual;
ReturnValueGrammar g(actual); ReturnValueGrammar g(actual);
EXPECT(parse("pair<Point2,Point3>", g, space_p).full);
EXPECT( actual==ReturnValue(ReturnType("Point2"),ReturnType("Point3")));
cout << actual << endl;
actual.clear();
EXPECT(parse("VectorNotEigen", g, space_p).full); EXPECT(parse("VectorNotEigen", g, space_p).full);
EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen",Qualified::CLASS))); EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen")));
actual.clear(); actual.clear();
EXPECT(parse("double", g, space_p).full); EXPECT(parse("double", g, space_p).full);

View File

@ -22,6 +22,22 @@
using namespace std; using namespace std;
using namespace wrap; 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 ) { TEST( Type, grammar ) {