diff --git a/.gitignore b/.gitignore index a0771e7..ca7b258 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ libSDL2pp.so.* tests/*.exe tests/live_mixer tests/live_rendering +tests/live_window tests/test_error tests/test_optional tests/test_pointrect diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7424787..36bb3d1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,7 @@ SET(CLI_TESTS # live tests require X11 display and/or audio output SET(LIVE_TESTS live_rendering + live_window ) IF(SDL2PP_WITH_MIXER) diff --git a/tests/live_window.cc b/tests/live_window.cc new file mode 100644 index 0000000..0c1a9d9 --- /dev/null +++ b/tests/live_window.cc @@ -0,0 +1,68 @@ +#include + +#include +#include + +#include "testing.h" + +using namespace SDL2pp; + +static void ProcessEvents() { + SDL_Event event; + while (SDL_PollEvent(&event)) { + } +} + +BEGIN_TEST(int, char*[]) + SDL sdl(SDL_INIT_VIDEO); + Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, 0); + + ProcessEvents(); + + { + // Size + EXPECT_EQUAL(window.GetSize(), Point(320, 240)); + EXPECT_EQUAL(window.GetWidth(), 320); + EXPECT_EQUAL(window.GetHeight(), 240); + + window.SetSize(400, 300); + + EXPECT_EQUAL(window.GetSize(), Point(400, 300)); + EXPECT_EQUAL(window.GetWidth(), 400); + EXPECT_EQUAL(window.GetHeight(), 300); + } + + { + // Title + EXPECT_EQUAL(window.GetTitle(), "libSDL2pp test"); + + window.SetTitle("libSDL2pp window test"); + + EXPECT_EQUAL(window.GetTitle(), "libSDL2pp window test"); + } + + { + // Drawable size + EXPECT_EQUAL(window.GetDrawableSize(), Point(window.GetDrawableWidth(), window.GetDrawableHeight())); + + // Drawable may be larget than window size, see SDL docs + // Should we compare with multiplies of window size? + EXPECT_TRUE(window.GetDrawableWidth() >= window.GetWidth()); + EXPECT_TRUE(window.GetDrawableHeight() >= window.GetHeight()); + EXPECT_TRUE(window.GetDrawableWidth() > window.GetDrawableHeight()); + } + + { + // Position + Point old_pos = window.GetPosition(); + + window.SetPosition(old_pos + Point(2, 1)); + + EXPECT_EQUAL(window.GetPosition(), old_pos + Point(2, 1)); + + window.SetPosition(old_pos.x + 4, old_pos.y + 2); + + EXPECT_EQUAL(window.GetPosition(), old_pos + Point(4, 2)); + } + +END_TEST()