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 namespace testing
37 {
38 
40 
41 template<typename Scope>
42 struct ScopeTraits
43 {
44  inline static const char* name()
45  {
46  return "unknown";
47  }
48 
49  inline static std::shared_ptr<Scope> construct()
50  {
51  return std::make_shared<Scope>();
52  }
53 };
54 
55 template<typename Scope>
56 class TypedScopeFixture : public ::testing::Test
57 {
58 public:
59  TypedScopeFixture()
60  : scope(ScopeTraits<Scope>::construct()),
61  registry_proxy(&registry, [](unity::scopes::Registry*) {})
62  {
63  }
64 
65  void SetUp()
66  {
67  EXPECT_EQ(UNITY_SCOPES_VERSION_MAJOR,
68  scope->start(ScopeTraits<Scope>::name(), registry_proxy));
69  EXPECT_NO_THROW(scope->run());
70  }
71 
72  void TearDown()
73  {
74  EXPECT_NO_THROW(scope->stop());
75  }
76 
77 protected:
78  std::shared_ptr<Scope> scope;
79  unity::scopes::testing::MockRegistry registry;
80  unity::scopes::RegistryProxy registry_proxy;
81 };
82 
84 
85 } // namespace testing
86 
87 } // namespace scopes
88 
89 } // namespace unity
90 #endif
std::shared_ptr< Registry > RegistryProxy
Convenience type definition.
Definition: RegistryProxyFwd.h:34