Skip to content

Commit 637f00a

Browse files
committed
r16 | charles.nicholson | 2010-03-18 15:01:25 -0500 (Thu, 18 Mar 2010) | 1 line
DLL builds for win32, more bin/lib/obj location and configuration name changing in vs2005
1 parent c95e86c commit 637f00a

29 files changed

+544
-171
lines changed

Makefile

Lines changed: 98 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,98 @@
1-
CXX = g++
2-
CXXFLAGS ?= -g -Wall -W -Winline -ansi
3-
LDFLAGS ?=
4-
SED = sed
5-
MV = mv
6-
RM = rm
7-
8-
.SUFFIXES: .o .cpp
9-
10-
lib = libUnitTest++.a
11-
test = TestUnitTest++
12-
13-
src = src/AssertException.cpp \
14-
src/Test.cpp \
15-
src/Checks.cpp \
16-
src/TestRunner.cpp \
17-
src/TestResults.cpp \
18-
src/TestReporter.cpp \
19-
src/TestReporterStdout.cpp \
20-
src/ReportAssert.cpp \
21-
src/TestList.cpp \
22-
src/TimeConstraint.cpp \
23-
src/TestDetails.cpp \
24-
src/MemoryOutStream.cpp \
25-
src/DeferredTestReporter.cpp \
26-
src/DeferredTestResult.cpp \
27-
src/XmlTestReporter.cpp \
28-
src/CurrentTest.cpp
29-
30-
ifeq ($(MSYSTEM), MINGW32)
31-
src += src/Win32/TimeHelpers.cpp
32-
else
33-
src += src/Posix/SignalTranslator.cpp \
34-
src/Posix/TimeHelpers.cpp
35-
endif
36-
37-
test_src = src/tests/Main.cpp \
38-
src/tests/TestAssertHandler.cpp \
39-
src/tests/TestChecks.cpp \
40-
src/tests/TestUnitTestPP.cpp \
41-
src/tests/TestTest.cpp \
42-
src/tests/TestTestResults.cpp \
43-
src/tests/TestTestRunner.cpp \
44-
src/tests/TestCheckMacros.cpp \
45-
src/tests/TestTestList.cpp \
46-
src/tests/TestTestMacros.cpp \
47-
src/tests/TestTimeConstraint.cpp \
48-
src/tests/TestTimeConstraintMacro.cpp \
49-
src/tests/TestMemoryOutStream.cpp \
50-
src/tests/TestDeferredTestReporter.cpp \
51-
src/tests/TestXmlTestReporter.cpp \
52-
src/tests/TestCurrentTest.cpp
53-
54-
objects = $(patsubst %.cpp, %.o, $(src))
55-
test_objects = $(patsubst %.cpp, %.o, $(test_src))
56-
dependencies = $(subst .o,.d,$(objects))
57-
test_dependencies = $(subst .o,.d,$(test_objects))
58-
59-
define make-depend
60-
$(CXX) $(CXXFLAGS) -M $1 | \
61-
$(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp
62-
$(SED) -e 's/#.*//' \
63-
-e 's/^[^:]*: *//' \
64-
-e 's/ *\\$$//' \
65-
-e '/^$$/ d' \
66-
-e 's/$$/ :/' $3.tmp >> $3.tmp
67-
$(MV) $3.tmp $3
68-
endef
69-
70-
71-
all: $(test)
72-
73-
74-
$(lib): $(objects)
75-
@echo Creating $(lib) library...
76-
@ar cr $(lib) $(objects)
77-
78-
$(test): $(lib) $(test_objects)
79-
@echo Linking $(test)...
80-
@$(CXX) $(LDFLAGS) -o $(test) $(test_objects) $(lib)
81-
@echo Running unit tests...
82-
@./$(test)
83-
84-
clean:
85-
-@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null
86-
87-
%.o : %.cpp
88-
@echo $<
89-
@$(call make-depend,$<,$@,$(subst .o,.d,$@))
90-
@$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<)
91-
92-
93-
ifneq "$(MAKECMDGOALS)" "clean"
94-
-include $(dependencies)
95-
-include $(test_dependencies)
96-
endif
1+
CXX = g++
2+
CXXFLAGS ?= -g -Wall -W -Winline -ansi
3+
LDFLAGS ?=
4+
SED = sed
5+
MV = mv
6+
RM = rm
7+
8+
.SUFFIXES: .o .cpp
9+
10+
lib = libunittestpp.a
11+
test = test-unittestpp
12+
13+
src = src/AssertException.cpp \
14+
src/Test.cpp \
15+
src/Checks.cpp \
16+
src/TestRunner.cpp \
17+
src/TestResults.cpp \
18+
src/TestReporter.cpp \
19+
src/TestReporterStdout.cpp \
20+
src/ReportAssert.cpp \
21+
src/TestList.cpp \
22+
src/TimeConstraint.cpp \
23+
src/TestDetails.cpp \
24+
src/MemoryOutStream.cpp \
25+
src/DeferredTestReporter.cpp \
26+
src/DeferredTestResult.cpp \
27+
src/XmlTestReporter.cpp \
28+
src/CurrentTest.cpp
29+
30+
ifeq ($(MSYSTEM), MINGW32)
31+
src += src/Win32/TimeHelpers.cpp
32+
else
33+
src += src/Posix/SignalTranslator.cpp \
34+
src/Posix/TimeHelpers.cpp
35+
endif
36+
37+
test_src = src/tests/Main.cpp \
38+
src/tests/TestAssertHandler.cpp \
39+
src/tests/TestChecks.cpp \
40+
src/tests/TestUnitTestPP.cpp \
41+
src/tests/TestTest.cpp \
42+
src/tests/TestTestResults.cpp \
43+
src/tests/TestTestRunner.cpp \
44+
src/tests/TestCheckMacros.cpp \
45+
src/tests/TestTestList.cpp \
46+
src/tests/TestTestMacros.cpp \
47+
src/tests/TestTimeConstraint.cpp \
48+
src/tests/TestTimeConstraintMacro.cpp \
49+
src/tests/TestMemoryOutStream.cpp \
50+
src/tests/TestDeferredTestReporter.cpp \
51+
src/tests/TestXmlTestReporter.cpp \
52+
src/tests/TestCurrentTest.cpp
53+
54+
objects = $(patsubst %.cpp, %.o, $(src))
55+
test_objects = $(patsubst %.cpp, %.o, $(test_src))
56+
dependencies = $(subst .o,.d,$(objects))
57+
test_dependencies = $(subst .o,.d,$(test_objects))
58+
59+
define make-depend
60+
$(CXX) $(CXXFLAGS) -M $1 | \
61+
$(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp
62+
$(SED) -e 's/#.*//' \
63+
-e 's/^[^:]*: *//' \
64+
-e 's/ *\\$$//' \
65+
-e '/^$$/ d' \
66+
-e 's/$$/ :/' $3.tmp >> $3.tmp
67+
$(MV) $3.tmp $3
68+
endef
69+
70+
71+
all: $(test)
72+
73+
74+
$(lib): $(objects)
75+
@mkdir -p lib/win32_gcc_debug
76+
@echo Creating $(lib) library...
77+
@ar cr lib/win32_gcc_debug/$(lib) $(objects)
78+
79+
$(test): $(lib) $(test_objects)
80+
@mkdir -p bin/win32_gcc_static_debug
81+
@echo Linking $(test)...
82+
@$(CXX) $(LDFLAGS) -o bin/win32_gcc_static_debug/$(test) $(test_objects) lib/win32_gcc_debug/$(lib)
83+
@echo Running unit tests...
84+
@bin/win32_gcc_static_debug/$(test)
85+
86+
clean:
87+
-@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null
88+
89+
%.o : %.cpp
90+
@echo $<
91+
@$(call make-depend,$<,$@,$(subst .o,.d,$@))
92+
@$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<)
93+
94+
95+
ifneq "$(MAKECMDGOALS)" "clean"
96+
-include $(dependencies)
97+
-include $(test_dependencies)
98+
endif

config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#pragma warning(disable:4786)
1313
#pragma warning(disable:4290)
1414
#endif
15+
16+
#ifdef _USRDLL
17+
#define UNITTEST_WIN32_DLL
18+
#endif
1519
#endif
1620

1721
#if defined(unix) || defined(__unix__) || defined(__unix) || defined(linux) || \

src/AssertException.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
#include "../config.h"
55
#ifdef UNITTEST_USE_EXCEPTIONS
66

7+
#include "DllMacros.h"
78
#include <exception>
89

910
namespace UnitTest {
1011

11-
class AssertException : public std::exception
12+
class UNITTEST_LINKAGE AssertException : public std::exception
1213
{
1314
public:
1415
AssertException();

src/Checks.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ void CheckEqual(TestResults& results, Expected const& expected, Actual const& ac
2727
}
2828
}
2929

30-
void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
30+
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char const* actual, TestDetails const& details);
3131

32-
void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
32+
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char* actual, TestDetails const& details);
3333

34-
void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details);
34+
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char* expected, char const* actual, TestDetails const& details);
3535

36-
void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details);
36+
UNITTEST_LINKAGE void CheckEqual(TestResults& results, char const* expected, char* actual, TestDetails const& details);
3737

3838
template< typename Expected, typename Actual, typename Tolerance >
3939
bool AreClose(Expected const& expected, Actual const& actual, Tolerance const& tolerance)

src/CurrentTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
namespace UnitTest {
55

6-
TestResults*& CurrentTest::Results()
6+
UNITTEST_LINKAGE TestResults*& CurrentTest::Results()
77
{
88
static TestResults* testResults = NULL;
99
return testResults;
1010
}
1111

12-
const TestDetails*& CurrentTest::Details()
12+
UNITTEST_LINKAGE const TestDetails*& CurrentTest::Details()
1313
{
1414
static const TestDetails* testDetails = NULL;
1515
return testDetails;

src/CurrentTest.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#ifndef UNITTEST_CURRENTTESTRESULTS_H
22
#define UNITTEST_CURRENTTESTRESULTS_H
33

4+
#include "DllMacros.h"
5+
46
namespace UnitTest {
57

68
class TestResults;
79
class TestDetails;
810

911
namespace CurrentTest
1012
{
11-
TestResults*& Results();
12-
const TestDetails*& Details();
13+
UNITTEST_LINKAGE TestResults*& Results();
14+
UNITTEST_LINKAGE const TestDetails*& Details();
1315
}
1416

1517
}

src/DeferredTestReporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void DeferredTestReporter::ReportFailure(TestDetails const& details, char const*
1515
{
1616
DeferredTestResult& r = m_results.back();
1717
r.failed = true;
18-
r.failures.push_back(DeferredTestResult::Failure(details.lineNumber, failure));
18+
r.failures.push_back(DeferredTestFailure(details.lineNumber, failure));
1919
r.failureFile = details.filename;
2020
}
2121

src/DeferredTestReporter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
#include <vector>
1212

13+
UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestResult);
14+
1315
namespace UnitTest
1416
{
1517

16-
class DeferredTestReporter : public TestReporter
18+
class UNITTEST_LINKAGE DeferredTestReporter : public TestReporter
1719
{
1820
public:
1921
virtual void ReportTestStart(TestDetails const& details);

src/DeferredTestResult.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@
22
#ifdef UNITTEST_USE_DEFERRED_REPORTER
33

44
#include "DeferredTestResult.h"
5+
#include <cstring>
56

67
namespace UnitTest
78
{
89

10+
DeferredTestFailure::DeferredTestFailure()
11+
: lineNumber(-1)
12+
{
13+
failureStr[0] = '\0';
14+
}
15+
16+
DeferredTestFailure::DeferredTestFailure(int lineNumber_, const char* failureStr_)
17+
: lineNumber(lineNumber_)
18+
{
19+
std::strcpy(failureStr, failureStr_);
20+
}
21+
922
DeferredTestResult::DeferredTestResult()
1023
: suiteName("")
1124
, testName("")

src/DeferredTestResult.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@
44
#include "../config.h"
55
#ifdef UNITTEST_USE_DEFERRED_REPORTER
66

7+
#include "DllMacros.h"
78
#include <string>
89
#include <vector>
910

1011
namespace UnitTest
1112
{
1213

13-
struct DeferredTestResult
14+
class UNITTEST_LINKAGE DeferredTestFailure
1415
{
16+
public:
17+
DeferredTestFailure();
18+
DeferredTestFailure(int lineNumber_, const char* failureStr_);
19+
20+
int lineNumber;
21+
char failureStr[1024];
22+
};
23+
24+
}
25+
26+
UNITTEST_STDVECTOR_LINKAGE(UnitTest::DeferredTestFailure);
27+
28+
namespace UnitTest
29+
{
30+
31+
class UNITTEST_LINKAGE DeferredTestResult
32+
{
33+
public:
1534
DeferredTestResult();
1635
DeferredTestResult(char const* suite, char const* test);
1736
~DeferredTestResult();
@@ -20,8 +39,7 @@ struct DeferredTestResult
2039
std::string testName;
2140
std::string failureFile;
2241

23-
typedef std::pair< int, std::string > Failure;
24-
typedef std::vector< Failure > FailureVec;
42+
typedef std::vector< DeferredTestFailure > FailureVec;
2543
FailureVec failures;
2644

2745
float timeElapsed;

src/MemoryOutStream.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
#define UNITTEST_MEMORYOUTSTREAM_H
33

44
#include "../config.h"
5+
#include "DllMacros.h"
6+
57
#ifndef UNITTEST_USE_CUSTOM_STREAMS
68

79
#include <sstream>
810

911
namespace UnitTest
1012
{
1113

12-
class MemoryOutStream : public std::ostringstream
14+
class UNITTEST_LINKAGE MemoryOutStream : public std::ostringstream
1315
{
1416
public:
1517
MemoryOutStream() {}
@@ -32,7 +34,7 @@ class MemoryOutStream : public std::ostringstream
3234
namespace UnitTest
3335
{
3436

35-
class MemoryOutStream
37+
class UNITTEST_LINKAGE MemoryOutStream
3638
{
3739
public:
3840
explicit MemoryOutStream(int const size = 256);

0 commit comments

Comments
 (0)