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_Texture)
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_Sampler_TextureArray)
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 auto itStateCreator = IExample.GetCreators().find(uT(
"State"));
126 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
128 auto itTextureCreator = IExample.GetCreators().find(uT(
"TextureArray"));
129 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
131 auto SamplerRender = itStateCreator->second(Component_t::Make(
133 { uT(
"kind"), uT(
"Sampler") }
135 ASSERT_NE(
nullptr, SamplerRender);
137 auto TextureRender = itTextureCreator->second(Component_t::Make({ }));
138 ASSERT_NE(
nullptr, TextureRender);
140 using namespace ::testing;
142 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
149 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, _))
152 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
156 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
160 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT))
163 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT))
170TEST_F(OpenGLCommon_test, Test_State_Scissor_Enable)
172 using GLProxy_t = ::mock::GLProxy;
174 GLProxy_t::GetInstance() = &GLProxy;
176 const Tested_t Example{ Data_t{} };
177 const ITested_t & IExample = Example;
179 const auto pScissorData = Component_t::Make(
181 { uT(
"kind"), uT(
"Rect") },
184 auto itCreatorState = IExample.GetCreators().find(uT(
"State"));
185 ASSERT_NE(IExample.GetCreators().end(), itCreatorState);
187 const auto pScissor = Component_t::Make(
189 { uT(
"kind"), uT(
"Scissor") },
190 { uT(
"enabled"),
true },
191 { uT(
"service"), Object_t{ pScissorData } },
194 auto Render = itCreatorState->second(pScissor);
195 ASSERT_NE(
nullptr, Render);
197 auto TestCallRender =
198 [&](
int _X,
int _Y,
int _Width,
int _Height,
int _WindowHeight)
200 const int Yo = _WindowHeight - (_Y + _Height);
202 (*pScissorData)[uT(
"left")] = _X;
203 (*pScissorData)[uT(
"top")] = _Y;
204 (*pScissorData)[uT(
"right")] = _X + _Width;
205 (*pScissorData)[uT(
"bottom")] = _Y + _Height;
207 using namespace ::testing;
211 EXPECT_CALL(GLProxy, Enable(GL_SCISSOR_TEST))
214 const int Viewport[4] = { 0, 0, 0, _WindowHeight };
216 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
218 .WillOnce(Return(Viewport));
220 EXPECT_CALL(GLProxy, Scissor(_X, Yo, _Width, _Height))
228 TestCallRender(1509, 1510, 1511, 1512, 1513);
229 TestCallRender(1514, 1515, 1516, 1517, 1518);
233TEST_F(OpenGLCommon_test, Test_State_Scissor_Disable)
235 using GLProxy_t = ::mock::GLProxy;
237 GLProxy_t::GetInstance() = &GLProxy;
239 const Tested_t Example{ Data_t{} };
240 const ITested_t & IExample = Example;
242 auto itCreator = IExample.GetCreators().find(uT(
"State"));
243 ASSERT_NE(IExample.GetCreators().end(), itCreator);
245 const auto pComponent = Component_t::Make(
247 { uT(
"kind"), uT(
"Scissor") },
248 { uT(
"enabled"),
false },
251 auto Render = itCreator->second(pComponent);
252 ASSERT_NE(
nullptr, Render);
254 using namespace ::testing;
256 EXPECT_CALL(GLProxy, Disable(GL_SCISSOR_TEST))
263TEST_F(OpenGLCommon_test, Test_State_Depth_Disabled)
265 using GLProxy_t = ::mock::GLProxy;
267 GLProxy_t::GetInstance() = &GLProxy;
269 const Tested_t Example{ Data_t{} };
270 const ITested_t & IExample = Example;
272 auto itCreator = IExample.GetCreators().find(uT(
"State"));
273 ASSERT_NE(IExample.GetCreators().end(), itCreator);
275 using namespace ::testing;
277 const auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pState)
279 auto Render = itCreator->second(_pState);
280 ASSERT_NE(
nullptr, Render);
282 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
285 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
288 EXPECT_CALL(GLProxy, DepthFunc(_))
291 EXPECT_CALL(GLProxy, ClearDepth(_))
294 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
300 TestCallRender(Component_t::Make(
302 { uT(
"kind"), uT(
"Depth") },
305 TestCallRender(Component_t::Make(
307 { uT(
"kind"), uT(
"Depth") },
308 { uT(
"enabled"),
false },
313TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_NoClear_Overwrite)
315 using GLProxy_t = ::mock::GLProxy;
317 GLProxy_t::GetInstance() = &GLProxy;
319 const Tested_t Example{ Data_t{} };
320 const ITested_t & IExample = Example;
322 auto itCreator = IExample.GetCreators().find(uT(
"State"));
323 ASSERT_NE(IExample.GetCreators().end(), itCreator);
325 using namespace ::testing;
327 const auto Render = itCreator->second(Component_t::Make(
329 { uT(
"kind"), uT(
"Depth") },
330 { uT(
"enabled"),
true },
331 { uT(
"clear"),
false },
333 ASSERT_NE(
nullptr, Render);
335 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
338 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
341 EXPECT_CALL(GLProxy, DepthMask(GL_TRUE))
344 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
347 EXPECT_CALL(GLProxy, ClearDepth(_))
350 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
357TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_Clear_Overwrite)
359 using GLProxy_t = ::mock::GLProxy;
361 GLProxy_t::GetInstance() = &GLProxy;
363 const Tested_t Example{ Data_t{} };
364 const ITested_t & IExample = Example;
366 auto itCreator = IExample.GetCreators().find(uT(
"State"));
367 ASSERT_NE(IExample.GetCreators().end(), itCreator);
369 using namespace ::testing;
371 const auto Render = itCreator->second(Component_t::Make(
373 { uT(
"kind"), uT(
"Depth") },
374 { uT(
"enabled"),
true },
375 { uT(
"clear"),
true },
377 ASSERT_NE(
nullptr, Render);
379 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
382 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
385 EXPECT_CALL(GLProxy, DepthMask(GL_TRUE))
388 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
391 EXPECT_CALL(GLProxy, ClearDepth(0.0f))
394 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
401TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_NoClear_NoOverwrite)
403 using GLProxy_t = ::mock::GLProxy;
405 GLProxy_t::GetInstance() = &GLProxy;
407 const Tested_t Example{ Data_t{} };
408 const ITested_t & IExample = Example;
410 auto itCreator = IExample.GetCreators().find(uT(
"State"));
411 ASSERT_NE(IExample.GetCreators().end(), itCreator);
413 using namespace ::testing;
415 const auto Render = itCreator->second(Component_t::Make(
417 { uT(
"kind"), uT(
"Depth") },
418 { uT(
"enabled"),
true },
419 { uT(
"clear"),
false },
420 { uT(
"overwrite"),
false },
422 ASSERT_NE(
nullptr, Render);
424 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
427 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
430 EXPECT_CALL(GLProxy, DepthMask(GL_FALSE))
433 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
436 EXPECT_CALL(GLProxy, ClearDepth(_))
439 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
446TEST_F(OpenGLCommon_test, Test_State_Depth_Enable_Clear_NoOverwrite)
448 using GLProxy_t = ::mock::GLProxy;
450 GLProxy_t::GetInstance() = &GLProxy;
452 const Tested_t Example{ Data_t{} };
453 const ITested_t & IExample = Example;
455 auto itCreator = IExample.GetCreators().find(uT(
"State"));
456 ASSERT_NE(IExample.GetCreators().end(), itCreator);
458 using namespace ::testing;
460 const auto Render = itCreator->second(Component_t::Make(
462 { uT(
"kind"), uT(
"Depth") },
463 { uT(
"enabled"),
true },
464 { uT(
"clear"),
true },
465 { uT(
"overwrite"),
false },
467 ASSERT_NE(
nullptr, Render);
469 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
472 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
475 EXPECT_CALL(GLProxy, DepthMask(GL_FALSE))
478 EXPECT_CALL(GLProxy, DepthFunc(GL_GREATER))
481 EXPECT_CALL(GLProxy, ClearDepth(0.0f))
484 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
491TEST_F(OpenGLCommon_test, Test_State_Clear)
493 using Color_t = ::std::vector<float>;
495 using GLProxy_t = ::mock::GLProxy;
497 GLProxy_t::GetInstance() = &GLProxy;
499 Tested_t Example{ Data_t{ } };
500 ITested_t & IExample = Example;
502 auto itCreator = IExample.GetCreators().find(uT(
"State"));
503 ASSERT_NE(IExample.GetCreators().end(), itCreator);
505 const auto TestCallRender = [&](
506 const Component_t::ComponentPtr_t & _pState,
507 const Color_t & _ExpectedColor)
509 const auto Render = itCreator->second(_pState);
510 ASSERT_NE(
nullptr, Render);
512 using namespace ::testing;
516 ASSERT_EQ(4, _ExpectedColor.size());
518 EXPECT_CALL(GLProxy, ClearColor(_ExpectedColor[0], _ExpectedColor[1],
519 _ExpectedColor[2], _ExpectedColor[3]))
522 EXPECT_CALL(GLProxy, Clear(GL_COLOR_BUFFER_BIT))
529 const ::std::vector<FLOAT> DefaultColor =
537 TestCallRender(Component_t::Make(
539 { uT(
"kind"), uT(
"Clear") },
544 const ::std::vector<FLOAT> Color =
546 0.86274509803921568627450980392157f,
547 0.72941176470588235294117647058824f,
548 0.5960784313725490196078431372549f,
549 0.9960784313725490196078431372549f,
552 TestCallRender(Component_t::Make(
554 { uT(
"kind"), uT(
"Clear") },
555 { uT(
"color"), 0xFEDCBA98 },
561TEST_F(OpenGLCommon_test, Test_Texture_glTexImage2D_Fail)
563 using GLProxy_t = ::mock::GLProxy;
565 GLProxy_t::GetInstance() = &GLProxy;
567 const ::mock::GLuint TextureId = 1612182301;
569 const Tested_t Example{ Data_t{} };
570 const ITested_t & IExample = Example;
572 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
573 ASSERT_NE(IExample.GetCreators().end(), itCreator);
575 using namespace ::testing;
579 EXPECT_CALL(GLProxy, GenTextures(1))
581 .WillOnce(Return(TextureId));
583 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
586 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
589 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
592 EXPECT_CALL(GLProxy, GetError())
594 .WillOnce(Return(1808261916));
596 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
600TEST_F(OpenGLCommon_test, Test_Texture_UnknownDestination)
602 using GLProxy_t = ::mock::GLProxy;
604 GLProxy_t::GetInstance() = &GLProxy;
606 const Tested_t Example{ Data_t{} };
607 const ITested_t & IExample = Example;
609 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
610 ASSERT_NE(IExample.GetCreators().end(), itCreator);
612 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture)
614 const ::mock::GLuint TextureId = 1812181809;
616 using namespace ::testing;
620 EXPECT_CALL(GLProxy, GenTextures(_))
623 EXPECT_CALL(GLProxy, BindTexture(_, _))
626 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
629 EXPECT_CALL(GLProxy, GetError())
632 EXPECT_THROW(itCreator->second(_pTexture), ::std::exception);
636 const auto pTexture = Component_t::Make(
638 { uT(
"destination"), uT(
"1907251102") },
645 const auto pData = Component_t::Make(
647 { uT(
"kind"), uT(
"Texture") },
648 { uT(
"destination"), uT(
"1907251103") },
651 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
656TEST_F(OpenGLCommon_test, Test_TextureArray_Create_Fail)
658 using GLProxy_t = ::mock::GLProxy;
660 GLProxy_t::GetInstance() = &GLProxy;
662 const ::mock::GLuint TextureId = 2504062041;
664 const Tested_t Example{ Data_t{} };
665 const ITested_t & IExample = Example;
667 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
668 ASSERT_NE(IExample.GetCreators().end(), itCreator);
670 using namespace ::testing;
674 EXPECT_CALL(GLProxy, GenTextures(1))
676 .WillOnce(Return(TextureId));
678 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
681 EXPECT_CALL(GLProxy, TexStorage3D(_, _, _, _, _, _))
684 EXPECT_CALL(GLProxy, TexSubImage3D_1(_, _, _, _, _, _, _))
687 EXPECT_CALL(GLProxy, TexSubImage3D_2(_, _, _, _))
690 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
693 EXPECT_CALL(GLProxy, GetError())
695 .WillOnce(Return(2504062042));
697 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
701TEST_F(OpenGLCommon_test, Test_TextureArray_UnknownDestination)
703 using GLProxy_t = ::mock::GLProxy;
705 GLProxy_t::GetInstance() = &GLProxy;
707 const Tested_t Example{ Data_t{} };
708 const ITested_t & IExample = Example;
710 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
711 ASSERT_NE(IExample.GetCreators().end(), itCreator);
713 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture)
715 const ::mock::GLuint TextureId = 2504062208;
717 using namespace ::testing;
721 EXPECT_CALL(GLProxy, GenTextures(_))
724 EXPECT_CALL(GLProxy, BindTexture(_, _))
727 EXPECT_CALL(GLProxy, TexStorage3D(_, _, _, _, _, _))
730 EXPECT_CALL(GLProxy, TexSubImage3D_1(_, _, _, _, _, _, _))
733 EXPECT_CALL(GLProxy, TexSubImage3D_2(_, _, _, _))
736 EXPECT_CALL(GLProxy, GetError())
739 EXPECT_THROW(itCreator->second(_pTexture), ::std::exception);
743 const auto pTexture = Component_t::Make(
745 { uT(
"destination"), uT(
"2504062206") },
752 const auto pData = Component_t::Make(
754 { uT(
"kind"), uT(
"TextureArray") },
755 { uT(
"destination"), uT(
"2504062207") },
758 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
763TEST_F(OpenGLCommon_test, Test_Buffer_UnknownType)
765 const ::std::vector<float> Source = { 0.0f };
767 const Tested_t Example{ Data_t{} };
768 const ITested_t & IExample = Example;
770 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
771 ASSERT_NE(IExample.GetCreators().end(), itCreator);
776 const auto pBuffer = Component_t::Make(
778 { uT(
"id"), uT(
"id.1905081956") },
779 { uT(
"type"), uT(
"type.1905081956") },
780 { uT(
"kind"), uT(
"kind.1905081956") },
781 { uT(
"content"), Source },
784 EXPECT_STDEXCEPTION(itCreator->second(pBuffer),
785 ".+\\.cpp\\([0-9]+\\): Unexpected buffer format \\["
786 "id: id.1905081956, "
787 "type: type.1905081956, "
788 "kind: kind.1905081956\\]\\.");
794 const auto pData = Component_t::Make(
796 { uT(
"kind"), uT(
"Buffer") },
797 { uT(
"content"), Source },
800 const auto pBuffer = Component_t::Make(
802 { uT(
"id"), uT(
"id.1905082000") },
803 { uT(
"type"), uT(
"type.1905082000") },
804 { uT(
"kind"), uT(
"kind.1905082000") },
805 { uT(
"service"), Object_t{ pData } }
808 EXPECT_STDEXCEPTION(itCreator->second(pBuffer),
809 ".+\\.cpp\\([0-9]+\\): Unexpected buffer format \\["
810 "id: id.1905082000, "
811 "type: type.1905082000, "
812 "kind: kind.1905082000\\]\\.");