From f4bb6d57cc88a7e25b3a5f43faafa49a7f500b7c Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 5 Oct 2024 14:16:57 +0200 Subject: restructure unit tests and dummies --- src/CMakeLists.txt | 11 +++++++--- src/crepe/Sound.cpp | 1 + src/dummy_audio.cpp | 40 ------------------------------------ src/example/CMakeLists.txt | 3 +++ src/example/audio_internal.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++ src/readme.md | 8 ++++++++ src/test/CMakeLists.txt | 5 +++++ src/test/audio.cpp | 29 ++++++++++++++++++++++++++ src/test/dummy.cpp | 4 ++++ 9 files changed, 104 insertions(+), 43 deletions(-) delete mode 100644 src/dummy_audio.cpp create mode 100644 src/example/CMakeLists.txt create mode 100644 src/example/audio_internal.cpp create mode 100644 src/readme.md create mode 100644 src/test/CMakeLists.txt create mode 100644 src/test/audio.cpp create mode 100644 src/test/dummy.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 232d330..62ca9a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,10 +9,12 @@ set(CMAKE_BUILD_TYPE Debug) add_compile_definitions(DEBUG) add_subdirectory(../lib/soloud soloud) +add_subdirectory(../lib/googletest googletest) project(crepe C CXX) add_library(crepe SHARED) +add_executable(test_main EXCLUDE_FROM_ALL) target_include_directories(crepe PUBLIC SYSTEM INTERFACE . @@ -24,13 +26,16 @@ target_link_libraries(crepe ) add_subdirectory(crepe) +add_subdirectory(test) +add_subdirectory(example) install( TARGETS crepe FILE_SET HEADERS DESTINATION include/crepe ) - -add_executable(dummy_audio dummy_audio.cpp) -target_link_libraries(dummy_audio PUBLIC crepe) +target_link_libraries(test_main + PRIVATE gtest_main + PUBLIC crepe +) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index e1150ac..1758282 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -58,3 +58,4 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } + diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp deleted file mode 100644 index 049bb49..0000000 --- a/src/dummy_audio.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "crepe/Sound.h" -#include "crepe/util/log.h" - -#include -#include - -using namespace crepe; -using namespace std; -using namespace std::chrono_literals; -using std::make_unique; - -int main() { - dbg_trace(); - - auto bgm = Sound("../mwe/audio/bgm.ogg"); - auto sfx1 = Sound("../mwe/audio/sfx1.wav"); - auto sfx2 = Sound("../mwe/audio/sfx2.wav"); - auto sfx3 = Sound("../mwe/audio/sfx3.wav"); - - bgm.play(); - - // play each sample sequentially - this_thread::sleep_for(500ms); - sfx1.play(); - this_thread::sleep_for(500ms); - sfx2.play(); - bgm.pause(); - this_thread::sleep_for(500ms); - sfx3.play(); - bgm.play(); - this_thread::sleep_for(500ms); - - // play all samples simultaniously - sfx1.play(); - sfx2.play(); - sfx3.play(); - this_thread::sleep_for(1000ms); - - return 0; -} diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt new file mode 100644 index 0000000..bcc9271 --- /dev/null +++ b/src/example/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(audio_internal EXCLUDE_FROM_ALL audio_internal.cpp) +target_link_libraries(audio_internal PUBLIC crepe) + diff --git a/src/example/audio_internal.cpp b/src/example/audio_internal.cpp new file mode 100644 index 0000000..09bd55c --- /dev/null +++ b/src/example/audio_internal.cpp @@ -0,0 +1,46 @@ +/** \file + * + * Standalone example for usage of the internal \c Sound class. + */ + +#include +#include + +#include +#include + +using namespace crepe; +using namespace std; +using namespace std::chrono_literals; +using std::make_unique; + +int main() { + dbg_trace(); + + auto bgm = Sound("../mwe/audio/bgm.ogg"); + auto sfx1 = Sound("../mwe/audio/sfx1.wav"); + auto sfx2 = Sound("../mwe/audio/sfx2.wav"); + auto sfx3 = Sound("../mwe/audio/sfx3.wav"); + + bgm.play(); + + // play each sample sequentially + this_thread::sleep_for(500ms); + sfx1.play(); + this_thread::sleep_for(500ms); + sfx2.play(); + bgm.pause(); + this_thread::sleep_for(500ms); + sfx3.play(); + bgm.play(); + this_thread::sleep_for(500ms); + + // play all samples simultaniously + sfx1.play(); + sfx2.play(); + sfx3.play(); + this_thread::sleep_for(1000ms); + + return 0; +} + diff --git a/src/readme.md b/src/readme.md new file mode 100644 index 0000000..1c5d3a2 --- /dev/null +++ b/src/readme.md @@ -0,0 +1,8 @@ +# engine source + +This folder contains the crêpe engine source files, unit tests, and some toy +examples. The only target built by default by the CMakeLists.txt in this folder +is the crêpe shared library object. Unit tests can be built by explicitly +specifying the target `test_main` when running the build command. Each source +file in the example/ folder corresponds to a CMake target as well. + diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 0000000..0d316d6 --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(test_main PUBLIC + dummy.cpp + # audio.cpp +) + diff --git a/src/test/audio.cpp b/src/test/audio.cpp new file mode 100644 index 0000000..5bb2607 --- /dev/null +++ b/src/test/audio.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include +#include + +#include +#include + +using namespace std; +using namespace std::chrono_literals; + +using namespace crepe::api; + +// TODO: mock internal audio class + +TEST(audio, play) { + auto res = std::make_unique("../mwe/audio/bgm.ogg"); + auto bgm = AudioSource(std::move(res)); + + bgm.play(); + + this_thread::sleep_for(2s); + + bgm.stop(); + + ASSERT_TRUE(true); +} + diff --git a/src/test/dummy.cpp b/src/test/dummy.cpp new file mode 100644 index 0000000..7f4c083 --- /dev/null +++ b/src/test/dummy.cpp @@ -0,0 +1,4 @@ +#include + +TEST(dummy, foo) { ASSERT_TRUE(1); } + -- cgit v1.2.3