aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-05 14:16:57 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-05 14:16:57 +0200
commitf4bb6d57cc88a7e25b3a5f43faafa49a7f500b7c (patch)
treebe9be8157c10599f572d20113795dc14c620a292 /src
parent65eda52aa51017f6f7aad158c4f8b6e91054cf0d (diff)
restructure unit tests and dummies
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt11
-rw-r--r--src/crepe/Sound.cpp1
-rw-r--r--src/example/CMakeLists.txt3
-rw-r--r--src/example/audio_internal.cpp (renamed from src/dummy_audio.cpp)10
-rw-r--r--src/readme.md8
-rw-r--r--src/test/CMakeLists.txt5
-rw-r--r--src/test/audio.cpp29
-rw-r--r--src/test/dummy.cpp4
8 files changed, 66 insertions, 5 deletions
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/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/dummy_audio.cpp b/src/example/audio_internal.cpp
index 049bb49..09bd55c 100644
--- a/src/dummy_audio.cpp
+++ b/src/example/audio_internal.cpp
@@ -1,5 +1,10 @@
-#include "crepe/Sound.h"
-#include "crepe/util/log.h"
+/** \file
+ *
+ * Standalone example for usage of the internal \c Sound class.
+ */
+
+#include <crepe/Sound.h>
+#include <crepe/util/log.h>
#include <chrono>
#include <thread>
@@ -38,3 +43,4 @@ int main() {
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 <gtest/gtest.h>
+#include <memory>
+
+#include <crepe/api/AudioSource.h>
+#include <crepe/api/Resource.h>
+
+#include <chrono>
+#include <thread>
+
+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<Resource>("../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 <gtest/gtest.h>
+
+TEST(dummy, foo) { ASSERT_TRUE(1); }
+