Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TypedScopeFixture.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the Lesser GNU General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef UNITY_SCOPES_TESTING_TYPED_SCOPE_FIXTURE_H
20 #define UNITY_SCOPES_TESTING_TYPED_SCOPE_FIXTURE_H
21 
22 #include <unity/scopes/Version.h>
23 
24 #include <unity/scopes/testing/MockRegistry.h>
25 
26 #include <gtest/gtest.h>
27 
28 #include <memory>
29 
30 namespace unity
31 {
32 
33 namespace scopes
34 {
35 
36 class ScopeBase;
37 
38 namespace testing
39 {
40 
42 
43 template<typename Scope>
44 struct ScopeTraits
45 {
46  inline static const char* name()
47  {
48  return "unknown";
49  }
50 
51  inline static std::shared_ptr<Scope> construct()
52  {
53  return std::make_shared<Scope>();
54  }
55 };
56 
57 struct TypedScopeFixtureHelper
58 {
59 private:
60  static void set_registry(std::shared_ptr<ScopeBase> const& scope, RegistryProxy const& r);
61 
62  template<typename Scope>
63  friend class TypedScopeFixture;
64 };
65 
66 template<typename Scope>
67 class TypedScopeFixture : public ::testing::Test
68 {
69 public:
70  TypedScopeFixture()
71  : registry_proxy(&registry, [](unity::scopes::Registry*) {})
72  , scope(ScopeTraits<Scope>::construct())
73  {
74  TypedScopeFixtureHelper::set_registry(scope, registry_proxy);
75  }
76 
77  void SetUp()
78  {
79  EXPECT_NO_THROW(scope->start(ScopeTraits<Scope>::name()));
80  EXPECT_NO_THROW(scope->run());
81  }
82 
83  void TearDown()
84  {
85  EXPECT_NO_THROW(scope->stop());
86  }
87 
88 protected:
89  unity::scopes::testing::MockRegistry registry;
90  unity::scopes::RegistryProxy registry_proxy;
91  std::shared_ptr<Scope> scope;
92 };
93 
95 
96 } // namespace testing
97 
98 } // namespace scopes
99 
100 } // namespace unity
101 #endif
std::shared_ptr< Registry > RegistryProxy
Convenience type definition.
Definition: RegistryProxyFwd.h:34