gtsam/wrap/tests/testReturnValue.cpp

120 lines
3.6 KiB
C++
Raw Normal View History

2014-12-01 05:33:30 +08:00
/* ----------------------------------------------------------------------------
2019-02-11 22:39:48 +08:00
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
2014-12-01 05:33:30 +08:00
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
* @file testReturnValue.cpp
* @brief Unit test for ReturnValue class & parser
* @author Frank Dellaert
* @date Nov 30, 2014
**/
#include <wrap/ReturnValue.h>
#include <CppUnitLite/TestHarness.h>
#include <iostream>
using namespace std;
using namespace wrap;
2014-12-01 06:02:23 +08:00
//******************************************************************************
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 ) {
2014-12-01 06:24:24 +08:00
ReturnType actual("Point3", Qualified::CLASS, true);
2014-12-01 06:02:23 +08:00
EXPECT(actual.namespaces().empty());
EXPECT(actual.name()=="Point3");
EXPECT(actual.category==Qualified::CLASS);
EXPECT(actual.isPtr);
}
2014-12-01 06:24:24 +08:00
//******************************************************************************
TEST( ReturnType, grammar ) {
using classic::space_p;
// Create type grammar that will place result in actual
ReturnType actual;
ReturnTypeGrammar g(actual);
EXPECT(parse("Point3", g, space_p).full);
EXPECT( actual==ReturnType("Point3"));
actual.clear();
EXPECT(parse("Test*", g, space_p).full);
EXPECT( actual==ReturnType("Test",Qualified::CLASS,true));
actual.clear();
EXPECT(parse("VectorNotEigen", g, space_p).full);
EXPECT(actual==ReturnType("VectorNotEigen"));
actual.clear();
EXPECT(parse("double", g, space_p).full);
EXPECT(actual==ReturnType("double",Qualified::BASIS));
actual.clear();
}
2014-12-01 06:02:23 +08:00
//******************************************************************************
TEST( ReturnValue, Constructor ) {
ReturnValue actual(ReturnType("Point2"), ReturnType("Point3"));
EXPECT(actual.type1==Qualified("Point2"));
EXPECT(actual.type2==Qualified("Point3"));
EXPECT(actual.isPair);
}
2014-12-01 05:33:30 +08:00
//******************************************************************************
TEST( ReturnValue, grammar ) {
using classic::space_p;
// Create type grammar that will place result in actual
ReturnValue actual;
ReturnValueGrammar g(actual);
2014-12-01 06:02:23 +08:00
EXPECT(parse("pair<Point2,Point3>", g, space_p).full);
EXPECT( actual==ReturnValue(ReturnType("Point2"),ReturnType("Point3")));
2014-12-01 06:24:24 +08:00
actual.clear();
EXPECT(parse("pair<Test*,Test>", g, space_p).full);
EXPECT( actual==ReturnValue( //
ReturnType("Test",Qualified::CLASS,true),ReturnType("Test")));
actual.clear();
EXPECT(parse("pair<Test,Test*>", g, space_p).full);
EXPECT( actual==ReturnValue(ReturnType("Test"), //
ReturnType("Test",Qualified::CLASS,true)));
2014-12-01 06:02:23 +08:00
actual.clear();
2014-12-01 05:33:30 +08:00
EXPECT(parse("VectorNotEigen", g, space_p).full);
2014-12-01 06:02:23 +08:00
EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen")));
2014-12-01 05:33:30 +08:00
actual.clear();
EXPECT(parse("double", g, space_p).full);
EXPECT(actual==ReturnValue(ReturnType("double",Qualified::BASIS)));
actual.clear();
2014-12-01 06:46:25 +08:00
EXPECT(parse("void", g, space_p).full);
EXPECT(actual==ReturnValue(ReturnType("void",Qualified::VOID)));
actual.clear();
2014-12-01 05:33:30 +08:00
}
//******************************************************************************
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
//******************************************************************************