diff --git a/CppUnitLite/Failure.cpp b/CppUnitLite/Failure.cpp index d0c919165..591485b04 100644 --- a/CppUnitLite/Failure.cpp +++ b/CppUnitLite/Failure.cpp @@ -13,14 +13,10 @@ #include "Failure.h" -#include -#include - - -Failure::Failure (const SimpleString& theTestName, - const SimpleString& theFileName, +Failure::Failure (const std::string& theTestName, + const std::string& theFileName, long theLineNumber, - const SimpleString& theCondition) + const std::string& theCondition) : message (theCondition), testName (theTestName), fileName (theFileName), @@ -28,9 +24,9 @@ Failure::Failure (const SimpleString& theTestName, { } -Failure::Failure (const SimpleString& theTestName, - const SimpleString& theFileName, - const SimpleString& theCondition) +Failure::Failure (const std::string& theTestName, + const std::string& theFileName, + const std::string& theCondition) : message (theCondition), testName (theTestName), fileName (theFileName), @@ -39,33 +35,16 @@ Failure::Failure (const SimpleString& theTestName, } -Failure::Failure (const SimpleString& theTestName, - const SimpleString& theFileName, +Failure::Failure (const std::string& theTestName, + const std::string& theFileName, long theLineNumber, - const SimpleString& expected, - const SimpleString& actual) -: testName (theTestName), + const std::string& expected, + const std::string& actual) +: message("expected " + expected + " but was: " + actual), + testName (theTestName), fileName (theFileName), lineNumber (theLineNumber) { - const char *part1 = "expected "; - const char *part3 = " but was: "; - - char *stage = new char [strlen (part1) - + expected.size () - + strlen (part3) - + actual.size () - + 1]; - - sprintf(stage, "%s%s%s%s", - part1, - expected.asCharString(), - part3, - actual.asCharString()); - - message = SimpleString(stage); - - delete stage; } diff --git a/CppUnitLite/Failure.h b/CppUnitLite/Failure.h index 1f898f08c..210ccd63d 100644 --- a/CppUnitLite/Failure.h +++ b/CppUnitLite/Failure.h @@ -24,32 +24,31 @@ #ifndef FAILURE_H #define FAILURE_H -#include "SimpleString.h" - +#include class Failure { public: - Failure (const SimpleString& theTestName, - const SimpleString& theFileName, + Failure (const std::string& theTestName, + const std::string& theFileName, long theLineNumber, - const SimpleString& theCondition); + const std::string& theCondition); - Failure (const SimpleString& theTestName, - const SimpleString& theFileName, + Failure (const std::string& theTestName, + const std::string& theFileName, long theLineNumber, - const SimpleString& expected, - const SimpleString& actual); + const std::string& expected, + const std::string& actual); - Failure (const SimpleString& theTestName, - const SimpleString& theFileName, - const SimpleString& theCondition); + Failure (const std::string& theTestName, + const std::string& theFileName, + const std::string& theCondition); - SimpleString message; - SimpleString testName; - SimpleString fileName; + std::string message; + std::string testName; + std::string fileName; long lineNumber; }; diff --git a/CppUnitLite/SimpleString.cpp b/CppUnitLite/SimpleString.cpp deleted file mode 100644 index 3fa040f63..000000000 --- a/CppUnitLite/SimpleString.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* ---------------------------------------------------------------------------- - - * 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 - - * -------------------------------------------------------------------------- */ - - - -#include "SimpleString.h" -#include -#include -#include - - -static const int DEFAULT_SIZE = 20; - -SimpleString::SimpleString () -: buffer_(new char [1]) -{ - buffer_ [0] = '\0'; -} - - -SimpleString::SimpleString (const char *otherBuffer) -: buffer_ (new char [strlen (otherBuffer) + 1]) -{ - strcpy (buffer_, otherBuffer); -} - -SimpleString::SimpleString (const SimpleString& other) -{ - buffer_ = new char [other.size() + 1]; - strcpy(buffer_, other.buffer_); -} - - -SimpleString SimpleString::operator= (const SimpleString& other) -{ - delete [] buffer_; - buffer_ = new char [other.size() + 1]; - strcpy(buffer_, other.buffer_); - return *this; -} - -SimpleString SimpleString::operator+ (const SimpleString& other) -{ - SimpleString ret; - delete [] ret.buffer_; - ret.buffer_ = new char [size() + other.size() + 1]; - strcpy(ret.buffer_, buffer_); - strcat(ret.buffer_, other.buffer_); - return ret; -} - -char *SimpleString::asCharString () const -{ - return buffer_; -} - -int SimpleString::size() const -{ - return strlen (buffer_); -} - -SimpleString::~SimpleString () -{ - delete [] buffer_; -} - - -bool operator== (const SimpleString& left, const SimpleString& right) -{ - return !strcmp (left.asCharString (), right.asCharString ()); -} - - -SimpleString StringFrom (bool value) -{ - char buffer [sizeof ("false") + 1]; - sprintf (buffer, "%s", value ? "true" : "false"); - return SimpleString(buffer); -} - -SimpleString StringFrom (const char *value) -{ - return SimpleString(value); -} - -SimpleString StringFrom (long value) -{ - char buffer [DEFAULT_SIZE]; - sprintf (buffer, "%ld", value); - - return SimpleString(buffer); -} - -SimpleString StringFrom (double value) -{ - char buffer [DEFAULT_SIZE]; - sprintf (buffer, "%lg", value); - - return SimpleString(buffer); -} - -SimpleString StringFrom (const SimpleString& value) -{ - return SimpleString(value); -} - - diff --git a/CppUnitLite/SimpleString.h b/CppUnitLite/SimpleString.h deleted file mode 100644 index c454e5571..000000000 --- a/CppUnitLite/SimpleString.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ---------------------------------------------------------------------------- - - * 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 - - * -------------------------------------------------------------------------- */ - - -/////////////////////////////////////////////////////////////////////////////// -// -// SIMPLESTRING.H -// -// One of the design goals of CppUnitLite is to compilation with very old C++ -// compilers. For that reason, I've added a simple string class that provides -// only the operations needed in CppUnitLite. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef SIMPLE_STRING -#define SIMPLE_STRING - - - -class SimpleString -{ - friend bool operator== (const SimpleString& left, const SimpleString& right); - -public: - SimpleString (); - SimpleString (const char *value); - SimpleString (const SimpleString& other); - ~SimpleString (); - - SimpleString operator= (const SimpleString& other); - SimpleString operator+ (const SimpleString& other); - - char *asCharString () const; - int size() const; - -private: - char *buffer_; -}; - - - -SimpleString StringFrom (bool value); -SimpleString StringFrom (const char *value); -SimpleString StringFrom (long value); -SimpleString StringFrom (double value); -SimpleString StringFrom (const SimpleString& other); - - -#endif diff --git a/CppUnitLite/Test.cpp b/CppUnitLite/Test.cpp index 1d9902b37..07230436e 100644 --- a/CppUnitLite/Test.cpp +++ b/CppUnitLite/Test.cpp @@ -10,20 +10,20 @@ * -------------------------------------------------------------------------- */ - #include "Test.h" #include "TestRegistry.h" #include "TestResult.h" #include "Failure.h" +#include -Test::Test (const SimpleString& testName) +Test::Test (const std::string& testName) : name_ (testName) { TestRegistry::addTest (this); } -Test::Test (const SimpleString& testName, const SimpleString& filename, long lineNumber, bool safeCheck = true) +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); @@ -40,31 +40,31 @@ void Test::setNext(Test *test) next_ = test; } -bool Test::check(long expected, long actual, TestResult& result, const SimpleString& fileName, long lineNumber) +bool Test::check(long expected, long actual, TestResult& result, const std::string& fileName, long lineNumber) { if (expected == actual) return true; result.addFailure ( Failure ( name_, - StringFrom (__FILE__), + boost::lexical_cast (__FILE__), __LINE__, - StringFrom (expected), - StringFrom (actual))); + boost::lexical_cast (expected), + boost::lexical_cast (actual))); return false; } -bool Test::check(const SimpleString& expected, const SimpleString& actual, TestResult& result, const SimpleString& fileName, long lineNumber) +bool Test::check(const std::string& expected, const std::string& actual, TestResult& result, const std::string& fileName, long lineNumber) { if (expected == actual) return true; result.addFailure ( Failure ( name_, - StringFrom (__FILE__), + boost::lexical_cast (__FILE__), __LINE__, expected, actual)); diff --git a/CppUnitLite/Test.h b/CppUnitLite/Test.h index 89d96f463..d5d5d1d2f 100644 --- a/CppUnitLite/Test.h +++ b/CppUnitLite/Test.h @@ -23,7 +23,7 @@ #include -#include "SimpleString.h" +#include class TestResult; @@ -32,8 +32,8 @@ class TestResult; class Test { public: - Test (const SimpleString& testName); - Test (const SimpleString& testName, const SimpleString& filename, long lineNumber, bool safeCheck); + Test (const std::string& testName); + Test (const std::string& testName, const std::string& filename, long lineNumber, bool safeCheck); virtual ~Test() {}; virtual void run (TestResult& result) = 0; @@ -41,19 +41,19 @@ public: void setNext(Test *test); Test *getNext () const; - SimpleString getName() const {return name_;} - SimpleString getFilename() const {return filename_;} + std::string getName() const {return name_;} + std::string getFilename() const {return filename_;} long getLineNumber() const {return lineNumber_;} bool safe() const {return safeCheck_;} protected: - bool check (long expected, long actual, TestResult& result, const SimpleString& fileName, long lineNumber); - bool check (const SimpleString& expected, const SimpleString& actual, TestResult& result, const SimpleString& fileName, long lineNumber); + bool check (long expected, long actual, TestResult& result, const std::string& fileName, long lineNumber); + bool check (const std::string& expected, const std::string& actual, TestResult& result, const std::string& fileName, long lineNumber); - SimpleString name_; + std::string name_; Test *next_; - SimpleString filename_; + std::string filename_; long lineNumber_; /// This is the line line number of the test, rather than the a single check bool safeCheck_; @@ -102,17 +102,17 @@ protected: #define THROWS_EXCEPTION(condition)\ { try { condition; \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Didn't throw: ") + StringFrom(#condition))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast(#condition))); \ return; } \ catch (...) {} } #define CHECK_EXCEPTION(condition, exception_name)\ { try { condition; \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Didn't throw: ") + StringFrom(#condition))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast(#condition))); \ return; } \ catch (exception_name&) {} \ catch (...) { \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, SimpleString("Wrong exception: ") + StringFrom(#condition) + StringFrom(", expected: ") + StringFrom(#exception_name))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Wrong exception: ") + boost::lexical_cast(#condition) + boost::lexical_cast(", expected: ") + boost::lexical_cast(#exception_name))); \ return; } } #define EQUALITY(expected,actual)\ @@ -120,21 +120,21 @@ protected: result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); } #define CHECK_EQUAL(expected,actual)\ -{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, StringFrom(expected), StringFrom(actual))); } +{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, boost::lexical_cast(expected), boost::lexical_cast(actual))); } #define LONGS_EQUAL(expected,actual)\ { long actualTemp = actual; \ long expectedTemp = expected; \ if ((expectedTemp) != (actualTemp)) \ -{ result_.addFailure (Failure (name_, __FILE__, __LINE__, StringFrom(expectedTemp), \ -StringFrom(actualTemp))); return; } } +{ result_.addFailure (Failure (name_, __FILE__, __LINE__, boost::lexical_cast(expectedTemp), \ +boost::lexical_cast(actualTemp))); return; } } #define DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ if (fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ -StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); return; } } +boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); return; } } /* EXPECTs: tests will continue running after a failure */ @@ -146,15 +146,15 @@ StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); return; } } { long actualTemp = actual; \ long expectedTemp = expected; \ if ((expectedTemp) != (actualTemp)) \ -{ result_.addFailure (Failure (name_, __FILE__, __LINE__, StringFrom(expectedTemp), \ -StringFrom(actualTemp))); } } +{ result_.addFailure (Failure (name_, __FILE__, __LINE__, boost::lexical_cast(expectedTemp), \ +boost::lexical_cast(actualTemp))); } } #define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ if (fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ -StringFrom((double)expectedTemp), StringFrom((double)actualTemp))); } } +boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); } } #define FAIL(text) \ diff --git a/CppUnitLite/TestRegistry.cpp b/CppUnitLite/TestRegistry.cpp index fa5295229..1d06b225c 100644 --- a/CppUnitLite/TestRegistry.cpp +++ b/CppUnitLite/TestRegistry.cpp @@ -17,7 +17,6 @@ #include "Failure.h" #include "TestResult.h" #include "TestRegistry.h" -#include "SimpleString.h" void TestRegistry::addTest (Test *test) { @@ -65,12 +64,12 @@ int TestRegistry::run (TestResult& result) // catch standard exceptions and derivatives result.addFailure( Failure(test->getName(), test->getFilename(), test->getLineNumber(), - SimpleString("Exception: ") + SimpleString(e.what()))); + std::string("Exception: ") + std::string(e.what()))); } catch (...) { // catch all other exceptions result.addFailure( Failure(test->getName(), test->getFilename(), test->getLineNumber(), - SimpleString("ExceptionThrown!"))); + "ExceptionThrown!")); } } else { diff --git a/CppUnitLite/TestResult.cpp b/CppUnitLite/TestResult.cpp index 3bc8a8ad5..a9e599989 100644 --- a/CppUnitLite/TestResult.cpp +++ b/CppUnitLite/TestResult.cpp @@ -32,16 +32,16 @@ void TestResult::addFailure (const Failure& failure) if (failure.lineNumber < 0) // allow for no line number fprintf (stdout, "%s%s%s%s\n", "Failure: \"", - failure.message.asCharString (), + failure.message.c_str (), "\" in ", - failure.fileName.asCharString ()); + failure.fileName.c_str ()); else fprintf (stdout, "%s%s%ld%s%s%s\n", - failure.fileName.asCharString(), // Format matches Eclipse error flagging + failure.fileName.c_str(), // Format matches Eclipse error flagging ":", failure.lineNumber, ": Failure: \"", - failure.message.asCharString(), + failure.message.c_str(), "\" "); failureCount++; diff --git a/tests/testGaussianISAM2.cpp b/tests/testGaussianISAM2.cpp index 9fdd6512f..2c932680d 100644 --- a/tests/testGaussianISAM2.cpp +++ b/tests/testGaussianISAM2.cpp @@ -381,7 +381,7 @@ TEST(ISAM2, optimize2) { bool isam_check(const planarSLAM::Graph& fullgraph, const Values& fullinit, const ISAM2& isam, Test& test, TestResult& result) { TestResult& result_ = result; - const SimpleString name_ = test.getName(); + const std::string name_ = test.getName(); Values actual = isam.calculateEstimate(); Ordering ordering = isam.getOrdering(); // *fullgraph.orderingCOLAMD(fullinit).first;