gtsam/CppUnitLite/Test.cpp

76 lines
1.6 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
* -------------------------------------------------------------------------- */
2009-08-22 06:23:24 +08:00
#include "Test.h"
#include "TestRegistry.h"
#include "TestResult.h"
#include "Failure.h"
#include <boost/lexical_cast.hpp>
2009-08-22 06:23:24 +08:00
Test::Test (const std::string& testName)
2009-08-22 06:23:24 +08:00
: name_ (testName)
{
TestRegistry::addTest (this);
}
Test::Test (const std::string& testName, const std::string& filename, long lineNumber, bool safeCheck = true)
: name_(testName), filename_(filename), lineNumber_(lineNumber), safeCheck_(safeCheck)
{
TestRegistry::addTest (this);
}
2009-08-22 06:23:24 +08:00
Test *Test::getNext() const
{
return next_;
}
void Test::setNext(Test *test)
{
next_ = test;
}
bool Test::check(long expected, long actual, TestResult& result, const std::string& fileName, long lineNumber)
2009-08-22 06:23:24 +08:00
{
if (expected == actual)
return true;
result.addFailure (
Failure (
name_,
boost::lexical_cast<std::string> (__FILE__),
2009-08-22 06:23:24 +08:00
__LINE__,
boost::lexical_cast<std::string> (expected),
boost::lexical_cast<std::string> (actual)));
2009-08-22 06:23:24 +08:00
return false;
}
bool Test::check(const std::string& expected, const std::string& actual, TestResult& result, const std::string& fileName, long lineNumber)
2009-08-22 06:23:24 +08:00
{
if (expected == actual)
return true;
result.addFailure (
Failure (
name_,
boost::lexical_cast<std::string> (__FILE__),
2009-08-22 06:23:24 +08:00
__LINE__,
expected,
actual));
return false;
}