diff --git a/tests/live_audiodevice.cc b/tests/live_audiodevice.cc index de1a72a..14e9538 100644 --- a/tests/live_audiodevice.cc +++ b/tests/live_audiodevice.cc @@ -5,6 +5,7 @@ #include #include "testing.h" +#include "movetest.hh" using namespace SDL2pp; @@ -22,6 +23,8 @@ BEGIN_TEST(int, char*[]) ++callback_requests; }); + MOVE_TEST(AudioDevice, device, Get, 0) + { EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PAUSED); EXPECT_TRUE(callback_requests == 0); diff --git a/tests/live_rendering.cc b/tests/live_rendering.cc index 30ed55f..6b5b2e4 100644 --- a/tests/live_rendering.cc +++ b/tests/live_rendering.cc @@ -4,6 +4,7 @@ #include #include "testing.h" +#include "movetest.hh" using namespace SDL2pp; @@ -56,6 +57,8 @@ BEGIN_TEST(int, char*[]) PixelInspector pixels(320, 240, 4); + MOVE_TEST(Renderer, renderer, Get, nullptr); + { // Info SDL_RendererInfo info; @@ -285,6 +288,8 @@ BEGIN_TEST(int, char*[]) Texture texture(renderer, TESTDATA_DIR "/crate.png"); + MOVE_TEST(Texture, texture, Get, nullptr); + EXPECT_EQUAL(texture.GetWidth(), 32); EXPECT_EQUAL(texture.GetHeight(), 32); EXPECT_EQUAL(texture.GetSize(), Point(32, 32)); diff --git a/tests/live_window.cc b/tests/live_window.cc index bdc64e7..cdd8216 100644 --- a/tests/live_window.cc +++ b/tests/live_window.cc @@ -4,6 +4,7 @@ #include #include "testing.h" +#include "movetest.hh" using namespace SDL2pp; @@ -20,21 +21,7 @@ BEGIN_TEST(int, char*[]) SDL sdl(SDL_INIT_VIDEO); Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE); - { - // Move tests - SDL_Window* win = window.Get(); - - Window window1(std::move(window)); - EXPECT_EQUAL(window1.Get(), win); - EXPECT_TRUE(window.Get() == nullptr); - - std::swap(window, window1); - EXPECT_EQUAL(window.Get(), win); - EXPECT_TRUE(window1.Get() == nullptr); - - window = std::move(window); // self-move - EXPECT_EQUAL(window.Get(), win); - } + MOVE_TEST(Window, window, Get, nullptr); EventSleep(1000); // Process events for newborn window diff --git a/tests/movetest.hh b/tests/movetest.hh new file mode 100644 index 0000000..3ec457a --- /dev/null +++ b/tests/movetest.hh @@ -0,0 +1,15 @@ +#define MOVE_TEST(cl, obj, getmethod, nullval) { \ + auto ptr = obj.getmethod(); \ + EXPECT_TRUE(ptr != nullval); \ + \ + cl obj1(std::move(obj)); \ + EXPECT_EQUAL(obj1.getmethod(), ptr); \ + EXPECT_TRUE(obj.getmethod() == nullval); \ + \ + std::swap(obj, obj1); \ + EXPECT_EQUAL(obj.getmethod(), ptr); \ + EXPECT_TRUE(obj1.getmethod() == nullval); \ + \ + obj = std::move(obj); \ + EXPECT_EQUAL(obj.getmethod(), ptr); \ +} diff --git a/tests/test_font.cc b/tests/test_font.cc index d3dd6ba..fca63df 100644 --- a/tests/test_font.cc +++ b/tests/test_font.cc @@ -5,6 +5,7 @@ #include #include "testing.h" +#include "movetest.hh" using namespace SDL2pp; @@ -12,23 +13,7 @@ BEGIN_TEST(int, char*[]) SDLTTF ttf; Font font(TESTDATA_DIR "/Vera.ttf", 30); - { - // Move tests - TTF_Font* ptr = font.Get(); - - EXPECT_TRUE(ptr != nullptr); - - Font font1(std::move(font)); - EXPECT_TRUE(font1.Get() == ptr); - EXPECT_TRUE(font.Get() == nullptr); - - std::swap(font, font1); - EXPECT_TRUE(font.Get() == ptr); - EXPECT_TRUE(font1.Get() == nullptr); - - font = std::move(font); // self-move - EXPECT_TRUE(font.Get() == ptr); - } + MOVE_TEST(Font, font, Get, nullptr); { // Font style diff --git a/tests/test_wav.cc b/tests/test_wav.cc index eeb0bcb..1604de1 100644 --- a/tests/test_wav.cc +++ b/tests/test_wav.cc @@ -3,12 +3,15 @@ #include #include "testing.h" +#include "movetest.hh" using namespace SDL2pp; BEGIN_TEST(int, char*[]) Wav wav(TESTDATA_DIR "/test.wav"); + MOVE_TEST(Wav, wav, GetBuffer, nullptr); + { // Wav tests EXPECT_EQUAL(wav.GetLength(), (Uint32)121044); @@ -29,20 +32,4 @@ BEGIN_TEST(int, char*[]) EXPECT_TRUE(spec.IsSameFormat(spec2)); } - - { - // Move tests - Uint8* buf = wav.GetBuffer(); - - Wav wav1(std::move(wav)); - EXPECT_TRUE(wav1.GetBuffer() == buf); - EXPECT_TRUE(wav.GetBuffer() == nullptr); - - std::swap(wav, wav1); - EXPECT_TRUE(wav.GetBuffer() == buf); - EXPECT_TRUE(wav1.GetBuffer() == nullptr); - - wav = std::move(wav); // self-move - EXPECT_TRUE(wav.GetBuffer() == buf); - } END_TEST()