mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
VS integration part 1 - allow catch_message.hpp to be included by more than 1 source file
This commit is contained in:
50
projects/SelfTest/MessageInstantiationTests1.cpp
Normal file
50
projects/SelfTest/MessageInstantiationTests1.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Created by Phil on 09/11/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#undef INTERNAL_CATCH_INLINE
|
||||
#define INTERNAL_CATCH_INLINE inline
|
||||
#include "internal/catch_message.hpp"
|
||||
|
||||
namespace Counter {
|
||||
int g_haveCountedMessages = 0;
|
||||
}
|
||||
|
||||
// This test works with the equivalent in MessageInstantiationTests2.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting1","")
|
||||
{
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace LongCounter {
|
||||
int g_haveCountedMessagesLong = 0;
|
||||
}
|
||||
|
||||
TEST_CASE("long message counting1","")
|
||||
{
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
}
|
||||
}
|
49
projects/SelfTest/MessageInstantiationTests2.cpp
Normal file
49
projects/SelfTest/MessageInstantiationTests2.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Created by Phil on 09/11/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#define INTERNAL_CATCH_INLINE inline
|
||||
#include "internal/catch_message.hpp"
|
||||
|
||||
namespace Counter {
|
||||
extern int g_haveCountedMessages;
|
||||
}
|
||||
|
||||
// This test works with the equivalent in MessageInstantiationTests1.cpp
|
||||
// The first test to reach this point will increment the MessageInfo counter. Subsequent tests
|
||||
// just check the value. The purpose of this test is to verify that the compiler's
|
||||
// greedy instantiation (or whatever process it uses) eliminate all other
|
||||
// references to the globalCount
|
||||
|
||||
TEST_CASE("message counting2","")
|
||||
{
|
||||
if( Counter::g_haveCountedMessages > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<unsigned int>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<unsigned int>::globalCount;
|
||||
Counter::g_haveCountedMessages = 1;
|
||||
}
|
||||
}
|
||||
|
||||
namespace LongCounter {
|
||||
extern int g_haveCountedMessagesLong;
|
||||
}
|
||||
|
||||
TEST_CASE("long message counting2","")
|
||||
{
|
||||
if( LongCounter::g_haveCountedMessagesLong > 0 ) {
|
||||
REQUIRE( Catch::MessageInfoCounter<long>::globalCount > 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
++Catch::MessageInfoCounter<long>::globalCount;
|
||||
LongCounter::g_haveCountedMessagesLong = 1;
|
||||
}
|
||||
}
|
@@ -4,6 +4,8 @@ SOURCES = ApproxTests.cpp \
|
||||
ExceptionTests.cpp \
|
||||
GeneratorTests.cpp \
|
||||
MessageTests.cpp \
|
||||
MessageInstantiationTests1.cpp \
|
||||
MessageInstantiationTests2.cpp \
|
||||
MiscTests.cpp \
|
||||
TestMain.cpp \
|
||||
TrickyTests.cpp \
|
||||
@@ -18,4 +20,4 @@ CatchSelfTest: $(OBJECTS)
|
||||
$(CXX) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS)
|
||||
rm -f CatchSelfTest CatchSelfTest.exe $(OBJECTS)
|
||||
|
Reference in New Issue
Block a user