• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Created by Phil on 09/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 
11 namespace{ namespace ClassTests {
12 
13 #ifndef CLASS_TEST_HELPERS_INCLUDED // Don't compile this more than once per TU
14 #define CLASS_TEST_HELPERS_INCLUDED
15 
16 class TestClass
17 {
18     std::string s;
19 
20 public:
TestClass()21     TestClass()
22     : s( "hello" )
23     {}
24 
succeedingCase()25     void succeedingCase()
26     {
27         REQUIRE( s == "hello" );
28     }
failingCase()29     void failingCase()
30     {
31         REQUIRE( s == "world" );
32     }
33 };
34 
35 struct Fixture
36 {
Fixture__anon6fb5b94f0111::ClassTests::Fixture37     Fixture() : m_a( 1 ) {}
38 
39     int m_a;
40 };
41 
42 template< typename T >
43 struct Template_Fixture {
Template_Fixture__anon6fb5b94f0111::ClassTests::Template_Fixture44     Template_Fixture(): m_a(1) {}
45 
46     T m_a;
47 };
48 
49 template<typename T>
50 struct Template_Fixture_2 {
Template_Fixture_2__anon6fb5b94f0111::ClassTests::Template_Fixture_251     Template_Fixture_2() {}
52 
53     T m_a;
54 };
55 
56 template< typename T>
57 struct Template_Foo {
size__anon6fb5b94f0111::ClassTests::Template_Foo58     size_t size() { return 0; }
59 };
60 
61 #endif
62 
63 
64 
65 METHOD_AS_TEST_CASE( TestClass::succeedingCase, "A METHOD_AS_TEST_CASE based test run that succeeds", "[class]" )
66 METHOD_AS_TEST_CASE( TestClass::failingCase, "A METHOD_AS_TEST_CASE based test run that fails", "[.][class][failing]" )
67 
68 TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that succeeds", "[class]" )
69 {
70     REQUIRE( m_a == 1 );
71 }
72 
73 TEMPLATE_TEST_CASE_METHOD(Template_Fixture, "A TEMPLATE_TEST_CASE_METHOD based test run that succeeds", "[class][template]", int, float, double) {
74     REQUIRE( Template_Fixture<TestType>::m_a == 1 );
75 }
76 
77 TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Fixture_2, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test run that succeeds","[class][template][product]",(std::vector,Template_Foo),(int,float))
78 {
79     REQUIRE( Template_Fixture_2<TestType>::m_a.size() == 0 );
80 }
81 
82 // We should be able to write our tests within a different namespace
83 namespace Inner
84 {
85     TEST_CASE_METHOD( Fixture, "A TEST_CASE_METHOD based test run that fails", "[.][class][failing]" )
86     {
87         REQUIRE( m_a == 2 );
88     }
89 
90     TEMPLATE_TEST_CASE_METHOD(Template_Fixture,"A TEMPLATE_TEST_CASE_METHOD based test run that fails", "[.][class][template][failing]", int, float, double)
91     {
92         REQUIRE( Template_Fixture<TestType>::m_a == 2 );
93     }
94 
95     TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Fixture_2, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test run that fails","[.][class][template][product][failing]",(std::vector,Template_Foo),(int,float))
96     {
97         REQUIRE( Template_Fixture_2<TestType>::m_a.size() == 1 );
98     }
99 }
100 
101 
102 
103 }} // namespace ClassTests
104