Skip to content

Add changes required to compile with MS VC6 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion UnitTest++/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion UnitTest++/DeferredTestResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion UnitTest++/HelperMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions UnitTest++/MemoryOutStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 17 additions & 3 deletions UnitTest++/MemoryOutStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cstddef>

#ifdef UNITTEST_COMPILER_IS_MSVC6
namespace std {}
#endif

namespace UnitTest
{

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
18 changes: 15 additions & 3 deletions tests/TestMemoryOutStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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());
}

Expand Down