1 /*
2  *  Created by Phil on 29/11/2010.
3  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 
9 #include "catch.hpp"
10 
itDoesThis()11 inline bool itDoesThis(){ return true; }
itDoesThat()12 inline bool itDoesThat(){ return true; }
13 
14 SCENARIO( "Do that thing with the thing", "[Tags]" ) {
15     GIVEN( "This stuff exists" ) {
16         // make stuff exist
17         WHEN( "I do this" ) {
18             // do this
19             THEN( "it should do this")
20             {
21                 REQUIRE( itDoesThis() );
22                 AND_THEN( "do that")
23                     REQUIRE( itDoesThat() );
24             }
25         }
26     }
27 }
28 
29 SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capacity]" ) {
30     GIVEN( "an empty vector" ) {
31         std::vector<int> v;
32         REQUIRE( v.size() == 0 );
33 
34         WHEN( "it is made larger" ) {
35             v.resize( 10 );
36             THEN( "the size and capacity go up" ) {
37                 REQUIRE( v.size() == 10 );
38                 REQUIRE( v.capacity() >= 10 );
39 
40                 AND_WHEN( "it is made smaller again" ) {
41                     v.resize( 5 );
42                     THEN( "the size goes down but the capacity stays the same" ) {
43                         REQUIRE( v.size() == 5 );
44                         REQUIRE( v.capacity() >= 10 );
45                     }
46                 }
47             }
48         }
49 
50         WHEN( "we reserve more space" ) {
51             v.reserve( 10 );
52             THEN( "The capacity is increased but the size remains the same" ) {
53                 REQUIRE( v.capacity() >= 10 );
54                 REQUIRE( v.size() == 0 );
55             }
56         }
57     }
58 }
59 
60 SCENARIO(   "This is a really long scenario name to see how the list command deals with wrapping",
61             "[very long tags][lots][long][tags][verbose]"
62             "[one very long tag name that should cause line wrapping writing out using the list command]"
63             "[anotherReallyLongTagNameButThisOneHasNoObviousWrapPointsSoShouldSplitWithinAWordUsingADashCharacter]" ) {
64     GIVEN( "A section name that is so long that it cannot fit in a single console width" )
65         WHEN( "The test headers are printed as part of the normal running of the scenario" )
66             THEN( "The, deliberately very long and overly verbose (you see what I did there?) section names must wrap, along with an indent" )
67                 SUCCEED("boo!");
68 }
69 
70 namespace {
71 
72 // a trivial fixture example to support SCENARIO_METHOD tests
73 struct Fixture
74 {
Fixture__anonf860d2840111::Fixture75     Fixture()
76     : d_counter(0)
77     {
78     }
79 
counter__anonf860d2840111::Fixture80     int counter()
81     {
82         return d_counter++;
83     }
84 
85     int d_counter;
86 };
87 
88 }
89 
90 SCENARIO_METHOD(Fixture,
91     "BDD tests requiring Fixtures to provide commonly-accessed data or methods",
92     "[bdd][fixtures]") {
93     const int before(counter());
94     GIVEN("No operations precede me") {
95         REQUIRE(before == 0);
96         WHEN("We get the count") {
97             const int after(counter());
98             THEN("Subsequently values are higher") {
99                 REQUIRE(after > before);
100             }
101         }
102     }
103 }
104