2013-07-23 09:15:34 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 20/07/2013.
|
|
|
|
* Copyright 2013 Two Blue Cubes Ltd
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wpadded"
|
|
|
|
#endif
|
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
#include "internal/catch_test_case_tracker.hpp"
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
#include "catch.hpp"
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
TEST_CASE( "section tracking", "" ) {
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
using namespace Catch;
|
2013-07-23 19:48:36 +02:00
|
|
|
TestCaseTracker testCaseTracker( "test case" );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
const std::string section1Name = "section 1";
|
|
|
|
const std::string section2Name = "section 2";
|
|
|
|
|
2013-07-23 19:48:36 +02:00
|
|
|
CHECK_FALSE( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
SECTION( "test case with no sections", "" ) {
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
|
|
|
CHECK_FALSE( testCaseTracker.isCompleted() );
|
|
|
|
}
|
2013-07-23 19:48:36 +02:00
|
|
|
CHECK( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
SECTION( "test case with one section", "" ) {
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Enter section? - yes
|
|
|
|
CHECK( testCaseTracker.enterSection( section1Name ) );
|
2013-07-25 09:07:55 +02:00
|
|
|
CHECK_FALSE( testCaseTracker.isCompleted() );
|
2014-04-21 20:02:38 +02:00
|
|
|
testCaseTracker.leaveSection();
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Leave test case - now complete
|
2013-07-25 09:07:55 +02:00
|
|
|
}
|
2014-04-21 20:02:38 +02:00
|
|
|
CHECK( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
// Enter test case again
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Enter section? - no - now complete
|
|
|
|
CHECK_FALSE( testCaseTracker.enterSection( section1Name ) );
|
2013-07-25 09:07:55 +02:00
|
|
|
}
|
2013-07-23 09:15:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
SECTION( "test case with two consecutive sections", "" ) {
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
// Enter test case
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Enter section 1? - yes
|
|
|
|
CHECK( testCaseTracker.enterSection( section1Name ) );
|
|
|
|
testCaseTracker.leaveSection();
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Enter section 2? - no - we just exected section 1
|
2013-07-25 09:07:55 +02:00
|
|
|
CHECK_FALSE( testCaseTracker.enterSection( section2Name ) );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Leave test case - incomplete (still need to visit section 2)
|
|
|
|
}
|
2013-07-23 19:48:36 +02:00
|
|
|
CHECK_FALSE( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
// Enter test case again
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Enter section 1? - no, already done now
|
|
|
|
CHECK_FALSE( testCaseTracker.enterSection( section1Name ) );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Enter section 2? - yes
|
2013-07-25 09:07:55 +02:00
|
|
|
CHECK( testCaseTracker.enterSection( section2Name ) );
|
|
|
|
testCaseTracker.leaveSection();
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Leave test case - now complete
|
|
|
|
}
|
2013-07-23 19:48:36 +02:00
|
|
|
CHECK( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
SECTION( "test case with one section within another", "" ) {
|
2013-07-23 09:15:34 +02:00
|
|
|
|
|
|
|
// Enter test case again
|
2013-07-25 09:07:55 +02:00
|
|
|
{
|
|
|
|
TestCaseTracker::Guard guard( testCaseTracker );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Enter section 1? - yes
|
|
|
|
CHECK( testCaseTracker.enterSection( section1Name ) );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
// Enter section 2? - yes
|
|
|
|
CHECK( testCaseTracker.enterSection( section2Name ) );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2014-04-21 20:02:38 +02:00
|
|
|
CHECK_FALSE( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
testCaseTracker.leaveSection(); // section 2
|
|
|
|
testCaseTracker.leaveSection(); // section 1
|
2013-07-23 09:15:34 +02:00
|
|
|
|
2013-07-25 09:07:55 +02:00
|
|
|
// Leave test case - now complete
|
|
|
|
}
|
2013-07-23 19:48:36 +02:00
|
|
|
CHECK( testCaseTracker.isCompleted() );
|
2013-07-23 09:15:34 +02:00
|
|
|
}
|
|
|
|
}
|