3#include <Platform/Windows.mock.hpp>
5inline static ::std::vector<float> ARGBtoFloat4(
const uint32_t _HexColor)
9 ((_HexColor & 0x00FF0000) >> 16) / 255.0f,
10 ((_HexColor & 0x0000FF00) >> 8) / 255.0f,
11 ((_HexColor & 0x000000FF) >> 0) / 255.0f,
12 ((_HexColor & 0xFF000000) >> 24) / 255.0f,
20TEST_F(OpenGLCommon_test, Test_NoEqMatrix)
25 EXPECT_FALSE(::glm::mat4{ 1.0f } == ::glm::mat4{ 2.0f });
26 EXPECT_TRUE(::glm::mat4{ 1.0f } != ::glm::mat4{ 2.0f });
30TEST_F(OpenGLCommon_test, Test_State_Blend)
32 using GLProxy_t = ::mock::GLProxy;
34 GLProxy_t::GetInstance() = &GLProxy;
36 const Tested_t Example{ Data_t{} };
37 const ITested_t & IExample = Example;
39 auto itCreator = IExample.GetCreators().find(uT(
"State"));
40 ASSERT_NE(IExample.GetCreators().end(), itCreator);
42 auto Render = itCreator->second(Component_t::Make(
44 { uT(
"kind"), uT(
"Blend") }
46 ASSERT_NE(
nullptr, Render);
48 using namespace ::testing;
52 EXPECT_CALL(GLProxy, Enable(GL_BLEND))
55 EXPECT_CALL(GLProxy, BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA))
62TEST_F(OpenGLCommon_test, Test_State_Sampler)
64 using GLProxy_t = ::mock::GLProxy;
66 GLProxy_t::GetInstance() = &GLProxy;
68 const Tested_t Example{ Data_t{} };
69 const ITested_t & IExample = Example;
71 auto itStateCreator = IExample.GetCreators().find(uT(
"State"));
72 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
74 auto itTextureCreator = IExample.GetCreators().find(uT(
"Texture"));
75 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
77 auto SamplerRender = itStateCreator->second(Component_t::Make(
79 { uT(
"kind"), uT(
"Sampler") }
81 ASSERT_NE(
nullptr, SamplerRender);
83 auto TextureRender = itTextureCreator->second(Component_t::Make({ }));
84 ASSERT_NE(
nullptr, TextureRender);
86 using namespace ::testing;
88 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
95 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, _))
98 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
102 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
106 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT))
109 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT))
116TEST_F(OpenGLCommon_test, Test_State_Scissor_Enable)
118 using GLProxy_t = ::mock::GLProxy;
120 GLProxy_t::GetInstance() = &GLProxy;
122 const Tested_t Example{ Data_t{} };
123 const ITested_t & IExample = Example;
125 const auto pScissorData = Component_t::Make(
127 { uT(
"kind"), uT(
"Rect") },
130 auto itCreatorState = IExample.GetCreators().find(uT(
"State"));
131 ASSERT_NE(IExample.GetCreators().end(), itCreatorState);
133 const auto pScissor = Component_t::Make(
135 { uT(
"kind"), uT(
"Scissor") },
136 { uT(
"enabled"),
true },
137 { uT(
"service"), Object_t{ pScissorData } },
140 auto Render = itCreatorState->second(pScissor);
141 ASSERT_NE(
nullptr, Render);
143 auto TestCallRender =
144 [&](
int _X,
int _Y,
int _Width,
int _Height,
int _WindowHeight)
146 const int Yo = _WindowHeight - (_Y + _Height);
148 (*pScissorData)[uT(
"left")] = _X;
149 (*pScissorData)[uT(
"top")] = _Y;
150 (*pScissorData)[uT(
"right")] = _X + _Width;
151 (*pScissorData)[uT(
"bottom")] = _Y + _Height;
153 using namespace ::testing;
157 EXPECT_CALL(GLProxy, Enable(GL_SCISSOR_TEST))
160 const int Viewport[4] = { 0, 0, 0, _WindowHeight };
162 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
164 .WillOnce(Return(Viewport));
166 EXPECT_CALL(GLProxy, Scissor(_X, Yo, _Width, _Height))
174 TestCallRender(1509, 1510, 1511, 1512, 1513);
175 TestCallRender(1514, 1515, 1516, 1517, 1518);
179TEST_F(OpenGLCommon_test, Test_State_Scissor_Disable)
181 using GLProxy_t = ::mock::GLProxy;
183 GLProxy_t::GetInstance() = &GLProxy;
185 const Tested_t Example{ Data_t{} };
186 const ITested_t & IExample = Example;
188 auto itCreator = IExample.GetCreators().find(uT(
"State"));
189 ASSERT_NE(IExample.GetCreators().end(), itCreator);
191 const auto pComponent = Component_t::Make(
193 { uT(
"kind"), uT(
"Scissor") },
194 { uT(
"enabled"),
false },
197 auto Render = itCreator->second(pComponent);
198 ASSERT_NE(
nullptr, Render);
200 using namespace ::testing;
202 EXPECT_CALL(GLProxy, Disable(GL_SCISSOR_TEST))
209TEST_F(OpenGLCommon_test, Test_State_Depth_Disabled)
211 using GLProxy_t = ::mock::GLProxy;
213 GLProxy_t::GetInstance() = &GLProxy;
215 const Tested_t Example{ Data_t{} };
216 const ITested_t & IExample = Example;
218 auto itCreator = IExample.GetCreators().find(uT(
"State"));
219 ASSERT_NE(IExample.GetCreators().end(), itCreator);
221 using namespace ::testing;
223 const auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pState)
225 auto Render = itCreator->second(_pState);
226 ASSERT_NE(
nullptr, Render);
228 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
231 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
234 EXPECT_CALL(GLProxy, DepthFunc(_))
237 EXPECT_CALL(GLProxy, ClearDepth(_))
240 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
246 TestCallRender(Component_t::Make(
248 { uT(
"kind"), uT(
"Depth") },
251 TestCallRender(Component_t::Make(
253 { uT(
"kind"), uT(
"Depth") },
254 { uT(
"enabled"),
false },
259TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_NoClear_Overwrite)
261 using GLProxy_t = ::mock::GLProxy;
263 GLProxy_t::GetInstance() = &GLProxy;
265 const Tested_t Example{ Data_t{} };
266 const ITested_t & IExample = Example;
268 auto itCreator = IExample.GetCreators().find(uT(
"State"));
269 ASSERT_NE(IExample.GetCreators().end(), itCreator);
271 using namespace ::testing;
273 const auto Render = itCreator->second(Component_t::Make(
275 { uT(
"kind"), uT(
"Depth") },
276 { uT(
"enabled"),
true },
277 { uT(
"clear"),
false },
279 ASSERT_NE(
nullptr, Render);
281 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
284 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
287 EXPECT_CALL(GLProxy, DepthMask(GL_TRUE))
290 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
293 EXPECT_CALL(GLProxy, ClearDepth(_))
296 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
303TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_Clear_Overwrite)
305 using GLProxy_t = ::mock::GLProxy;
307 GLProxy_t::GetInstance() = &GLProxy;
309 const Tested_t Example{ Data_t{} };
310 const ITested_t & IExample = Example;
312 auto itCreator = IExample.GetCreators().find(uT(
"State"));
313 ASSERT_NE(IExample.GetCreators().end(), itCreator);
315 using namespace ::testing;
317 const auto Render = itCreator->second(Component_t::Make(
319 { uT(
"kind"), uT(
"Depth") },
320 { uT(
"enabled"),
true },
321 { uT(
"clear"),
true },
323 ASSERT_NE(
nullptr, Render);
325 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
328 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
331 EXPECT_CALL(GLProxy, DepthMask(GL_TRUE))
334 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
337 EXPECT_CALL(GLProxy, ClearDepth(0.0f))
340 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
347TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_NoClear_NoOverwrite)
349 using GLProxy_t = ::mock::GLProxy;
351 GLProxy_t::GetInstance() = &GLProxy;
353 const Tested_t Example{ Data_t{} };
354 const ITested_t & IExample = Example;
356 auto itCreator = IExample.GetCreators().find(uT(
"State"));
357 ASSERT_NE(IExample.GetCreators().end(), itCreator);
359 using namespace ::testing;
361 const auto Render = itCreator->second(Component_t::Make(
363 { uT(
"kind"), uT(
"Depth") },
364 { uT(
"enabled"),
true },
365 { uT(
"clear"),
false },
366 { uT(
"overwrite"),
false },
368 ASSERT_NE(
nullptr, Render);
370 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
373 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
376 EXPECT_CALL(GLProxy, DepthMask(GL_FALSE))
379 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
382 EXPECT_CALL(GLProxy, ClearDepth(_))
385 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
392TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_Clear_NoOverwrite)
394 using GLProxy_t = ::mock::GLProxy;
396 GLProxy_t::GetInstance() = &GLProxy;
398 const Tested_t Example{ Data_t{} };
399 const ITested_t & IExample = Example;
401 auto itCreator = IExample.GetCreators().find(uT(
"State"));
402 ASSERT_NE(IExample.GetCreators().end(), itCreator);
404 using namespace ::testing;
406 const auto Render = itCreator->second(Component_t::Make(
408 { uT(
"kind"), uT(
"Depth") },
409 { uT(
"enabled"),
true },
410 { uT(
"clear"),
true },
411 { uT(
"overwrite"),
false },
413 ASSERT_NE(
nullptr, Render);
415 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
418 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
421 EXPECT_CALL(GLProxy, DepthMask(GL_FALSE))
424 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
427 EXPECT_CALL(GLProxy, ClearDepth(0.0f))
430 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
437TEST_F(OpenGLCommon_test, Test_State_Clear)
439 using Color_t = ::std::vector<float>;
441 using GLProxy_t = ::mock::GLProxy;
443 GLProxy_t::GetInstance() = &GLProxy;
445 Tested_t Example{ Data_t{ } };
446 ITested_t & IExample = Example;
448 auto itCreator = IExample.GetCreators().find(uT(
"State"));
449 ASSERT_NE(IExample.GetCreators().end(), itCreator);
451 const auto TestCallRender = [&](
452 const Component_t::ComponentPtr_t & _pState,
453 const Color_t & _ExpectedColor)
455 const auto Render = itCreator->second(_pState);
456 ASSERT_NE(
nullptr, Render);
458 using namespace ::testing;
462 ASSERT_EQ(4, _ExpectedColor.size());
464 EXPECT_CALL(GLProxy, ClearColor(_ExpectedColor[0], _ExpectedColor[1],
465 _ExpectedColor[2], _ExpectedColor[3]))
468 EXPECT_CALL(GLProxy, Clear(GL_COLOR_BUFFER_BIT))
475 const ::std::vector<FLOAT> DefaultColor =
483 TestCallRender(Component_t::Make(
485 { uT(
"kind"), uT(
"Clear") },
490 const ::std::vector<FLOAT> Color =
492 0.86274509803921568627450980392157f,
493 0.72941176470588235294117647058824f,
494 0.5960784313725490196078431372549f,
495 0.9960784313725490196078431372549f,
498 TestCallRender(Component_t::Make(
500 { uT(
"kind"), uT(
"Clear") },
501 { uT(
"color"), 0xFEDCBA98 },
507TEST_F(OpenGLCommon_test, Test_Texture_glTexImage2D_Fail)
509 using GLProxy_t = ::mock::GLProxy;
511 GLProxy_t::GetInstance() = &GLProxy;
513 const ::mock::GLuint TextureId = 1612182301;
515 const Tested_t Example{ Data_t{} };
516 const ITested_t & IExample = Example;
518 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
519 ASSERT_NE(IExample.GetCreators().end(), itCreator);
521 using namespace ::testing;
525 EXPECT_CALL(GLProxy, GenTextures(1))
527 .WillOnce(Return(TextureId));
529 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
532 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
535 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
538 EXPECT_CALL(GLProxy, GetError())
540 .WillOnce(Return(1808261916));
542 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
546TEST_F(OpenGLCommon_test, Test_Texture_UnknownDestination)
548 using GLProxy_t = ::mock::GLProxy;
550 GLProxy_t::GetInstance() = &GLProxy;
552 const Tested_t Example{ Data_t{} };
553 const ITested_t & IExample = Example;
555 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
556 ASSERT_NE(IExample.GetCreators().end(), itCreator);
558 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture)
560 const ::mock::GLuint TextureId = 1812181809;
562 using namespace ::testing;
566 EXPECT_CALL(GLProxy, GenTextures(_))
569 EXPECT_CALL(GLProxy, BindTexture(_, _))
572 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
575 EXPECT_CALL(GLProxy, GetError())
578 EXPECT_THROW(itCreator->second(_pTexture), ::std::exception);
582 const auto pTexture = Component_t::Make(
584 { uT(
"destination"), uT(
"1907251102") },
591 const auto pData = Component_t::Make(
593 { uT(
"kind"), uT(
"Texture") },
594 { uT(
"destination"), uT(
"1907251103") },
597 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
602TEST_F(OpenGLCommon_test, Test_Buffer_UnknownType)
604 const ::std::vector<float> Source = { 0.0f };
606 const Tested_t Example{ Data_t{} };
607 const ITested_t & IExample = Example;
609 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
610 ASSERT_NE(IExample.GetCreators().end(), itCreator);
615 const auto pBuffer = Component_t::Make(
617 { uT(
"id"), uT(
"id.1905081956") },
618 { uT(
"type"), uT(
"type.1905081956") },
619 { uT(
"kind"), uT(
"kind.1905081956") },
620 { uT(
"content"), Source },
623 EXPECT_STDEXCEPTION(itCreator->second(pBuffer),
624 ".+\\.cpp\\([0-9]+\\): Unexpected buffer format \\["
625 "id: id.1905081956, "
626 "type: type.1905081956, "
627 "kind: kind.1905081956\\]\\.");
633 const auto pData = Component_t::Make(
635 { uT(
"kind"), uT(
"Buffer") },
636 { uT(
"content"), Source },
639 const auto pBuffer = Component_t::Make(
641 { uT(
"id"), uT(
"id.1905082000") },
642 { uT(
"type"), uT(
"type.1905082000") },
643 { uT(
"kind"), uT(
"kind.1905082000") },
644 { uT(
"service"), Object_t{ pData } }
647 EXPECT_STDEXCEPTION(itCreator->second(pBuffer),
648 ".+\\.cpp\\([0-9]+\\): Unexpected buffer format \\["
649 "id: id.1905082000, "
650 "type: type.1905082000, "
651 "kind: kind.1905082000\\]\\.");