diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9bb294f..afe1a55 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,11 @@ # simple command-line tests SET(CLI_TESTS + test_error + test_optional test_pointrect test_pointrect_constexpr test_rwops - test_optional - test_error + test_wav ) # live tests require X11 display and/or audio output diff --git a/tests/test_wav.cc b/tests/test_wav.cc new file mode 100644 index 0000000..5137e73 --- /dev/null +++ b/tests/test_wav.cc @@ -0,0 +1,38 @@ +#include + +#include + +#include "testing.h" + +using namespace SDL2pp; + +BEGIN_TEST(int, char*[]) + Wav wav(TESTDATA_DIR "/test.wav"); + + { + EXPECT_EQUAL(wav.GetLength(), (Uint32)121044); + EXPECT_TRUE(wav.GetBuffer() != nullptr); + EXPECT_TRUE((const Uint8*)wav.GetBuffer() == (Uint8*)wav.GetBuffer()); + + const AudioSpec& spec = wav.GetSpec(); + + EXPECT_EQUAL(spec.Get()->freq, 44100); + EXPECT_EQUAL((int)spec.Get()->channels, 2); + } + + { + // 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()