From 3f083e0e0e9cbeae177270fd53284cd11c5fb39f Mon Sep 17 00:00:00 2001 From: archshift Date: Wed, 10 Dec 2014 19:46:17 -0800 Subject: [PATCH] Make Test a template function for easy comparison with values. Also allows further logging and output in the future. --- source/tests/cpu/integer.cpp | 10 +++++----- source/tests/fs/fs.cpp | 8 ++------ source/tests/fs/fs_sdmc.cpp | 36 +++++++----------------------------- source/tests/test.cpp | 9 ++------- source/tests/test.h | 9 +++++++-- 5 files changed, 23 insertions(+), 49 deletions(-) diff --git a/source/tests/cpu/integer.cpp b/source/tests/cpu/integer.cpp index 58a5974..db1adfc 100644 --- a/source/tests/cpu/integer.cpp +++ b/source/tests/cpu/integer.cpp @@ -111,11 +111,11 @@ static bool Ssax() { void TestAll() { const std::string tag = "Integer"; - Test(tag, "ADD", &Add); - Test(tag, "SUB", &Sub); - Test(tag, "MUL", &Mul); - Test(tag, "SASX", &Sasx); - Test(tag, "SSAX", &Ssax); + Test(tag, "ADD", Add(), true); + Test(tag, "SUB", Sub(), true); + Test(tag, "MUL", Mul(), true); + Test(tag, "SASX", Sasx(), true); + Test(tag, "SSAX", Ssax(), true); } } diff --git a/source/tests/fs/fs.cpp b/source/tests/fs/fs.cpp index 667d399..3593245 100644 --- a/source/tests/fs/fs.cpp +++ b/source/tests/fs/fs.cpp @@ -8,15 +8,11 @@ namespace FS { void TestAll() { - TestResult("FS", "Initializing service", [&]{ - return fsInit(); - }); + Test("FS", "Initializing service", fsInit(), 0L); SDMC::TestAll(); - TestResult("FS", "Exiting service", [&]{ - return fsExit(); - }); + Test("FS", "Exiting service", fsExit(), 0L); } } // namespace diff --git a/source/tests/fs/fs_sdmc.cpp b/source/tests/fs/fs_sdmc.cpp index 9de2159..c09f1d1 100644 --- a/source/tests/fs/fs_sdmc.cpp +++ b/source/tests/fs/fs_sdmc.cpp @@ -145,35 +145,13 @@ void TestAll() { FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } }; - // Open SDMC - TestResult("SDMC", "Opening archive", [&]{ - return FSUSER_OpenArchive(NULL, &sdmcArchive); - }); - - Test("SDMC", "Creating and deleting file", [&] { - return TestFileCreateDelete(sdmcArchive); - }); - - 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); - }); + Test("SDMC", "Opening archive", FSUSER_OpenArchive(NULL, &sdmcArchive), 0L); + Test("SDMC", "Creating and deleting file", TestFileCreateDelete(sdmcArchive), true); + 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", "Renaming directory", TestDirRename(sdmcArchive), true); + Test("SDMC", "Closing archive", FSUSER_CloseArchive(NULL, &sdmcArchive), 0L); } } // namespace diff --git a/source/tests/test.cpp b/source/tests/test.cpp index 1a0f495..12817bb 100644 --- a/source/tests/test.cpp +++ b/source/tests/test.cpp @@ -4,12 +4,7 @@ #include "output.h" -void Test(std::string group, std::string name, std::function 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"); -} - -void TestResult(std::string group, std::string name, std::function test) -{ - print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE"); + print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), val ? "SUCCESS" : "FAILURE"); } diff --git a/source/tests/test.h b/source/tests/test.h index 6a4575e..0954cef 100644 --- a/source/tests/test.h +++ b/source/tests/test.h @@ -5,6 +5,11 @@ // If the condition fails, return false #define SoftAssert(cond) do { if (!(cond)) { return false; } } while (0) -void Test(std::string group, std::string name, std::function test); +void PrintSuccess(std::string group, std::string name, bool val); -void TestResult(std::string group, std::string name, std::function test); +template +bool Test(std::string group, std::string name, T result, T expected) +{ + PrintSuccess(group, name, result == expected); + return result == expected; +}