mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Added Malcolm Noyes' test cases
This commit is contained in:
parent
01db6c4471
commit
46b4909c08
@ -50,7 +50,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
||||
"Number of 'succeeding' tests is fixed" )
|
||||
{
|
||||
runner.runMatching( "./succeeding/*" );
|
||||
CHECK( runner.getSuccessCount() == 218 );
|
||||
CHECK( runner.getSuccessCount() == 224 );
|
||||
CHECK( runner.getFailureCount() == 0 );
|
||||
}
|
||||
|
||||
|
@ -120,3 +120,111 @@ TEST_CASE
|
||||
REQUIRE( i++ == 8 );
|
||||
|
||||
}
|
||||
|
||||
namespace A {
|
||||
struct X
|
||||
{
|
||||
X() : a(4), b(2), c(7) {}
|
||||
X(int v) : a(v), b(2), c(7) {}
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
};
|
||||
}
|
||||
|
||||
namespace B {
|
||||
struct Y
|
||||
{
|
||||
Y() : a(4), b(2), c(7) {}
|
||||
Y(int v) : a(v), b(2), c(7) {}
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
};
|
||||
}
|
||||
bool operator==(const A::X& lhs, const B::Y& rhs)
|
||||
{
|
||||
return (lhs.a == rhs.a);
|
||||
}
|
||||
|
||||
bool operator==(const B::Y& lhs, const A::X& rhs)
|
||||
{
|
||||
return (lhs.a == rhs.a);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TEST_CASE
|
||||
(
|
||||
"./succeeding/koenig",
|
||||
"Operators at different namespace levels not hijacked by Koenig lookup"
|
||||
)
|
||||
{
|
||||
A::X x;
|
||||
B::Y y;
|
||||
REQUIRE( x == y );
|
||||
}
|
||||
|
||||
|
||||
namespace ObjectWithConversions
|
||||
{
|
||||
struct Object
|
||||
{
|
||||
operator unsigned int() {return 0xc0000000;}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TEST_CASE
|
||||
(
|
||||
"./succeeding/koenig",
|
||||
"Operators at different namespace levels not hijacked by Koenig lookup"
|
||||
)
|
||||
{
|
||||
|
||||
Object o;
|
||||
|
||||
bool ok = (0xc0000000 == o); // ok
|
||||
REQUIRE(ok);
|
||||
REQUIRE(0xc0000000 == o ); // doesn't compile (VC or GCC)
|
||||
}
|
||||
}
|
||||
|
||||
namespace ObjectWithNonConstEqualityOperator
|
||||
{
|
||||
struct Test
|
||||
{
|
||||
Test( unsigned int v )
|
||||
: m_value(v)
|
||||
{}
|
||||
|
||||
bool operator==( const Test&rhs )
|
||||
{
|
||||
return (m_value == rhs.m_value);
|
||||
}
|
||||
bool operator==( const Test&rhs ) const
|
||||
{
|
||||
return (m_value != rhs.m_value);
|
||||
}
|
||||
unsigned int m_value;
|
||||
};
|
||||
|
||||
TEST_CASE("./succeeding/non-const==", "Demonstrate that a non-const == is not used")
|
||||
{
|
||||
Test t( 1 );
|
||||
|
||||
bool ok = (t == 1); // ok
|
||||
REQUIRE(ok);
|
||||
REQUIRE( t == 1 ); // doesn't compile (VC or GCC)
|
||||
}
|
||||
}
|
||||
|
||||
namespace EnumBitFieldTests
|
||||
{
|
||||
enum Bits {bit0 = 0x0001, bit1 = 0x0002, bit2 = 0x0004, bit3 = 0x0008, bit1and2 = 0x0006,
|
||||
bit30 = 0x40000000, bit31 = 0x80000000,
|
||||
bit30and31 = 0xc0000000};
|
||||
|
||||
TEST_CASE("./succeeding/enum/bits", "Test enum bit values")
|
||||
{
|
||||
REQUIRE( 0xc0000000 == bit30and31 );
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,20 @@ inline std::string toString
|
||||
return "\"" + value + "\"";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline std::string toString
|
||||
(
|
||||
const std::wstring& value
|
||||
)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "\"";
|
||||
for(size_t i = 0; i < value.size(); ++i )
|
||||
oss << static_cast<char>( value[i] <= 0xff ? value[i] : '?');
|
||||
oss << "\"";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline std::string toString
|
||||
(
|
||||
@ -136,6 +150,34 @@ inline std::string toString
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline std::string toString
|
||||
(
|
||||
unsigned int value
|
||||
)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if( value > 8192 )
|
||||
oss << "0x" << std::hex << value;
|
||||
else
|
||||
oss << value;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline std::string toString
|
||||
(
|
||||
unsigned long value
|
||||
)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
if( value > 8192 )
|
||||
oss << "0x" << std::hex << value;
|
||||
else
|
||||
oss << value;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline std::string toString
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user