Skip to content

Adding Borland C++ Builder 5 support. #137

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 22 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ option(UTPP_INCLUDE_TESTS_IN_BUILD
option(UTPP_AMPLIFY_WARNINGS
"Set this to OFF if you wish to use CMake default warning levels; should generally only use to work around support issues for your specific compiler"
ON)


if(BORLAND)
set(UTPP_USE_PLUS_SIGN OFF)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this set statement required for Borland? Can it not generate output files with + in the name?

string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " cp32mti.lib Vcl50.bpi Vclx50.bpi bcbsmp50.bpi Qrpt50.bpi Vcldb50.bpi Vclbde50.bpi ibsmp50.bpi vcldbx50.bpi TeeUI50.bpi TeeDB50.bpi Tee50.bpi TeeQR50.bpi VCLIB50.bpi bcbie50.bpi vclie50.bpi Inetdb50.bpi Inet50.bpi NMFast50.bpi dclocx50.bpi bcb2kaxserver50.bpi Memmgr.Lib ")
endif()

if(MSVC14 OR MSVC12)
# has the support we need
else()
Expand All @@ -32,6 +37,8 @@ if (${UTPP_AMPLIFY_WARNINGS})
# we are dealing with an MSVC or MSVC-like compiler (e.g. Intel on Windows)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
elseif(BORLAND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w-par")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
Expand Down Expand Up @@ -59,28 +66,34 @@ add_library(UnitTest++ STATIC ${headers_} ${sources_} ${platformHeaders_} ${plat

if(${UTPP_USE_PLUS_SIGN})
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTest++)
else()
set_target_properties(UnitTest++ PROPERTIES OUTPUT_NAME UnitTestpp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me this is changing the meaning of UTPP_USE_PLUS_SIGN; in its current incarnation it only changes the install path to use PP instead of ++. Am I right?

endif()


if(${UTPP_USE_PLUS_SIGN})
set(UTPP_TEST_NAME TestUnitTest++)
else()
set(UTPP_TEST_NAME TestUnitTestPP)
endif()

# build the test runner
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tests/*.cpp tests/*.h)
source_group( "" FILES ${TEST_SRCS})
add_executable(TestUnitTest++ ${TEST_SRCS})
add_executable(${UTPP_TEST_NAME} ${TEST_SRCS})
include_directories(.)

if(${UTPP_USE_PLUS_SIGN})
set_target_properties(TestUnitTest++ PROPERTIES OUTPUT_NAME TestUnitTest++)
endif()
set_target_properties(${UTPP_TEST_NAME} PROPERTIES OUTPUT_NAME ${UTPP_TEST_NAME})

target_link_libraries(TestUnitTest++ UnitTest++)
target_link_libraries(${UTPP_TEST_NAME} UnitTest++)

# run unit tests as post build step
add_custom_command(TARGET TestUnitTest++
POST_BUILD COMMAND TestUnitTest++
add_custom_command(TARGET ${UTPP_TEST_NAME}
POST_BUILD COMMAND ${UTPP_TEST_NAME}
COMMENT "Running unit tests")

if(NOT ${UTPP_INCLUDE_TESTS_IN_BUILD})
set_target_properties(TestUnitTest++ PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(${UTPP_TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL 1)
endif()

# add install targets
Expand Down
9 changes: 7 additions & 2 deletions UnitTest++/MemoryOutStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ namespace UnitTest {

char const* MemoryOutStream::GetText() const
{
m_text = this->str();
try
{
m_text = this->str();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the Borland implementation of ostringstream::str throw if nothing has been streamed in yet?

If so, can we catch a more specific exception? Maybe std::exception?

Or, can we change the exception mask to prevent the exception entirely? http://en.cppreference.com/w/cpp/io/basic_ios/exceptions

}
catch (...) { m_text = ""; }

return m_text.c_str();
}

void MemoryOutStream::Clear()
{
this->str(std::string());
m_text = this->str();
m_text = std::string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe m_text.clear() instead of another allocation?

}

#ifdef UNITTEST_COMPILER_IS_MSVC6
Expand Down
3 changes: 3 additions & 0 deletions tests/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "UnitTest++/UnitTestPP.h"
#ifdef __BORLANDC__
#include <vcl.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think we needed the Visual Component Library to run a console application?

#endif

int main(int, char const *[])
{
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "ScopedCurrentTest.h"

using namespace std;
#ifdef __BORLANDC__
using namespace UnitTest;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there individual statements that can be changed, rather than adding this?

#endif

namespace {

Expand Down
10 changes: 10 additions & 0 deletions tests/TestChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include <cstring>

#ifdef __BORLANDC__
#include <math.h>
#include <float.h>
#endif

using namespace UnitTest;


Expand Down Expand Up @@ -148,6 +153,11 @@ namespace {

TEST(CheckCloseWithNaNFails)
{
#ifdef __BORLANDC__
// This is to allow the check test to pass when using Nan (invalid float numbers), otherwise, they throw an exception
// and the test fails (CheckCloseWithNaNFails and CheckCloseWithNaNAgainstItselfFails)
_control87(MCW_EM, MCW_EM);
#endif
const unsigned int bitpattern = 0xFFFFFFFF;
float nan;
UNIITEST_NS_QUAL_STD(memcpy)(&nan, &bitpattern, sizeof(bitpattern));
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCurrentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "UnitTest++/CurrentTest.h"
#include "ScopedCurrentTest.h"

#ifdef __BORLANDC__
using namespace UnitTest;
#endif

namespace
{

Expand Down
3 changes: 3 additions & 0 deletions tests/TestExceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <stdexcept>

using namespace std;
#ifdef __BORLANDC__
using namespace UnitTest;
#endif

namespace {

Expand Down
4 changes: 4 additions & 0 deletions tests/TestLongMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "UnitTest++/UnitTestPP.h"

#ifdef __BORLANDC__
using namespace UnitTest;
#endif

// This file is not intended to test every little thing, just a few basics to hopefully ensure
// the macros are working and the short macros are not defined.
UNITTEST_SUITE(LongMacros)
Expand Down
9 changes: 6 additions & 3 deletions tests/TestMemoryOutStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace {
TEST(StreamingLongLongWritesCorrectCharacters)
{
MemoryOutStream stream;
#ifdef UNITTEST_COMPILER_IS_MSVC6
#if defined(UNITTEST_COMPILER_IS_MSVC6) || defined(__BORLANDC__)
stream << (__int64)-12345i64;
#else
stream << (long long)-12345ll;
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace {
TEST(StreamingUnsignedLongLongWritesCorrectCharacters)
{
MemoryOutStream stream;
#ifdef UNITTEST_COMPILER_IS_MSVC6
#if defined(UNITTEST_COMPILER_IS_MSVC6) || defined(__BORLANDC__)
stream << (unsigned __int64)85899ui64;
#else
stream << (unsigned long long)85899ull;
Expand All @@ -219,7 +219,7 @@ namespace {
TEST(StreamingMinUnsignedLongLongWritesCorrectCharacters)
{
MemoryOutStream stream;
#ifdef UNITTEST_COMPILER_IS_MSVC6
#if defined(UNITTEST_COMPILER_IS_MSVC6) || defined(__BORLANDC__)
stream << (unsigned __int64)0ui64;
#else
stream << (unsigned long long)0ull;
Expand Down Expand Up @@ -257,6 +257,9 @@ namespace {
CHECK_EQUAL("53124", stream.GetText());
}

// Not sure why but this test fails with the Borland C++ 5.5 compiler.
// It throws an unhandled exception:
// unexpected NULL pointer in function: basic_string( const charT*,size_type,const Allocator&)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this test still fails, or did one of your other changes fix it?

TEST(ClearEmptiesMemoryOutStreamContents)
{
MemoryOutStream stream;
Expand Down
3 changes: 3 additions & 0 deletions tests/TestRequireMacrosWithExceptionsOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "ScopedCurrentTest.h"

using namespace std;
#ifdef __BORLANDC__
using namespace UnitTest;
#endif

#ifndef UNITTEST_NO_EXCEPTIONS

Expand Down
3 changes: 3 additions & 0 deletions tests/TestTestMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using namespace std;
#else
#define _NOEXCEPT_OP(x)
#endif
#else
#define _NOEXCEPT_OP(x)
#endif
#endif

Expand All @@ -43,6 +45,7 @@ using namespace std;

#endif


namespace {

TestList list1;
Expand Down
4 changes: 4 additions & 0 deletions tests/TestTestSuite.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "UnitTest++/UnitTestPP.h"

#ifdef __BORLANDC__
using namespace UnitTest;
#endif

// We're really testing if it's possible to use the same suite in two files
// to compile and link successfuly (TestTestSuite.cpp has suite with the same name)
// Note: we are outside of the anonymous namespace
Expand Down
4 changes: 4 additions & 0 deletions tests/TestTimeConstraintMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "RecordingReporter.h"
#include "ScopedCurrentTest.h"

#ifdef __BORLANDC__
using namespace UnitTest;
#endif

namespace {

TEST(TimeConstraintMacroQualifiesNamespace)
Expand Down
3 changes: 3 additions & 0 deletions tests/TestUnitTestPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "ScopedCurrentTest.h"

// These are sample tests that show the different features of the framework
#ifdef __BORLANDC__
using namespace UnitTest;
#endif

namespace {

Expand Down