From 251c1ff8aecaa608ef9e6041c2691d369430bf7b Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sun, 14 Jul 2002 18:48:32 +0000 Subject: CodingGuideLines. CodingGuideLines.txt: added. CppUnit's coding guidelines for portability. * include/cppunit/portability/CppUnitStack.h: added. wrapper for std::stack. * include/cppunit/portability/CppUnitSet.h: added. wrapper for std::set. * include/cppunit/ui/text/TestRunner.h: fixed namespace definition for deprecated TestRunner. * include/cppunit/TestAssert.h: * src/cppunit/TestAssert.cpp: removed old deprecated functions that did not use SourceLine. Moved assertEquals() and assertDoubleEquals() into CppUnit namespace. * src/cppunit/TestFactoryRegistry.cpp: use CppUnitMap instead of std::map. * src/DllPlugInTester/CommandLineParser.h: use CppUnitDeque instead std::deque. * examples/cppunittest/*.h: * examples/cppunittest/*.cpp: removed all usage of CppUnitTest namespace. Everything is now in global space. * examples/*/*.h: * examples/*/*.cpp: replaced usage of CppUnit:: with CPPUNIT_NS::. * examples/ClockerPlugIn/ClockerModel.h: use CppUnit STL wrapper instead of STL container. --- include/cppunit/TestAssert.h | 106 ++++++++--------------- include/cppunit/TextTestRunner.h | 14 --- include/cppunit/XmlOutputter.h | 4 +- include/cppunit/config/config-msvc6.h | 5 +- include/cppunit/extensions/TestFactoryRegistry.h | 4 +- include/cppunit/plugin/TestPlugIn.h | 3 +- include/cppunit/portability/CppUnitDeque.h | 4 - include/cppunit/portability/CppUnitMap.h | 4 - include/cppunit/portability/CppUnitSet.h | 27 ++++++ include/cppunit/portability/CppUnitStack.h | 26 ++++++ include/cppunit/portability/CppUnitVector.h | 4 - include/cppunit/portability/Makefile.am | 6 +- include/cppunit/ui/text/TestRunner.h | 19 ++-- include/cppunit/ui/text/TextTestRunner.h | 1 - 14 files changed, 115 insertions(+), 112 deletions(-) create mode 100644 include/cppunit/portability/CppUnitSet.h create mode 100644 include/cppunit/portability/CppUnitStack.h (limited to 'include/cppunit') diff --git a/include/cppunit/TestAssert.h b/include/cppunit/TestAssert.h index ba30e9c..87510df 100644 --- a/include/cppunit/TestAssert.h +++ b/include/cppunit/TestAssert.h @@ -49,66 +49,34 @@ struct assertion_traits }; -namespace TestAssert +/*! \brief (Implementation) Asserts that two objects of the same type are equals. + * Use CPPUNIT_ASSERT_EQUAL instead of this function. + * \sa assertion_traits, Asserter::failNotEqual(). + */ +template +void assertEquals( const T& expected, + const T& actual, + SourceLine sourceLine, + const std::string &message ="" ) { -#ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED - void CPPUNIT_API assertImplementation( bool condition, - std::string conditionExpression = "", - long lineNumber, - std::string fileName ); - - void CPPUNIT_API assertNotEqualImplementation( std::string expected, - std::string actual, - long lineNumber, - std::string fileName ); - - - template - void assertEquals( const T& expected, - const T& actual, - long lineNumber, - std::string fileName ) + if ( !assertion_traits::equal(expected,actual) ) // lazy toString conversion... { - if ( !assertion_traits::equal(expected,actual) ) // lazy toString conversion... - { - assertNotEqualImplementation( assertion_traits::toString(expected), - assertion_traits::toString(actual), - lineNumber, - fileName ); - } + Asserter::failNotEqual( assertion_traits::toString(expected), + assertion_traits::toString(actual), + sourceLine, + message ); } - - void CPPUNIT_API assertEquals( double expected, - double actual, - double delta, - long lineNumber, - std::string fileName ); - -#else // using SourceLine - - template - void assertEquals( const T& expected, - const T& actual, - SourceLine sourceLine, - const std::string &message ="" ) - { - if ( !assertion_traits::equal(expected,actual) ) // lazy toString conversion... - { - Asserter::failNotEqual( assertion_traits::toString(expected), - assertion_traits::toString(actual), - sourceLine, - message ); - } - } - - void CPPUNIT_API assertDoubleEquals( double expected, - double actual, - double delta, - SourceLine sourceLine ); - -#endif } +/*! \brief (Implementation) Asserts that two double are equals given a tolerance. + * Use CPPUNIT_ASSERT_DOUBLES_EQUAL instead of this function. + * \sa Asserter::failNotEqual(). + */ +void CPPUNIT_API assertDoubleEquals( double expected, + double actual, + double delta, + SourceLine sourceLine ); + /* A set of macros which allow us to get the line number * and file name at the point of an error. @@ -155,9 +123,9 @@ namespace TestAssert #ifdef CPPUNIT_ENABLE_SOURCELINE_DEPRECATED /// Generalized macro for primitive value comparisons #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ - ( CPPUNIT_NS::TestAssert::assertEquals( (expected), \ - (actual), \ - __LINE__, __FILE__ ) ) + ( CPPUNIT_NS::assertEquals( (expected), \ + (actual), \ + __LINE__, __FILE__ ) ) #else /** Asserts that two values are equals. * \ingroup Assertions @@ -176,9 +144,9 @@ namespace TestAssert * removed by specializing the CppUnit::assertion_traits. */ #define CPPUNIT_ASSERT_EQUAL(expected,actual) \ - ( CPPUNIT_NS::TestAssert::assertEquals( (expected), \ - (actual), \ - CPPUNIT_SOURCELINE() ) ) + ( CPPUNIT_NS::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE() ) ) /** Asserts that two values are equals, provides additional messafe on failure. * \ingroup Assertions @@ -199,20 +167,20 @@ namespace TestAssert * removed by specializing the CppUnit::assertion_traits. */ #define CPPUNIT_ASSERT_EQUAL_MESSAGE(message,expected,actual) \ - ( CPPUNIT_NS::TestAssert::assertEquals( (expected), \ - (actual), \ - CPPUNIT_SOURCELINE(), \ - (message) ) ) + ( CPPUNIT_NS::assertEquals( (expected), \ + (actual), \ + CPPUNIT_SOURCELINE(), \ + (message) ) ) #endif /*! \brief Macro for primitive value comparisons * \ingroup Assertions */ #define CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,delta) \ - ( CPPUNIT_NS::TestAssert::assertDoubleEquals( (expected), \ - (actual), \ - (delta), \ - CPPUNIT_SOURCELINE() ) ) + ( CPPUNIT_NS::assertDoubleEquals( (expected), \ + (actual), \ + (delta), \ + CPPUNIT_SOURCELINE() ) ) // Backwards compatibility diff --git a/include/cppunit/TextTestRunner.h b/include/cppunit/TextTestRunner.h index 28c2513..23890e0 100644 --- a/include/cppunit/TextTestRunner.h +++ b/include/cppunit/TextTestRunner.h @@ -3,18 +3,4 @@ #include - -#if !defined(CPPUNIT_NO_NAMESPACE) -namespace TextUi -{ - - /*! Text TestRunner (DEPRECATED). - * \deprecated Use TextTestRunner instead. - */ - typedef TextTestRunner TestRunner; - -} -#endif - - #endif // CPPUNIT_TEXTTESTRUNNER_H diff --git a/include/cppunit/XmlOutputter.h b/include/cppunit/XmlOutputter.h index b28b727..fafffa2 100644 --- a/include/cppunit/XmlOutputter.h +++ b/include/cppunit/XmlOutputter.h @@ -10,8 +10,8 @@ #include #include +#include #include -#include CPPUNIT_NS_BEGIN @@ -76,7 +76,7 @@ public: virtual void setStyleSheet( const std::string &styleSheet ); - typedef std::map FailedTests; + typedef CppUnitMap FailedTests; /*! Sets the root element and adds its children. * diff --git a/include/cppunit/config/config-msvc6.h b/include/cppunit/config/config-msvc6.h index eea5cf6..2c48a92 100644 --- a/include/cppunit/config/config-msvc6.h +++ b/include/cppunit/config/config-msvc6.h @@ -56,8 +56,9 @@ // Uncomment to turn on STL wrapping => use this to test compilation. // This will make CppUnit subclass std::vector & co to provide default // parameter. -#define CPPUNIT_STD_NEED_ALLOCATOR 1 -#define CPPUNIT_STD_ALLOCATOR std::allocator +//#define CPPUNIT_STD_NEED_ALLOCATOR 1 +//#define CPPUNIT_STD_ALLOCATOR std::allocator +#define CPPUNIT_NO_NAMESPACE 1 /* _INCLUDE_CPPUNIT_CONFIG_MSVC6_H */ diff --git a/include/cppunit/extensions/TestFactoryRegistry.h b/include/cppunit/extensions/TestFactoryRegistry.h index 1164bf3..8109d40 100644 --- a/include/cppunit/extensions/TestFactoryRegistry.h +++ b/include/cppunit/extensions/TestFactoryRegistry.h @@ -8,8 +8,8 @@ #pragma warning( disable: 4251) // X needs to have dll-interface to be used by clients of class Z #endif +#include #include -#include #include CPPUNIT_NS_BEGIN @@ -165,7 +165,7 @@ private: void operator =( const TestFactoryRegistry © ); private: - typedef std::set Factories; + typedef CppUnitSet Factories; Factories m_factories; std::string m_name; diff --git a/include/cppunit/plugin/TestPlugIn.h b/include/cppunit/plugin/TestPlugIn.h index d206d79..06e0888 100644 --- a/include/cppunit/plugin/TestPlugIn.h +++ b/include/cppunit/plugin/TestPlugIn.h @@ -14,7 +14,8 @@ class Test; class TestFactoryRegistry; class TestResult; class XmlOutputter; -} + +CPPUNIT_NS_END /*! \file */ diff --git a/include/cppunit/portability/CppUnitDeque.h b/include/cppunit/portability/CppUnitDeque.h index 781c43e..fac09d6 100644 --- a/include/cppunit/portability/CppUnitDeque.h +++ b/include/cppunit/portability/CppUnitDeque.h @@ -9,16 +9,12 @@ #if CPPUNIT_STD_NEED_ALLOCATOR -CPPUNIT_NS_BEGIN - template class CppUnitDeque : public std::deque { public: }; -CPPUNIT_NS_END - #else // CPPUNIT_STD_NEED_ALLOCATOR #define CppUnitDeque std::deque diff --git a/include/cppunit/portability/CppUnitMap.h b/include/cppunit/portability/CppUnitMap.h index 24df4a5..3073e6f 100644 --- a/include/cppunit/portability/CppUnitMap.h +++ b/include/cppunit/portability/CppUnitMap.h @@ -10,8 +10,6 @@ #if CPPUNIT_STD_NEED_ALLOCATOR -CPPUNIT_NS_BEGIN - template class CppUnitMap : public std::map +#include +#include + + +#if CPPUNIT_STD_NEED_ALLOCATOR + +template +class CppUnitSet : public std::set + ,CPPUNIT_STD_ALLOCATOR> +{ +public: +}; + +#else // CPPUNIT_STD_NEED_ALLOCATOR + +#define CppUnitSet std::set + +#endif + +#endif // CPPUNIT_PORTABILITY_CPPUNITSET_H \ No newline at end of file diff --git a/include/cppunit/portability/CppUnitStack.h b/include/cppunit/portability/CppUnitStack.h new file mode 100644 index 0000000..bc7785b --- /dev/null +++ b/include/cppunit/portability/CppUnitStack.h @@ -0,0 +1,26 @@ +#ifndef CPPUNIT_PORTABILITY_CPPUNITSTACK_H +#define CPPUNIT_PORTABILITY_CPPUNITSTACK_H + +// The technic used is similar to the wrapper of STLPort. + +#include +#include +#include + + +#if CPPUNIT_STD_NEED_ALLOCATOR + +template +class CppUnitStack : public std::stack > +{ +public: +}; + +#else // CPPUNIT_STD_NEED_ALLOCATOR + +#define CppUnitStack std::stack + +#endif + +#endif // CPPUNIT_PORTABILITY_CPPUNITSTACK_H \ No newline at end of file diff --git a/include/cppunit/portability/CppUnitVector.h b/include/cppunit/portability/CppUnitVector.h index f3157e6..83525d3 100644 --- a/include/cppunit/portability/CppUnitVector.h +++ b/include/cppunit/portability/CppUnitVector.h @@ -9,16 +9,12 @@ #if CPPUNIT_STD_NEED_ALLOCATOR -CPPUNIT_NS_BEGIN - template class CppUnitVector : public std::vector { public: }; -CPPUNIT_NS_END - #else // CPPUNIT_STD_NEED_ALLOCATOR #define CppUnitVector std::vector diff --git a/include/cppunit/portability/Makefile.am b/include/cppunit/portability/Makefile.am index c70aaf0..1fb032e 100644 --- a/include/cppunit/portability/Makefile.am +++ b/include/cppunit/portability/Makefile.am @@ -2,5 +2,7 @@ libcppunitincludedir = $(includedir)/cppunit/portability libcppunitinclude_HEADERS = \ CppUnitDeque.h \ - CppUnitVector.h \ - CppUnitMap.h + CppUnitMap.h \ + CppUnitSet.h \ + CppUnitStack.h \ + CppUnitVector.h diff --git a/include/cppunit/ui/text/TestRunner.h b/include/cppunit/ui/text/TestRunner.h index c931f66..023eb83 100644 --- a/include/cppunit/ui/text/TestRunner.h +++ b/include/cppunit/ui/text/TestRunner.h @@ -3,17 +3,22 @@ #include -CPPUNIT_NS_BEGIN +#if defined(CPPUNIT_HAVE_NAMESPACES) -/*! - * \brief A text mode test runner. - * \ingroup ExecutingTest - * \deprecated Use CppUnit::TextUi::TestRunner instead. - */ -typedef CPPUNIT_NS::TextUi::TestRunner TextTestRunner; +CPPUNIT_NS_BEGIN +namespace TextUi +{ + /*! Text TestRunner (DEPRECATED). + * \deprecated Use TextTestRunner instead. + */ + typedef TextTestRunner TestRunner; +} CPPUNIT_NS_END +#endif // defined(CPPUNIT_HAVE_NAMESPACES) + + #endif // CPPUNIT_UI_TEXT_TESTRUNNER_H diff --git a/include/cppunit/ui/text/TextTestRunner.h b/include/cppunit/ui/text/TextTestRunner.h index dee37a7..76e225e 100644 --- a/include/cppunit/ui/text/TextTestRunner.h +++ b/include/cppunit/ui/text/TextTestRunner.h @@ -4,7 +4,6 @@ #include #include -#include #include CPPUNIT_NS_BEGIN -- cgit v1.2.1