mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15: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 <SDL2pp/SDL2pp.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "movetest.hh"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ BEGIN_TEST(int, char*[])
|
|||||||
++callback_requests;
|
++callback_requests;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
MOVE_TEST(AudioDevice, device, Get, 0)
|
||||||
|
|
||||||
{
|
{
|
||||||
EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PAUSED);
|
EXPECT_TRUE(device.GetStatus(), SDL_AUDIO_PAUSED);
|
||||||
EXPECT_TRUE(callback_requests == 0);
|
EXPECT_TRUE(callback_requests == 0);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <SDL2pp/SDL2pp.hh>
|
#include <SDL2pp/SDL2pp.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "movetest.hh"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
@ -56,6 +57,8 @@ BEGIN_TEST(int, char*[])
|
|||||||
|
|
||||||
PixelInspector pixels(320, 240, 4);
|
PixelInspector pixels(320, 240, 4);
|
||||||
|
|
||||||
|
MOVE_TEST(Renderer, renderer, Get, nullptr);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Info
|
// Info
|
||||||
SDL_RendererInfo info;
|
SDL_RendererInfo info;
|
||||||
@ -285,6 +288,8 @@ BEGIN_TEST(int, char*[])
|
|||||||
|
|
||||||
Texture texture(renderer, TESTDATA_DIR "/crate.png");
|
Texture texture(renderer, TESTDATA_DIR "/crate.png");
|
||||||
|
|
||||||
|
MOVE_TEST(Texture, texture, Get, nullptr);
|
||||||
|
|
||||||
EXPECT_EQUAL(texture.GetWidth(), 32);
|
EXPECT_EQUAL(texture.GetWidth(), 32);
|
||||||
EXPECT_EQUAL(texture.GetHeight(), 32);
|
EXPECT_EQUAL(texture.GetHeight(), 32);
|
||||||
EXPECT_EQUAL(texture.GetSize(), Point(32, 32));
|
EXPECT_EQUAL(texture.GetSize(), Point(32, 32));
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <SDL2pp/SDL2pp.hh>
|
#include <SDL2pp/SDL2pp.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "movetest.hh"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
@ -20,21 +21,7 @@ BEGIN_TEST(int, char*[])
|
|||||||
SDL sdl(SDL_INIT_VIDEO);
|
SDL sdl(SDL_INIT_VIDEO);
|
||||||
Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE);
|
Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
{
|
MOVE_TEST(Window, window, Get, nullptr);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventSleep(1000); // Process events for newborn window
|
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 <SDL2pp/Exception.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "movetest.hh"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
@ -12,23 +13,7 @@ BEGIN_TEST(int, char*[])
|
|||||||
SDLTTF ttf;
|
SDLTTF ttf;
|
||||||
Font font(TESTDATA_DIR "/Vera.ttf", 30);
|
Font font(TESTDATA_DIR "/Vera.ttf", 30);
|
||||||
|
|
||||||
{
|
MOVE_TEST(Font, font, Get, nullptr);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// Font style
|
// Font style
|
||||||
|
@ -3,12 +3,15 @@
|
|||||||
#include <SDL2pp/Wav.hh>
|
#include <SDL2pp/Wav.hh>
|
||||||
|
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
|
#include "movetest.hh"
|
||||||
|
|
||||||
using namespace SDL2pp;
|
using namespace SDL2pp;
|
||||||
|
|
||||||
BEGIN_TEST(int, char*[])
|
BEGIN_TEST(int, char*[])
|
||||||
Wav wav(TESTDATA_DIR "/test.wav");
|
Wav wav(TESTDATA_DIR "/test.wav");
|
||||||
|
|
||||||
|
MOVE_TEST(Wav, wav, GetBuffer, nullptr);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Wav tests
|
// Wav tests
|
||||||
EXPECT_EQUAL(wav.GetLength(), (Uint32)121044);
|
EXPECT_EQUAL(wav.GetLength(), (Uint32)121044);
|
||||||
@ -29,20 +32,4 @@ BEGIN_TEST(int, char*[])
|
|||||||
|
|
||||||
EXPECT_TRUE(spec.IsSameFormat(spec2));
|
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()
|
END_TEST()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user