windowManagerTest.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. using ::testing::Matcher;
  30. using ::testing::TypedEq;
  31. class PlatformWindowManagerSDLTest : public ::testing::Test
  32. {
  33. protected:
  34. PlatformWindowManagerSDLTest()
  35. {
  36. putenv("SDL_VIDEODRIVER=dummy");
  37. putenv("SDL_AUDIODRIVER=dummy");
  38. // for tests in this class we probably only need the init_video an nothing else.
  39. SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE);
  40. }
  41. void SetUp() override
  42. {
  43. }
  44. void TearDown() override
  45. {
  46. }
  47. };
  48. TEST_F(PlatformWindowManagerSDLTest, Constructor)
  49. {
  50. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  51. ASSERT_TRUE(pwm) << "no monitor to test against!";
  52. }
  53. TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
  54. {
  55. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  56. // Check out the primary desktop area...
  57. RectI primary = pwm->getPrimaryDesktopArea();
  58. EXPECT_TRUE(primary.isValidRect())
  59. << "Got some sort of invalid rect from the window manager!";
  60. }
  61. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsValid)
  62. {
  63. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  64. // Now try to get info about all the monitors.
  65. Vector<RectI> monitorRects;
  66. pwm->getMonitorRegions(monitorRects);
  67. // should override the function above to test this with multiple setups.
  68. for (S32 i = 0; i < monitorRects.size(); i++)
  69. {
  70. EXPECT_TRUE(monitorRects[i].isValidRect())
  71. << "Got an invalid rect for this monitor - no good.";
  72. }
  73. }
  74. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsAtLeastOne)
  75. {
  76. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  77. // Now try to get info about all the monitors.
  78. Vector<RectI> monitorRects;
  79. pwm->getMonitorRegions(monitorRects);
  80. EXPECT_GT(monitorRects.size(), 0)
  81. << "Should get at least one monitor rect back from getMonitorRegions!";
  82. }
  83. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
  84. {
  85. PlatformWindowManagerSDL* pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  86. // Now try to get info about all the monitors.
  87. Vector<RectI> monitorRects;
  88. pwm->getMonitorRegions(monitorRects);
  89. // This test is here just to detect overflow/runaway situations. -- BJG
  90. EXPECT_LT(monitorRects.size(), 64)
  91. << "Either something's wrong, or you have a lot of monitors...";
  92. }