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 @@ private: 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 @@ public: 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/TestMemoryOutStream.cpp b/tests/TestMemoryOutStream.cpp index 9b2aa1f..ff1e920 100644 --- a/tests/TestMemoryOutStream.cpp +++ b/tests/TestMemoryOutStream.cpp @@ -167,12 +167,15 @@ TEST(StreamingMinUnsignedLongWritesCorrectCharacters) CHECK_EQUAL("0", stream.GetText()); } -#ifndef UNITTEST_COMPILER_IS_MSVC6 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 @@ -196,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 @@ -212,10 +219,13 @@ 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()); } -#endif TEST(StreamingFloatWritesCorrectCharacters) {