Merge pull request #21 from yuriks/ConnectToPort
Add ConnectToPort SVC test
This commit is contained in:
commit
c8c343955e
2
Makefile
2
Makefile
@ -19,7 +19,7 @@ include $(DEVKITARM)/3ds_rules
|
|||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
export TARGET := $(shell basename $(CURDIR))
|
export TARGET := $(shell basename $(CURDIR))
|
||||||
BUILD := build
|
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
|
DATA := data
|
||||||
INCLUDES := source #include
|
INCLUDES := source #include
|
||||||
|
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
#include "tests/test.h"
|
#include "tests/test.h"
|
||||||
#include "tests/fs/fs.h"
|
#include "tests/fs/fs.h"
|
||||||
#include "tests/cpu/cputests.h"
|
#include "tests/cpu/cputests.h"
|
||||||
|
#include "tests/kernel/kernel.h"
|
||||||
|
|
||||||
static unsigned int test_counter = 0;
|
static unsigned int test_counter = 0;
|
||||||
static TestCaller tests[] = {
|
static TestCaller tests[] = {
|
||||||
FS::TestAll,
|
FS::TestAll,
|
||||||
CPU::Integer::TestAll
|
CPU::Integer::TestAll,
|
||||||
|
Kernel::TestAll,
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
11
source/tests/kernel/kernel.cpp
Normal file
11
source/tests/kernel/kernel.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
namespace Ports { void TestAll(); }
|
||||||
|
|
||||||
|
void TestAll() {
|
||||||
|
Ports::TestAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
5
source/tests/kernel/kernel.h
Normal file
5
source/tests/kernel/kernel.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
void TestAll();
|
||||||
|
}
|
41
source/tests/kernel/ports.cpp
Normal file
41
source/tests/kernel/ports.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <memory>
|
||||||
|
#include <cstring>
|
||||||
|
#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
|
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
void SoftAssertLog(const std::string& function, int line, const std::string& condition)
|
void SoftAssertLog(const std::string& function, int line, const std::string& condition)
|
||||||
{
|
{
|
||||||
LogToFile(Common::FormatString("SOFTASSERT FAILURE: `%s`\n", condition.c_str()));
|
Log(GFX_TOP, 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(" At `%s` L%i\n", function.c_str(), line));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintSuccess(const std::string& group, const std::string& name, bool val)
|
void PrintSuccess(const std::string& group, const std::string& name, bool val)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
typedef void (*TestCaller)(void);
|
typedef void (*TestCaller)(void);
|
||||||
|
|
||||||
@ -15,6 +16,18 @@ void SoftAssertLog(const std::string& function, int line, const std::string& con
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} 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);
|
void PrintSuccess(const std::string& group, const std::string& name, bool val);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user