mirror of
https://github.com/unittest-cpp/unittest-cpp
synced 2026-09-26 16:19:30 +03:00
Adapt MemoryOutStream for VC6 __int64 type
This commit is contained in:
parent
424918c2d5
commit
65d2e03ec9
3 changed files with 67 additions and 8 deletions
|
|
@ -16,6 +16,33 @@ void MemoryOutStream::Clear()
|
|||
m_text = this->str();
|
||||
}
|
||||
|
||||
#ifdef UNITTEST_COMPILER_IS_MSVC6
|
||||
|
||||
#define snprintf _snprintf
|
||||
|
||||
template<typename ValueType>
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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 <cstddef>
|
||||
|
||||
#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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue