Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
Application.mock.hpp
1
2#pragma once
3#include <stack>
4#include <functional>
5#include <Covellite/Events/Events.hpp>
6#include <Covellite/App/IApplication.hpp>
7#include <Covellite/App/IWindow.hpp>
8
9/*
10An example of use:
11
12using ExampleProxy_t = ::mock::covellite::Application::Proxy;
13ExampleProxy_t ExampleProxy;
14ExampleProxy_t::GetInstance() = &ExampleProxy;
15
16const ::mock::Id_t ExampleId = 1607301544;
17
18using namespace ::testing;
19
20InSequence Dummy;
21
22EXPECT_CALL(ExampleProxy, Constructor(Value1))
23 .Times(1)
24 .WillOnce(Return(ExampleId));
25
26::mock::covellite::Application Example(Value1);
27
28EXPECT_CALL(ExampleProxy, Function(ExampleId, Value2))
29 .Times(1)
30 .WillOnce(Return(Value3));
31
32const auto Result = Example.Function(Value2);
33EXPECT_EQ(Value3, Result);
34*/
35
36namespace mock
37{
38
39namespace covellite
40{
41
42namespace app
43{
44
45class Application :
47{
48 using Events_t = ::covellite::events::Events;
49 using Run_t = ::std::function<void(void)>;
50 using Windows_t = ::std::stack<::std::shared_ptr<::covellite::app::IWindow>>;
51
52public:
53 class Proxy :
54 public ::alicorn::extension::testing::Proxy<Proxy>
55 {
56 public:
57 MOCK_METHOD0(ContinuousConstructor, Id_t(void));
58 MOCK_METHOD0(EventBasedConstructor, Id_t(void));
59 MOCK_METHOD2(Main, void(::std::string, void *));
60 MOCK_METHOD1(Run, void(Id_t));
61 MOCK_METHOD2(MakeWindow, void(Id_t, ::std::string));
62 };
63
64public:
65 const Id_t m_Id = 0;
66 Application & operator= (const Application &) = delete;
67 bool operator== (const Application & _Value) const { return (m_Id == _Value.m_Id); }
68
69public:
70 class Continuous {};
71 class EventBased {};
72
73public:
74 template<class TApplication>
75 static void Main(void * _pParams) noexcept
76 {
77 Proxy::GetInstance()->Main(typeid(TApplication).name(), _pParams);
78 }
79
80 const Run_t Run;
81
82public:
83 operator Events_t (void) const final { return m_Events; }
84
85protected:
86 template<class TWindow, class ... TArgs>
87 TWindow & MakeWindow(TArgs && ... _Args)
88 {
89 Proxy::GetInstance()->MakeWindow(m_Id, typeid(TWindow).name());
90
91 auto pWindow = ::std::make_shared<TWindow>(_Args ...);
92 m_Windows.push(pWindow);
93 return *pWindow;
94 }
95
96protected:
97 Events_t m_Events;
98 Windows_t m_Windows;
99
100public:
101 explicit Application(Continuous) :
102 m_Id(Proxy::GetInstance()->ContinuousConstructor()),
103 Run([=](void) { Proxy::GetInstance()->Run(m_Id); })
104 {
105
106 }
107
108 explicit Application(EventBased) :
109 m_Id(Proxy::GetInstance()->EventBasedConstructor()),
110 Run([=](void) { Proxy::GetInstance()->Run(m_Id); })
111 {
112
113 }
114
115 virtual ~Application(void) = default;
116};
117
118} // namespace app
119
120} // namespace covellite
121
122} // namespace mock
Класс входит в проект Covellite.App Интерфейсный класс приложения.
Definition IApplication.hpp:28
Класс входит в проект Covellite.Events Класс для работы с событиями фреймворка.
Definition Events.hpp:36