mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 19:05:59 -04:00
Add standard move test
This commit is contained in:
parent
9097064a4e
commit
62ea64d28d
@ -5,6 +5,7 @@
|
||||
#include <SDL2pp/SDL2pp.hh>
|
||||
|
||||
#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);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <SDL2pp/SDL2pp.hh>
|
||||
|
||||
#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));
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <SDL2pp/SDL2pp.hh>
|
||||
|
||||
#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
|
||||
|
||||
|
15
tests/movetest.hh
Normal file
15
tests/movetest.hh
Normal file
@ -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); \
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
#include <SDL2pp/Exception.hh>
|
||||
|
||||
#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
|
||||
|
@ -3,12 +3,15 @@
|
||||
#include <SDL2pp/Wav.hh>
|
||||
|
||||
#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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user