1 /*
2  *  Created by Phil on 7/1/2011
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 #ifndef TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
9 #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
10 
11 #include "catch_test_registry.h"
12 #include "catch_test_spec.h"
13 #include "catch_interfaces_config.h"
14 
15 #include <vector>
16 #include <set>
17 #include <algorithm>
18 #include <ios>
19 
20 namespace Catch {
21 
22     class TestCase;
23     struct IConfig;
24 
25     std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
26     bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
27 
28     void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );
29 
30     std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
31     std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
32 
33     class TestRegistry : public ITestCaseRegistry {
34     public:
35         virtual ~TestRegistry() = default;
36 
37         virtual void registerTest( TestCase const& testCase );
38 
39         std::vector<TestCase> const& getAllTests() const override;
40         std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const override;
41 
42     private:
43         std::vector<TestCase> m_functions;
44         mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
45         mutable std::vector<TestCase> m_sortedFunctions;
46         std::size_t m_unnamedCount = 0;
47         std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
48     };
49 
50     ///////////////////////////////////////////////////////////////////////////
51 
52     class TestInvokerAsFunction : public ITestInvoker {
53         void(*m_testAsFunction)();
54     public:
55         TestInvokerAsFunction( void(*testAsFunction)() ) noexcept;
56 
57         void invoke() const override;
58     };
59 
60 
61     std::string extractClassName( StringRef const& classOrQualifiedMethodName );
62 
63     ///////////////////////////////////////////////////////////////////////////
64 
65 
66 } // end namespace Catch
67 
68 
69 #endif // TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
70