diff --git a/UnitTest++/Config.h b/UnitTest++/Config.h index 5313b09..4f695f7 100644 --- a/UnitTest++/Config.h +++ b/UnitTest++/Config.h @@ -7,7 +7,8 @@ #pragma warning(disable:4702) // unreachable code #pragma warning(disable:4722) // destructor never returns, potential memory leak - #if (_MSC_VER == 1200) // VC6 +#if (_MSC_VER == 1200) // VC6 + #define UNITTEST_COMPILER_IS_MSVC6 #pragma warning(disable:4786) #pragma warning(disable:4290) #endif @@ -60,4 +61,13 @@ //#define UNITTEST_NO_EXCEPTIONS + +// std namespace qualification: used for functions like strcpy that +// may live in std:: namespace (cstring header). +#if defined( UNITTEST_COMPILER_IS_MSVC6 ) + #define UNIITEST_NS_QUAL_STD(x) x +#else + #define UNIITEST_NS_QUAL_STD(x) ::std::x +#endif + #endif diff --git a/UnitTest++/DeferredTestResult.cpp b/UnitTest++/DeferredTestResult.cpp index 5071f82..cdad9eb 100644 --- a/UnitTest++/DeferredTestResult.cpp +++ b/UnitTest++/DeferredTestResult.cpp @@ -16,7 +16,7 @@ DeferredTestFailure::DeferredTestFailure() DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr_) : lineNumber(lineNumber_) { - std::strcpy(failureStr, failureStr_); + UNIITEST_NS_QUAL_STD(strcpy)(failureStr, failureStr_); } DeferredTestResult::DeferredTestResult() diff --git a/UnitTest++/HelperMacros.h b/UnitTest++/HelperMacros.h index fb3181d..699d99d 100644 --- a/UnitTest++/HelperMacros.h +++ b/UnitTest++/HelperMacros.h @@ -5,7 +5,7 @@ #define UNITTEST_MULTILINE_MACRO_BEGIN do { -#ifdef UNITTEST_WIN32 +#if defined(UNITTEST_WIN32) && !defined(UNITTEST_COMPILER_IS_MSVC6) #define UNITTEST_MULTILINE_MACRO_END \ } __pragma(warning(push)) __pragma(warning(disable:4127)) while (0) __pragma(warning(pop)) #else diff --git a/UnitTest++/MemoryOutStream.cpp b/UnitTest++/MemoryOutStream.cpp index 3c112b6..319dfda 100644 --- a/UnitTest++/MemoryOutStream.cpp +++ b/UnitTest++/MemoryOutStream.cpp @@ -16,6 +16,33 @@ void MemoryOutStream::Clear() m_text = this->str(); } +#ifdef UNITTEST_COMPILER_IS_MSVC6 + +#define snprintf _snprintf + +template +std::ostream& FormatToStream(std::ostream& stream, char const* format, ValueType const& value) +{ + using namespace std; + + const size_t BUFFER_SIZE=32; + char txt[BUFFER_SIZE]; + snprintf(txt, BUFFER_SIZE, format, value); + return stream << txt; +} + +std::ostream& operator<<(std::ostream& stream, __int64 const n) +{ + return FormatToStream(stream, "%I64d", n); +} + +std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n) +{ + return FormatToStream(stream, "%I64u", n); +} + +#endif + } #else @@ -108,7 +135,11 @@ MemoryOutStream& MemoryOutStream::operator <<(unsigned long const n) return *this; } +#ifdef UNITTEST_COMPILER_IS_MSVC6 +MemoryOutStream& MemoryOutStream::operator <<(__int64 const n) +#else MemoryOutStream& MemoryOutStream::operator <<(long long const n) +#endif { #ifdef UNITTEST_WIN32 FormatToStream(*this, "%I64d", n); @@ -119,7 +150,11 @@ MemoryOutStream& MemoryOutStream::operator <<(long long const n) return *this; } +#ifdef UNITTEST_COMPILER_IS_MSVC6 +MemoryOutStream& MemoryOutStream::operator <<(unsigned __int64 const n) +#else MemoryOutStream& MemoryOutStream::operator <<(unsigned long long const n) +#endif { #ifdef UNITTEST_WIN32 FormatToStream(*this, "%I64u", n); diff --git a/UnitTest++/MemoryOutStream.h b/UnitTest++/MemoryOutStream.h index 0c46f53..b9cea19 100644 --- a/UnitTest++/MemoryOutStream.h +++ b/UnitTest++/MemoryOutStream.h @@ -26,12 +26,21 @@ class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream mutable std::string m_text; }; +#ifdef UNITTEST_COMPILER_IS_MSVC6 +std::ostream& operator<<(std::ostream& stream, __int64 const n); +std::ostream& operator<<(std::ostream& stream, unsigned __int64 const n); +#endif + } #else #include +#ifdef UNITTEST_COMPILER_IS_MSVC6 +namespace std {} +#endif + namespace UnitTest { @@ -47,10 +56,15 @@ class UNITTEST_LINKAGE MemoryOutStream MemoryOutStream& operator <<(char const* txt); MemoryOutStream& operator <<(int n); MemoryOutStream& operator <<(long n); - MemoryOutStream& operator <<(long long n); MemoryOutStream& operator <<(unsigned long n); - MemoryOutStream& operator <<(unsigned long long n); - MemoryOutStream& operator <<(float f); +#ifdef UNITTEST_COMPILER_IS_MSVC6 + MemoryOutStream& operator <<(__int64 n); + MemoryOutStream& operator <<(unsigned __int64 n); +#else + MemoryOutStream& operator <<(long long n); + MemoryOutStream& operator <<(unsigned long long n); +#endif + MemoryOutStream& operator <<(float f); MemoryOutStream& operator <<(double d); MemoryOutStream& operator <<(void const* p); MemoryOutStream& operator <<(unsigned int s); diff --git a/tests/TestChecks.cpp b/tests/TestChecks.cpp index 758ca31..9554b31 100644 --- a/tests/TestChecks.cpp +++ b/tests/TestChecks.cpp @@ -150,7 +150,7 @@ TEST(CheckCloseWithNaNFails) { const unsigned int bitpattern = 0xFFFFFFFF; float nan; - std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern)); TestResults results; CheckClose(results, 3.0f, nan, 0.1f, TestDetails("", "", "", 0)); @@ -161,7 +161,7 @@ TEST(CheckCloseWithNaNAgainstItselfFails) { const unsigned int bitpattern = 0xFFFFFFFF; float nan; - std::memcpy(&nan, &bitpattern, sizeof(bitpattern)); + UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern)); TestResults results; CheckClose(results, nan, nan, 0.1f, TestDetails("", "", "", 0)); diff --git a/tests/TestMemoryOutStream.cpp b/tests/TestMemoryOutStream.cpp index 74a9a56..ff1e920 100644 --- a/tests/TestMemoryOutStream.cpp +++ b/tests/TestMemoryOutStream.cpp @@ -170,8 +170,12 @@ TEST(StreamingMinUnsignedLongWritesCorrectCharacters) TEST(StreamingLongLongWritesCorrectCharacters) { MemoryOutStream stream; +#ifdef UNITTEST_COMPILER_IS_MSVC6 + stream << (__int64)-12345i64; +#else stream << (long long)-12345ll; - CHECK_EQUAL("-12345", stream.GetText()); +#endif + CHECK_EQUAL("-12345", stream.GetText()); } #ifdef LLONG_MAX @@ -195,8 +199,12 @@ TEST(StreamingMinLongLongWritesCorrectCharacters) TEST(StreamingUnsignedLongLongWritesCorrectCharacters) { MemoryOutStream stream; - stream << (unsigned long long)85899ull; - CHECK_EQUAL("85899", stream.GetText()); +#ifdef UNITTEST_COMPILER_IS_MSVC6 + stream << (unsigned __int64)85899ui64; +#else + stream << (unsigned long long)85899ull; +#endif + CHECK_EQUAL("85899", stream.GetText()); } #ifdef ULLONG_MAX @@ -211,7 +219,11 @@ TEST(StreamingMaxUnsignedLongLongWritesCorrectCharacters) TEST(StreamingMinUnsignedLongLongWritesCorrectCharacters) { MemoryOutStream stream; +#ifdef UNITTEST_COMPILER_IS_MSVC6 + stream << (unsigned __int64)0ui64; +#else stream << (unsigned long long)0ull; +#endif CHECK_EQUAL("0", stream.GetText()); }