CppUnit project page FAQ CppUnit home page

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Portability.h

Go to the documentation of this file.
00001 #ifndef CPPUNIT_PORTABILITY_H
00002 #define CPPUNIT_PORTABILITY_H
00003 
00004 #if defined(_WIN32) && !defined(WIN32)
00005 # define WIN32 1
00006 #endif
00007 
00008 /* include platform specific config */
00009 #if defined(__BORLANDC__)
00010 #    include <cppunit/config/config-bcb5.h>
00011 #elif defined (_MSC_VER)
00012 #    include <cppunit/config/config-msvc6.h>
00013 #else
00014 #    include <cppunit/config-auto.h>
00015 #endif
00016 
00017 // Version number of package
00018 #ifndef CPPUNIT_VERSION 
00019 #define CPPUNIT_VERSION  "1.10.2"
00020 #endif
00021  
00022 #include <cppunit/config/CppUnitApi.h>    // define CPPUNIT_API & CPPUNIT_NEED_DLL_DECL
00023 #include <cppunit/config/SelectDllLoader.h>
00024 
00025 
00026 /* Options that the library user may switch on or off.
00027  * If the user has not done so, we chose default values.
00028  */
00029 
00030 
00031 /* Define to 1 if you wish to have the old-style macros
00032    assert(), assertEqual(), assertDoublesEqual(), and assertLongsEqual() */
00033 #if !defined(CPPUNIT_ENABLE_NAKED_ASSERT)
00034 # define CPPUNIT_ENABLE_NAKED_ASSERT          0
00035 #endif
00036 
00037 /* Define to 1 if you wish to have the old-style CU_TEST family
00038    of macros. */
00039 #if !defined(CPPUNIT_ENABLE_CU_TEST_MACROS)
00040 # define CPPUNIT_ENABLE_CU_TEST_MACROS        0
00041 #endif
00042 
00043 /* Define to 1 if the preprocessor expands (#foo) to "foo" (quotes incl.) 
00044    I don't think there is any C preprocess that does NOT support this! */
00045 #if !defined(CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION)
00046 # define CPPUNIT_HAVE_CPP_SOURCE_ANNOTATION   1
00047 #endif
00048 
00049 /* Assumes that STL and CppUnit are in global space if the compiler does not
00050    support namespace. */
00051 #if !defined(CPPUNIT_HAVE_NAMESPACES)
00052 # if !defined(CPPUNIT_NO_NAMESPACE)
00053 #  define CPPUNIT_NO_NAMESPACE 1
00054 # endif // !defined(CPPUNIT_NO_NAMESPACE)
00055 # if !defined(CPPUNIT_NO_STD_NAMESPACE)
00056 #  define CPPUNIT_NO_STD_NAMESPACE 1
00057 # endif // !defined(CPPUNIT_NO_STD_NAMESPACE)
00058 #endif // !defined(CPPUNIT_HAVE_NAMESPACES)
00059 
00060 /* Define CPPUNIT_STD_NEED_ALLOCATOR to 1 if you need to specify
00061  * the allocator you used when instantiating STL container. Typically
00062  * used for compilers that do not support template default parameter.
00063  * CPPUNIT_STD_ALLOCATOR will be used as the allocator. Default is
00064  * std::allocator. On some compilers, you may need to change this to
00065  * std::allocator<T>.
00066  */
00067 #if CPPUNIT_STD_NEED_ALLOCATOR
00068 # if !defined(CPPUNIT_STD_ALLOCATOR)
00069 #  define CPPUNIT_STD_ALLOCATOR std::allocator
00070 # endif // !defined(CPPUNIT_STD_ALLOCATOR)
00071 #endif // defined(CPPUNIT_STD_NEED_ALLOCATOR)
00072 
00073 
00074 // Compiler error location format for CompilerOutputter
00075 // If not define, assumes that it's gcc
00076 // See class CompilerOutputter for format.
00077 #if !defined(CPPUNIT_COMPILER_LOCATION_FORMAT)
00078 # define CPPUNIT_COMPILER_LOCATION_FORMAT "%f:%l:"
00079 #endif
00080 
00081 // If CPPUNIT_HAVE_CPP_CAST is defined, then c++ style cast will be used,
00082 // otherwise, C style cast are used.
00083 #if defined( CPPUNIT_HAVE_CPP_CAST )
00084 # define CPPUNIT_CONST_CAST( TargetType, pointer ) \
00085     const_cast<TargetType>( pointer )
00086 
00087 # define CPPUNIT_STATIC_CAST( TargetType, pointer ) \
00088     static_cast<TargetType>( pointer )
00089 #else // defined( CPPUNIT_HAVE_CPP_CAST )
00090 # define CPPUNIT_CONST_CAST( TargetType, pointer ) \
00091     ((TargetType)( pointer ))
00092 # define CPPUNIT_STATIC_CAST( TargetType, pointer ) \
00093     ((TargetType)( pointer ))
00094 #endif // defined( CPPUNIT_HAVE_CPP_CAST )
00095 
00096 // If CPPUNIT_NO_STD_NAMESPACE is defined then STL are in the global space.
00097 // => Define macro 'std' to nothing
00098 #if defined(CPPUNIT_NO_STD_NAMESPACE)
00099 # undef std
00100 # define std
00101 #endif  // defined(CPPUNIT_NO_STD_NAMESPACE)
00102 
00103 // If CPPUNIT_NO_NAMESPACE is defined, then put CppUnit classes in the
00104 // global namespace: the compiler does not support namespace.
00105 #if defined(CPPUNIT_NO_NAMESPACE)
00106 # define CPPUNIT_NS_BEGIN
00107 # define CPPUNIT_NS_END
00108 # define CPPUNIT_NS
00109 #else   // defined(CPPUNIT_NO_NAMESPACE)
00110 # define CPPUNIT_NS_BEGIN namespace CppUnit {
00111 # define CPPUNIT_NS_END }
00112 # define CPPUNIT_NS CppUnit
00113 #endif  // defined(CPPUNIT_NO_NAMESPACE)
00114 
00125 #define CPPUNIT_STRINGIZE( symbol ) _CPPUNIT_DO_STRINGIZE( symbol )
00126 
00128 #define _CPPUNIT_DO_STRINGIZE( symbol ) #symbol
00129 
00148 #define CPPUNIT_JOIN( symbol1, symbol2 ) _CPPUNIT_DO_JOIN( symbol1, symbol2 )
00149 
00151 #define _CPPUNIT_DO_JOIN( symbol1, symbol2 ) _CPPUNIT_DO_JOIN2( symbol1, symbol2 )
00152 
00154 #define _CPPUNIT_DO_JOIN2( symbol1, symbol2 ) symbol1##symbol2
00155 
00160 #define CPPUNIT_MAKE_UNIQUE_NAME( prefix ) CPPUNIT_JOIN( prefix, __LINE__ )
00161 
00164 #if !defined(CPPUNIT_WRAP_COLUMN)
00165 # define CPPUNIT_WRAP_COLUMN 79
00166 #endif
00167 
00168 
00169 /* perform portability hacks */
00170 
00171 
00172 /* Define CPPUNIT_SSTREAM as a stream with a "std::string str()"
00173  * method.
00174  */
00175 #if CPPUNIT_HAVE_SSTREAM
00176 # include <sstream>
00177     CPPUNIT_NS_BEGIN
00178 
00179     typedef std::ostringstream OStringStream;
00180 
00181     CPPUNIT_NS_END
00182 #elif CPPUNIT_HAVE_CLASS_STRSTREAM
00183 # include <string>
00184 # if CPPUNIT_HAVE_STRSTREAM
00185 #   include <strstream>
00186 # else // CPPUNIT_HAVE_STRSTREAM
00187 #  include <strstream.h>
00188 # endif // CPPUNIT_HAVE_CLASS_STRSTREAM
00189 
00190     CPPUNIT_NS_BEGIN
00191 
00192       class OStringStream : public std::ostrstream 
00193       {
00194       public:
00195           std::string str()
00196           {
00197 //            (*this) << '\0';
00198 //            std::string msg(std::ostrstream::str());
00199 //            std::ostrstream::freeze(false);
00200 //            return msg;
00201 // Alternative implementation that don't rely on freeze which is not
00202 // available on some platforms:
00203             return std::string( std::ostrstream::str(), pcount() );
00204           }
00205       };
00206 
00207     CPPUNIT_NS_END
00208 #else // CPPUNIT_HAVE_CLASS_STRSTREAM
00209 #   error Cannot define CppUnit::OStringStream.
00210 #endif // CPPUNIT_HAVE_SSTREAM
00211 
00212 
00213 #endif // CPPUNIT_PORTABILITY_H

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers