diff --git a/gtsam/base/Makefile.am b/gtsam/base/Makefile.am index 4d10680f3..c01b20f7a 100644 --- a/gtsam/base/Makefile.am +++ b/gtsam/base/Makefile.am @@ -25,6 +25,7 @@ endif # Testing headers += Testable.h TestableAssertions.h numericalDerivative.h sources += timing.cpp debug.cpp +check_PROGRAMS += tests/testDebug # Lie Groups headers += Lie.h Lie-inl.h lieProxies.h LieScalar.h diff --git a/gtsam/base/debug.cpp b/gtsam/base/debug.cpp index 57951d756..4da6dc6c6 100644 --- a/gtsam/base/debug.cpp +++ b/gtsam/base/debug.cpp @@ -9,8 +9,6 @@ namespace gtsam { -#ifdef GTSAM_ENABLE_DEBUG FastMap > debugFlags; -#endif } diff --git a/gtsam/base/debug.h b/gtsam/base/debug.h index 215766661..51074bd46 100644 --- a/gtsam/base/debug.h +++ b/gtsam/base/debug.h @@ -5,8 +5,6 @@ * @created Feb 1, 2011 */ -#pragma once - #include #include #include @@ -32,19 +30,22 @@ #endif #endif -#ifdef GTSAM_ENABLE_DEBUG - namespace gtsam { extern FastMap > debugFlags; } +#undef ISDEBUG +#undef SETDEBUG + +#ifdef GTSAM_ENABLE_DEBUG + #define ISDEBUG(S) (gtsam::debugFlags[S]) -#define SETDEBUG(S,V) (gtsam::debugFlags[S] = (V)) +#define SETDEBUG(S,V) ((void)(gtsam::debugFlags[S] = (V))) #else #define ISDEBUG(S) (false) -#define SETDEBUG(S,V) (false) +#define SETDEBUG(S,V) ((void)false) #endif diff --git a/gtsam/base/tests/testDebug.cpp b/gtsam/base/tests/testDebug.cpp new file mode 100644 index 000000000..49e86a307 --- /dev/null +++ b/gtsam/base/tests/testDebug.cpp @@ -0,0 +1,53 @@ +/* ---------------------------------------------------------------------------- + + * 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 testCholesky.cpp + * @brief + * @author Richard Roberts + * @created Feb 14, 2011 + */ + +#include + +#define NDEBUG +#undef GTSAM_ENABLE_DEBUG +#include + +/* ************************************************************************* */ +TEST(Debug, debug_disabled) { + const bool debug1 = ISDEBUG("TestDebug"); + EXPECT(!debug1); + + SETDEBUG("TestDebug", true); + bool debug2 = ISDEBUG("TestDebug"); + EXPECT(!debug2); +} + +#define GTSAM_ENABLE_DEBUG +#include + +/* ************************************************************************* */ +TEST(Debug, debug_enabled) { + const bool debug1 = ISDEBUG("TestDebug"); + EXPECT(!debug1); + + SETDEBUG("TestDebug", true); + bool debug2 = ISDEBUG("TestDebug"); + EXPECT(debug2); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */