windowManagerTest.cpp 3.6 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. pwm = static_cast<PlatformWindowManagerSDL*>(CreatePlatformWindowManager());
  41. }
  42. void SetUp() override
  43. {
  44. }
  45. PlatformWindowManagerSDL* pwm;
  46. void TearDown() override
  47. {
  48. delete pwm;
  49. }
  50. };
  51. TEST_F(PlatformWindowManagerSDLTest, Constructor)
  52. {
  53. ASSERT_TRUE(pwm) << "no monitor to test against!";
  54. }
  55. TEST_F(PlatformWindowManagerSDLTest, PrimaryRectTest)
  56. {
  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. // 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. // Now try to get info about all the monitors.
  77. Vector<RectI> monitorRects;
  78. pwm->getMonitorRegions(monitorRects);
  79. EXPECT_GT(monitorRects.size(), 0)
  80. << "Should get at least one monitor rect back from getMonitorRegions!";
  81. }
  82. TEST_F(PlatformWindowManagerSDLTest, MonitorRectsOverflow)
  83. {
  84. // Now try to get info about all the monitors.
  85. Vector<RectI> monitorRects;
  86. pwm->getMonitorRegions(monitorRects);
  87. // This test is here just to detect overflow/runaway situations. -- BJG
  88. EXPECT_LT(monitorRects.size(), 64)
  89. << "Either something's wrong, or you have a lot of monitors...";
  90. }