Covellite++  Version: 2.3.0 Revision: ??? Platform: x64 Build: 23:13 04.01.2025
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
Updater_test.hpp
1
2#pragma once
3
4// ************************************************************************** //
5TEST_F(Updater_test, /*DISABLED_*/Test_Updater_NoFunction)
6{
7 Tested_t oExample{ Data_t{} };
8 ITested_t & IExample = oExample;
9
10 auto itCreator = IExample.GetCreators().find(uT("Updater"));
11 ASSERT_NE(IExample.GetCreators().end(), itCreator);
12
13 auto Render = itCreator->second(Component_t::Make({}));
14 ASSERT_NE(nullptr, Render);
15
16 EXPECT_NO_THROW(Render());
17}
18
19// ************************************************************************** //
20TEST_F(Updater_test, /*DISABLED_*/Test_Updater)
21{
22 using Time_t = ::std::chrono::microseconds;
23
24 class Proxy :
25 public ::alicorn::extension::testing::Proxy<Proxy>
26 {
27 public:
28 MOCK_METHOD1(Update, void(float));
29 };
30
31 Proxy theProxy;
32 Proxy::GetInstance() = &theProxy;
33
34 using SystemClockProxy_t = ::mock::std::chrono::system_clock::Proxy;
35 SystemClockProxy_t SystemClockProxy;
36 SystemClockProxy_t::GetInstance() = &SystemClockProxy;
37
38 const auto BeginTime = 1907232116;
39
40 const ::covellite::api::Updater_t Updater = [&](const float _Time)
41 {
42 theProxy.Update(_Time);
43 };
44
45 const auto pComponent = Component_t::Make(
46 {
47 { uT("function"), Updater },
48 });
49
50 using namespace ::testing;
51
52 InSequence Dummy;
53
54 EXPECT_CALL(SystemClockProxy, Now())
55 .Times(1)
56 .WillOnce(Return(Time_t{ BeginTime }));
57
58 Tested_t oExample{ Data_t{} };
59 ITested_t & IExample = oExample;
60
61 auto itCreator = IExample.GetCreators().find(uT("Updater"));
62 ASSERT_NE(IExample.GetCreators().end(), itCreator);
63
64 auto Render = itCreator->second(pComponent);
65 ASSERT_NE(nullptr, Render);
66
67 EXPECT_CALL(theProxy, Update(0.0f))
68 .Times(1);
69
70 Render();
71
72 EXPECT_CALL(SystemClockProxy, Now())
73 .Times(1)
74 .WillOnce(Return(Time_t{ BeginTime + 1000000 }));
75
76 IExample.PresentFrame();
77
78 EXPECT_CALL(theProxy, Update(1.0f))
79 .Times(1);
80
81 Render();
82}
83
84// ************************************************************************** //
85TEST_F(Updater_test, /*DISABLED_*/Test_Updater_ReplaceFunction)
86{
87 class Proxy :
88 public ::alicorn::extension::testing::Proxy<Proxy>
89 {
90 public:
91 MOCK_METHOD1(Update, void(int));
92 };
93
94 Proxy theProxy;
95 Proxy::GetInstance() = &theProxy;
96
97 const auto pComponent = Component_t::Make({ });
98
99 const ::covellite::api::Updater_t Updater2 = [&](const float)
100 {
101 theProxy.Update(2);
102 };
103
104 const ::covellite::api::Updater_t Updater1 = [&](const float)
105 {
106 (*pComponent)[uT("function")] = Updater2;
107
108 theProxy.Update(1);
109 };
110
111 const ::covellite::api::Updater_t Updater0 = [&](const float)
112 {
113 theProxy.Update(0);
114 };
115
116 Tested_t oExample{ Data_t{} };
117 ITested_t & IExample = oExample;
118
119 auto itCreator = IExample.GetCreators().find(uT("Updater"));
120 ASSERT_NE(IExample.GetCreators().end(), itCreator);
121
122 auto Render = itCreator->second(pComponent);
123 ASSERT_NE(nullptr, Render);
124
125 using namespace ::testing;
126
127 InSequence Dummy;
128
129 EXPECT_CALL(theProxy, Update(_))
130 .Times(0);
131
132 Render();
133
134 (*pComponent)[uT("function")] = Updater0;
135
136 EXPECT_CALL(theProxy, Update(0))
137 .Times(1);
138
139 Render();
140
141 (*pComponent)[uT("function")] = Updater1;
142
143 EXPECT_CALL(theProxy, Update(1))
144 .Times(1);
145
146 Render();
147
148 // Новый updater устанавливается внутри предыдущего.
149
150 EXPECT_CALL(theProxy, Update(2))
151 .Times(1);
152
153 Render();
154}