2
0

windowManagerTest.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2014 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "unitTesting.h"
  23. #include "windowManager/platformWindow.h"
  24. #include "windowManager/platformWindowMgr.h"
  25. #include "platform/platformInput.h"
  26. #include "platform/input/IProcessInput.h"
  27. #include "windowManager/sdl/sdlWindowMgr.h"
  28. #include "core/util/tVector.h"
  29. #include <SDL.h>
  30. using ::testing::Matcher;
  31. using ::testing::TypedEq;
  32. class PlatformWindowManagerSDLTest : public ::testing::Test
  33. {
  34. protected:
  35. PlatformWindowManagerSDLTest()
  36. {
  37. putenv("SDL_VIDEODRIVER=dummy");
  38. putenv("SDL_AUDIODRIVER=dummy");
  39. // for tests in this class we probably only need the init_video an nothing else.
  40. SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE);
  41. }
  42. void SetUp() override
  43. {
  44. }
  45. void TearDown() override
  46. {
  47. }
  48. };
  49. TEST_F(PlatformWindowManagerSDLTest, Constructor)
  50. {
  51. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  52. ASSERT_TRUE(pwm) << "no monitor to test against!";
  53. }
  54. TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
  55. {
  56. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  57. // Check out the primary desktop area...
  58. RectI primary = pwm->getPrimaryDesktopArea();
  59. EXPECT_TRUE(primary.isValidRect())
  60. << "Got some sort of invalid rect from the window manager!";
  61. }
  62. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
  63. {
  64. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  65. // Now try to get info about all the monitors.
  66. Vector<RectI> monitorRects;
  67. pwm->getMonitorRegions(monitorRects);
  68. // should override the function above to test this with multiple setups.
  69. for (S32 i = 0; i < monitorRects.size(); i++)
  70. {
  71. EXPECT_TRUE(monitorRects[i].isValidRect())
  72. << "Got an invalid rect for this monitor - no good.";
  73. }
  74. }
  75. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
  76. {
  77. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  78. // Now try to get info about all the monitors.
  79. Vector<RectI> monitorRects;
  80. pwm->getMonitorRegions(monitorRects);
  81. EXPECT_GT(monitorRects.size(), 0)
  82. << "Should get at least one monitor rect back from getMonitorRegions!";
  83. }
  84. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
  85. {
  86. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  87. // Now try to get info about all the monitors.
  88. Vector<RectI> monitorRects;
  89. pwm->getMonitorRegions(monitorRects);
  90. // This test is here just to detect overflow/runaway situations. -- BJG
  91. EXPECT_LT(monitorRects.size(), 64)
  92. << "Either something's wrong, or you have a lot of monitors...";
  93. }