commit 9e57678114b68c54e1b927e0e343c987c98a2b8b
Author: Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sun Jun 12 20:58:24 2022 -0600
Commit: Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Jun 18 15:20:02 2022 -0600
WIP adding a test the verify loading carts
---
source/vm.cpp | 4 +--
source/vm.h | 2 +-
test/Makefile | 8 +++++-
test/cartloadingtest.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 75 insertions(+), 4 deletions(-)
diff --git a/source/vm.cpp b/source/vm.cpp
index 57e538a..d0981ce 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -394,7 +394,7 @@ void Vm::LoadSettingsCart(){
}
}
-void Vm::LoadCart(std::string filename){
+void Vm::LoadCart(std::string filename, bool loadBiosOnFail){
if (filename == "__FAKE08-BIOS.p8") {
LoadBiosCart();
return;
@@ -414,7 +414,7 @@ void Vm::LoadCart(std::string filename){
bool success = loadCart(cart);
- if (!success) {
+ if (loadBiosOnFail && !success) {
CloseCart();
//todo: show an error message on the bios?
LoadBiosCart();
diff --git a/source/vm.h b/source/vm.h
index 3431f87..10fca8a 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -69,7 +69,7 @@ class Vm {
void LoadSettingsCart();
- void LoadCart(string filename);
+ void LoadCart(string filename, bool loadBiosOnFail = true);
void UpdateAndDraw();
diff --git a/test/Makefile b/test/Makefile
index 88078fd..8575a22 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -9,7 +9,7 @@ all: runtests
testrunner.a: testroot.o \
fontdatatests.o nibblehelperstests.o graphicstests.o audiotests.o \
- carttests.o endtoendtests.o vmtests.o filehelperstests.o printHelperTests.o
+ carttests.o endtoendtests.o vmtests.o cartloadingtest.o filehelperstests.o printHelperTests.o
g++ -I$(CURDIR)/include -L$(CURDIR)/lib \
testroot.o \
fontdata.o fontdatatests.o \
@@ -19,6 +19,7 @@ testrunner.a: testroot.o \
cart.o carttests.o nooplogger.o lodepng.o emojiconversion.o filehelpers.o \
vm.o endtoendtests.o picoluaapi.o Input.o \
vmtests.o stubhost.o \
+ cartloadingtest.o \
nibblehelpers.o nibblehelperstests.o \
filehelperstests.o \
-llua -ldl \
@@ -89,6 +90,11 @@ vmtests.o: endtoendtests.o \
g++ $(CFLAGS) -I$(CURDIR)/include -L$(CURDIR)/lib \
vmtests.cpp stubhost.cpp ../source/vm.cpp ../source/picoluaapi.cpp ../source/Input.cpp
+cartloadingtest.o: vmtests.o \
+ cartloadingtest.cpp
+ g++ $(CFLAGS) -I$(CURDIR)/include -L$(CURDIR)/lib \
+ cartloadingtest.cpp
+
filehelperstests.o: filehelperstests.cpp ../source/filehelpers.cpp ../source/filehelpers.h
g++ $(CFLAGS) filehelperstests.cpp ../source/filehelpers.cpp
diff --git a/test/cartloadingtest.cpp b/test/cartloadingtest.cpp
new file mode 100644
index 0000000..aad0c91
--- /dev/null
+++ b/test/cartloadingtest.cpp
@@ -0,0 +1,65 @@
+#include <string>
+#include <vector>
+#include <sstream>
+#include <algorithm>
+
+#include <stdio.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include "doctest.h"
+#include "../libs/lodepng/lodepng.h"
+
+#include "../source/vm.h"
+#include "../source/host.h"
+#include "../source/hostVmShared.h"
+#include "../source/nibblehelpers.h"
+#include "../source/filehelpers.h"
+
+TEST_CASE("Loading and running carts") {
+ Host* host = new Host();
+ Vm* vm = new Vm(host);
+
+ vector<string> carts;
+ vector<string> errors;
+
+ std::string _cartDirectory = "/Users/jon/p8carts/old/shouldfail";
+
+ DIR *dir;
+ struct dirent *ent;
+ if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
+ /* print all the files and directories within directory */
+ while ((ent = readdir (dir)) != NULL) {
+ if (isCartFile(ent->d_name)){
+ carts.push_back(ent->d_name);
+ }
+ }
+ closedir (dir);
+ } else {
+ /* could not open directory */
+ perror ("");
+ }
+
+
+ for(int i = 0; i < carts.size(); i++) {
+ vm->LoadCart(carts[i], false);
+
+ if (vm->GetBiosError() != "") {
+ errors.push_back(carts[i] + vm->GetBiosError());
+ }
+ else
+ {
+ vm->UpdateAndDraw();
+
+ if (vm->GetBiosError() != "") {
+ errors.push_back(carts[i] + vm->GetBiosError());
+ }
+ }
+
+ vm->CloseCart();
+ }
+
+
+ delete vm;
+ delete host;
+}
\ No newline at end of file