foxygit / fake-08-xbox360 Log in
commit 769feae408fd10500f88e245eebad48823f7fda9
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Wed Sep 9 15:06:35 2020 -0600
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Sep 15 17:09:08 2020 -0600

    Add first couple audio tests around sfx
---
 test/Makefile       |  8 +++++++-
 test/audiotests.cpp | 28 ++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/test/Makefile b/test/Makefile
index 8e8be85..ad2f230 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -6,10 +6,11 @@ CFLAGS := -Wall -g -c -O2 \
 all: runtests


-testrunner.a: testroot.o fontdatatests.o graphicstests.o
+testrunner.a: testroot.o fontdatatests.o graphicstests.o audiotests.o
 	g++ testroot.o \
 	fontdata.o fontdatatests.o \
 	graphics.o graphicstests.o stringToDataHelpers.o \
+	Audio.o synth.o audiotests.o \
 	-o testrunner.a

 testroot.o: testroot.cpp doctest.h
@@ -24,6 +25,11 @@ graphicstests.o: graphicstests.cpp ../source/graphics.cpp ../source/graphics.h \
 	../source/stringToDataHelpers.h ../source/stringToDataHelpers.cpp
 	g++ $(CFLAGS) graphicstests.cpp ../source/graphics.cpp ../source/stringToDataHelpers.cpp

+audiotests.o: audiotests.cpp ../source/Audio.cpp ../source/Audio.h \
+	../source/synth.cpp ../source/synth.h \
+	../source/PicoRam.h ../source/hostVmShared.h
+	g++ $(CFLAGS) audiotests.cpp ../source/Audio.cpp ../source/synth.cpp
+

 runtests: testrunner.a
 	./testrunner.a
diff --git a/test/audiotests.cpp b/test/audiotests.cpp
new file mode 100644
index 0000000..ed27cd0
--- /dev/null
+++ b/test/audiotests.cpp
@@ -0,0 +1,28 @@
+#include "doctest.h"
+#include "../source/Audio.h"
+#include "../source/PicoRam.h"
+
+TEST_CASE("audio class behaves as expected") {
+    //general setup
+    PicoRam picoRam;
+    picoRam = {0};
+    Audio* audio = new Audio(&picoRam);
+
+    SUBCASE("Audio constructor sets sfx channels to -1") {
+        bool allChannelsOff = true;
+
+        for(int i = 0; i < 4; i++) {
+            allChannelsOff &= picoRam._sfxChannels[i].sfxId == -1;
+        }
+
+        CHECK(allChannelsOff);
+    }
+    SUBCASE("api_sfx() with valid values sets the sfx to be played") {
+        int channel = 0;
+        int sfxId = 3;
+        audio->api_sfx(sfxId, channel, 0);
+
+        CHECK_EQ(picoRam._sfxChannels[0].sfxId, sfxId);
+    }
+
+}
\ No newline at end of file