diff --git a/Makefile b/Makefile index 9cc97b3..61f45d3 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ include $(DEVKITARM)/3ds_rules #--------------------------------------------------------------------------------- export TARGET := $(shell basename $(CURDIR)) BUILD := build -SOURCES := source source/common source/tests source/tests/fs source/tests/cpu +SOURCES := source source/common source/tests source/tests/fs source/tests/cpu source/tests/kernel DATA := data INCLUDES := source #include diff --git a/source/main.cpp b/source/main.cpp index 387e874..1b93973 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -4,11 +4,13 @@ #include "tests/test.h" #include "tests/fs/fs.h" #include "tests/cpu/cputests.h" +#include "tests/kernel/kernel.h" static unsigned int test_counter = 0; static TestCaller tests[] = { FS::TestAll, - CPU::Integer::TestAll + CPU::Integer::TestAll, + Kernel::TestAll, }; int main(int argc, char** argv) diff --git a/source/tests/kernel/kernel.cpp b/source/tests/kernel/kernel.cpp new file mode 100644 index 0000000..09e9f78 --- /dev/null +++ b/source/tests/kernel/kernel.cpp @@ -0,0 +1,11 @@ +#include "kernel.h" + +namespace Kernel { + +namespace Ports { void TestAll(); } + +void TestAll() { + Ports::TestAll(); +} + +} // namespace diff --git a/source/tests/kernel/kernel.h b/source/tests/kernel/kernel.h new file mode 100644 index 0000000..f3302ff --- /dev/null +++ b/source/tests/kernel/kernel.h @@ -0,0 +1,5 @@ +#pragma once + +namespace Kernel { + void TestAll(); +} diff --git a/source/tests/kernel/ports.cpp b/source/tests/kernel/ports.cpp new file mode 100644 index 0000000..f028f4e --- /dev/null +++ b/source/tests/kernel/ports.cpp @@ -0,0 +1,41 @@ +#include +#include +#include <3ds.h> + +#include "common/scope_exit.h" +#include "tests/test.h" + +namespace Kernel { +namespace Ports { + +static bool Test_ConnectToPort() { + const Result ERR_NOT_FOUND = 0xD88007FA; + const Result ERR_PORT_NAME_TOO_LONG = 0xE0E0181E; + Handle handle; + + // Test for correct Result codes in various situations + // NULL port name + TestEquals(svcConnectToPort(&handle, nullptr), ERR_UNKNOWN_PORT); + // empty port name + TestEquals(svcConnectToPort(&handle, ""), ERR_UNKNOWN_PORT); + // port name too long + TestEquals(svcConnectToPort(&handle, "SuperExtremelyUltraMegaVeryLongString"), ERR_PORT_NAME_TOO_LONG); + TestEquals(svcConnectToPort(&handle, "0123456789A"), ERR_UNKNOWN_PORT); // Just right (11 characters) + TestEquals(svcConnectToPort(&handle, "0123456789AB"), ERR_PORT_NAME_TOO_LONG); // too long + // non-registered port name + TestEquals(svcConnectToPort(&handle, "xyz:"), ERR_UNKNOWN_PORT); + // connecting to srv services using ConnectToPort should fail + TestEquals(svcConnectToPort(&handle, "APT:U"), ERR_UNKNOWN_PORT); + + // Connecting to "srv:" should succeed + TestEquals(svcConnectToPort(&handle, "srv:"), 0); + + return true; +} + +void TestAll() { + Test("Kernel::Ports", "ConnectToPort", Test_ConnectToPort(), true); +} + +} // namespace +} // namespace diff --git a/source/tests/test.cpp b/source/tests/test.cpp index 03df339..afab5e5 100644 --- a/source/tests/test.cpp +++ b/source/tests/test.cpp @@ -7,8 +7,8 @@ void SoftAssertLog(const std::string& function, int line, const std::string& condition) { - LogToFile(Common::FormatString("SOFTASSERT FAILURE: `%s`\n", condition.c_str())); - LogToFile(Common::FormatString(" At `%s` L%i\n", function.c_str(), line)); + Log(GFX_TOP, Common::FormatString("SOFTASSERT FAILURE: `%s`\n", condition.c_str())); + Log(GFX_TOP, Common::FormatString(" At `%s` L%i\n", function.c_str(), line)); } void PrintSuccess(const std::string& group, const std::string& name, bool val) diff --git a/source/tests/test.h b/source/tests/test.h index e0e1080..ee9600e 100644 --- a/source/tests/test.h +++ b/source/tests/test.h @@ -1,6 +1,7 @@ #pragma once #include +#include typedef void (*TestCaller)(void); @@ -15,6 +16,18 @@ void SoftAssertLog(const std::string& function, int line, const std::string& con } \ } while (0) +#define TestEquals(actual, expected) \ + do { \ + auto var_actual = (actual); \ + auto var_expected = (expected); \ + if (!(var_actual == var_expected)) { \ + std::ostringstream ss; \ + ss << std::hex << #actual << "\nexpected [" << var_expected << "]\ngot [" << var_actual << "]"; \ + SoftAssertLog(__PRETTY_FUNCTION__, __LINE__, ss.str()); \ + return false; \ + } \ + } while (0) + void PrintSuccess(const std::string& group, const std::string& name, bool val); template