gtsam/wrap/tests/testClass.cpp

91 lines
2.8 KiB
C++
Raw Normal View History

/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* 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 testClass.cpp
* @brief Unit test for Class class
* @author Frank Dellaert
* @date Nov 12, 2014
**/
#include <wrap/Class.h>
#include <CppUnitLite/TestHarness.h>
#include <iostream>
using namespace std;
using namespace wrap;
/* ************************************************************************* */
// Constructor
TEST( Class, Constructor ) {
Class cls;
}
/* ************************************************************************* */
2014-11-13 07:39:15 +08:00
// test method overloading
TEST( Class, OverloadingMethod ) {
Class cls;
2014-11-13 06:54:37 +08:00
const string name = "method1";
EXPECT(!cls.exists(name));
2014-11-13 07:39:15 +08:00
bool verbose = true, is_const = true;
ArgumentList args;
const ReturnValue retVal;
2014-12-02 03:29:35 +08:00
const Template tmplate;
cls.addMethod(verbose, is_const, name, args, retVal, tmplate);
2014-11-13 07:39:15 +08:00
EXPECT_LONGS_EQUAL(1, cls.nrMethods());
2014-11-13 06:54:37 +08:00
EXPECT(cls.exists(name));
2014-12-02 03:34:05 +08:00
EXPECT_LONGS_EQUAL(1, cls.method(name).nrOverloads());
2014-11-13 06:54:37 +08:00
2014-12-02 03:34:05 +08:00
// add an overload w different argument list
args.push_back(Argument(Qualified("Vector",Qualified::EIGEN),"v"));
2014-12-02 03:29:35 +08:00
cls.addMethod(verbose, is_const, name, args, retVal, tmplate);
2014-11-13 07:39:15 +08:00
EXPECT_LONGS_EQUAL(1, cls.nrMethods());
2014-12-02 03:34:05 +08:00
EXPECT_LONGS_EQUAL(2, cls.method(name).nrOverloads());
// add with non-trivial template list, will create two different functions
boost::optional<Template> t = //
CreateTemplate("template<T = {Point2, Point3}>");
CHECK(t);
cls.addMethod(verbose, is_const, name, args, retVal, *t);
EXPECT_LONGS_EQUAL(3, cls.nrMethods());
EXPECT_LONGS_EQUAL(2, cls.method(name).nrOverloads());
2014-11-13 07:39:15 +08:00
}
/* ************************************************************************* */
// test templated methods
TEST( Class, TemplatedMethods ) {
Class cls;
const string name = "method";
EXPECT(!cls.exists(name));
bool verbose = true, is_const = true;
ArgumentList args;
Argument arg;
2014-12-01 03:12:03 +08:00
arg.type.name_ = "T";
2014-11-13 07:39:15 +08:00
args.push_back(arg);
const ReturnValue retVal(ReturnType("T"));
2014-12-02 03:29:35 +08:00
boost::optional<Template> tmplate = //
CreateTemplate("template<T = {Point2, Point3}>");
CHECK(tmplate);
cls.addMethod(verbose, is_const, name, args, retVal, *tmplate);
2014-11-13 07:39:15 +08:00
EXPECT_LONGS_EQUAL(2, cls.nrMethods());
EXPECT(cls.exists(name+"Point2"));
EXPECT(cls.exists(name+"Point3"));
}
/* ************************************************************************* */
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */