Make Test a template function for easy comparison with values.

Also allows further logging and output in the future.
This commit is contained in:
archshift 2014-12-10 19:46:17 -08:00
parent 38a0c47d43
commit 3f083e0e0e
5 changed files with 23 additions and 49 deletions

View File

@ -111,11 +111,11 @@ static bool Ssax() {
void TestAll() { void TestAll() {
const std::string tag = "Integer"; const std::string tag = "Integer";
Test(tag, "ADD", &Add); Test(tag, "ADD", Add(), true);
Test(tag, "SUB", &Sub); Test(tag, "SUB", Sub(), true);
Test(tag, "MUL", &Mul); Test(tag, "MUL", Mul(), true);
Test(tag, "SASX", &Sasx); Test(tag, "SASX", Sasx(), true);
Test(tag, "SSAX", &Ssax); Test(tag, "SSAX", Ssax(), true);
} }
} }

View File

@ -8,15 +8,11 @@ namespace FS {
void TestAll() void TestAll()
{ {
TestResult("FS", "Initializing service", [&]{ Test("FS", "Initializing service", fsInit(), 0L);
return fsInit();
});
SDMC::TestAll(); SDMC::TestAll();
TestResult("FS", "Exiting service", [&]{ Test("FS", "Exiting service", fsExit(), 0L);
return fsExit();
});
} }
} // namespace } // namespace

View File

@ -145,35 +145,13 @@ void TestAll()
{ {
FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } }; FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
// Open SDMC Test("SDMC", "Opening archive", FSUSER_OpenArchive(NULL, &sdmcArchive), 0L);
TestResult("SDMC", "Opening archive", [&]{ Test("SDMC", "Creating and deleting file", TestFileCreateDelete(sdmcArchive), true);
return FSUSER_OpenArchive(NULL, &sdmcArchive); Test("SDMC", "Renaming file", TestFileRename(sdmcArchive), true);
}); Test("SDMC", "Writing and reading file", TestFileWriteRead(sdmcArchive), true);
Test("SDMC", "Creating and deleting directory", TestDirCreateDelete(sdmcArchive), true);
Test("SDMC", "Creating and deleting file", [&] { Test("SDMC", "Renaming directory", TestDirRename(sdmcArchive), true);
return TestFileCreateDelete(sdmcArchive); Test("SDMC", "Closing archive", FSUSER_CloseArchive(NULL, &sdmcArchive), 0L);
});
Test("SDMC", "Renaming file", [&] {
return TestFileRename(sdmcArchive);
});
Test("SDMC", "Writing and reading file", [&] {
return TestFileWriteRead(sdmcArchive);
});
Test("SDMC", "Creating and deleting directory", [&] {
return TestDirCreateDelete(sdmcArchive);
});
Test("SDMC", "Renaming directory", [&] {
return TestDirRename(sdmcArchive);
});
// Close SDMC
TestResult("SDMC", "Closing archive", [&]{
return FSUSER_CloseArchive(NULL, &sdmcArchive);
});
} }
} // namespace } // namespace

View File

@ -4,12 +4,7 @@
#include "output.h" #include "output.h"
void Test(std::string group, std::string name, std::function<bool (void)> test) void PrintSuccess(std::string group, std::string name, bool val)
{ {
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() ? "SUCCESS" : "FAILURE"); print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), val ? "SUCCESS" : "FAILURE");
}
void TestResult(std::string group, std::string name, std::function<int (void)> test)
{
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE");
} }

View File

@ -5,6 +5,11 @@
// If the condition fails, return false // If the condition fails, return false
#define SoftAssert(cond) do { if (!(cond)) { return false; } } while (0) #define SoftAssert(cond) do { if (!(cond)) { return false; } } while (0)
void Test(std::string group, std::string name, std::function<bool (void)> test); void PrintSuccess(std::string group, std::string name, bool val);
void TestResult(std::string group, std::string name, std::function<int (void)> test); template <typename T>
bool Test(std::string group, std::string name, T result, T expected)
{
PrintSuccess(group, name, result == expected);
return result == expected;
}