Merge pull request #21 from yuriks/ConnectToPort

Add ConnectToPort SVC test
This commit is contained in:
bunnei 2015-01-30 13:56:36 -05:00
commit c8c343955e
7 changed files with 76 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,11 @@
#include "kernel.h"
namespace Kernel {
namespace Ports { void TestAll(); }
void TestAll() {
Ports::TestAll();
}
} // namespace

View File

@ -0,0 +1,5 @@
#pragma once
namespace Kernel {
void TestAll();
}

View 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

View File

@ -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)

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <sstream>
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 <typename T>