Bemanitools v5.26 release
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
testexes += cconfig-test
|
||||
|
||||
srcdir_cconfig-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-test := \
|
||||
cconfig-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += cconfig-util-test
|
||||
|
||||
srcdir_cconfig-util-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-util-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-util-test := \
|
||||
cconfig-util-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += cconfig-cmd-test
|
||||
|
||||
srcdir_cconfig-cmd-test := src/test/cconfig
|
||||
|
||||
libs_cconfig-cmd-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_cconfig-cmd-test := \
|
||||
cconfig-cmd-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "cconfig/cmd.h"
|
||||
#include "cconfig/cconfig-util.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_cmd()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int argc = 6;
|
||||
char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"};
|
||||
char str[32];
|
||||
int32_t val;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_true(cconfig_cmd_parse(config, "-P", argc, argv, true));
|
||||
|
||||
check_int_eq(config->nentries, 2);
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1"));
|
||||
check_str_eq(str, "aaa");
|
||||
|
||||
check_bool_true(cconfig_util_get_int(config, "test2", &val, 0));
|
||||
check_int_eq(val, 123);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_cmd_absent_entries()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int argc = 6;
|
||||
char* argv[] = {"-P", "test=aaa", "-C", "asdf", "-P", "test2=123"};
|
||||
char str[32];
|
||||
int32_t val;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set2(config, "test", "aaa");
|
||||
|
||||
check_bool_true(cconfig_cmd_parse(config, "-P", argc, argv, false));
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", str, sizeof(str), "1"));
|
||||
check_str_eq(str, "aaa");
|
||||
|
||||
check_bool_false(cconfig_util_get_int(config, "test2", &val, 0));
|
||||
check_int_eq(val, 0);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig-cmd")
|
||||
TEST_MODULE_TEST(test_cmd)
|
||||
TEST_MODULE_TEST(test_cmd_absent_entries)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,156 @@
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_init()
|
||||
{
|
||||
struct cconfig* config;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_empty()
|
||||
{
|
||||
struct cconfig* config;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_null(cconfig_get(config, "test"));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_one_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set(config, "test", "123", "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "123");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "desc");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_one_elem2()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set2(config, "test", "123");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "123");
|
||||
check_str_eq(config->entries[0].desc, "");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_same_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_set(config, "test", "123", "desc");
|
||||
cconfig_set(config, "test", "12345", "aaa");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "12345");
|
||||
check_str_eq(config->entries[0].desc, "aaa");
|
||||
|
||||
entry = cconfig_get(config, "test");
|
||||
|
||||
check_str_eq(entry->key, "test");
|
||||
check_str_eq(entry->value, "12345");
|
||||
check_str_eq(entry->desc, "aaa");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_many_elem()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct cconfig_entry* entry;
|
||||
char key[16];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
cconfig_set(config, key, "123", "desc");
|
||||
}
|
||||
|
||||
check_int_eq(config->nentries, 1000);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
check_str_eq(config->entries[i].key, key);
|
||||
check_str_eq(config->entries[i].value, "123");
|
||||
check_str_eq(config->entries[i].desc, "desc");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sprintf(key, "%d", i);
|
||||
entry = cconfig_get(config, key);
|
||||
|
||||
check_str_eq(entry->key, key);
|
||||
check_str_eq(entry->value, "123");
|
||||
check_str_eq(entry->desc, "desc");
|
||||
}
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig")
|
||||
TEST_MODULE_TEST(test_init)
|
||||
TEST_MODULE_TEST(test_get_empty)
|
||||
TEST_MODULE_TEST(test_set_get_one_elem)
|
||||
TEST_MODULE_TEST(test_set_get_one_elem2)
|
||||
TEST_MODULE_TEST(test_set_get_same_elem)
|
||||
TEST_MODULE_TEST(test_set_get_many_elem)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,220 @@
|
||||
#include "cconfig/cconfig-util.h"
|
||||
#include "cconfig/cconfig.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_set_get_int()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int32_t value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_int(config, "test", 12345, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].value, "12345");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_int(config, "test", &value, 0));
|
||||
check_int_eq(value, 12345);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_int_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
int32_t value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_int(config, "test", &value, 123));
|
||||
check_int_eq(value, 123);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_float()
|
||||
{
|
||||
struct cconfig* config;
|
||||
float value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_float(config, "test", 100.5f, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_float(config, "test", &value, 0));
|
||||
check_float_eq(value, 100.5f, 0.1f);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_float_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
float value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_float(config, "test", &value, 115.9f));
|
||||
check_float_eq(value, 115.9f, 0.1f);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_bool()
|
||||
{
|
||||
struct cconfig* config;
|
||||
bool value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_bool(config, "test", true, "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_bool(config, "test", &value, 0));
|
||||
check_bool_true(value);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_bool_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
bool value;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_bool(config, "test", &value, true));
|
||||
check_bool_true(value);
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_str()
|
||||
{
|
||||
struct cconfig* config;
|
||||
char value[1024];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
cconfig_util_set_str(config, "test", "hello world", "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_str(config, "test", value, sizeof(value),
|
||||
"world hello"));
|
||||
check_str_eq(value, "hello world");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_str_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
char value[1024];
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_str(config, "test", value, sizeof(value),
|
||||
"world hello"));
|
||||
check_str_eq(value, "world hello");
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_set_get_data()
|
||||
{
|
||||
struct cconfig* config;
|
||||
uint8_t value[1024];
|
||||
uint8_t value2[1024];
|
||||
uint8_t value_default[] = {0x00};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
for (int i = 0; i < sizeof(value); i++) {
|
||||
value[i] = (uint8_t) i;
|
||||
}
|
||||
|
||||
cconfig_util_set_data(config, "test", value, sizeof(value), "desc");
|
||||
|
||||
check_int_eq(config->nentries, 1);
|
||||
check_str_eq(config->entries[0].key, "test");
|
||||
check_str_eq(config->entries[0].desc, "desc");
|
||||
|
||||
check_bool_true(cconfig_util_get_data(config, "test", value2, sizeof(value2),
|
||||
value_default));
|
||||
check_data_eq(value2, sizeof(value2), value, sizeof(value));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
static void test_get_data_na()
|
||||
{
|
||||
struct cconfig* config;
|
||||
uint8_t value[1024];
|
||||
uint8_t value_default[] = {0x01};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
check_int_eq(config->nentries, 0);
|
||||
check_null(config->entries);
|
||||
|
||||
check_bool_false(cconfig_util_get_data(config, "test", value, sizeof(value),
|
||||
value_default));
|
||||
check_data_eq(value, 1, value_default, sizeof(value_default));
|
||||
|
||||
cconfig_finit(config);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("cconfig-util")
|
||||
TEST_MODULE_TEST(test_set_get_int)
|
||||
TEST_MODULE_TEST(test_get_int_na)
|
||||
TEST_MODULE_TEST(test_set_get_float)
|
||||
TEST_MODULE_TEST(test_get_float_na)
|
||||
TEST_MODULE_TEST(test_set_get_bool)
|
||||
TEST_MODULE_TEST(test_get_bool_na)
|
||||
TEST_MODULE_TEST(test_set_get_str)
|
||||
TEST_MODULE_TEST(test_get_str_na)
|
||||
TEST_MODULE_TEST(test_set_get_data)
|
||||
TEST_MODULE_TEST(test_get_data_na)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,66 @@
|
||||
testexes += iidxhook-util-config-eamuse-test
|
||||
|
||||
srcdir_iidxhook-util-config-eamuse-test := src/test/iidxhook-util
|
||||
|
||||
ldflags_iidxhook-util-config-eamuse-test := \
|
||||
-lws2_32 \
|
||||
|
||||
libs_iidxhook-util-config-eamuse-test := \
|
||||
security \
|
||||
iidxhook-util \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-util-config-eamuse-test := \
|
||||
iidxhook-util-config-eamuse-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += iidxhook-util-config-gfx-test
|
||||
|
||||
srcdir_iidxhook-util-config-gfx-test := src/test/iidxhook-util
|
||||
|
||||
libs_iidxhook-util-config-gfx-test := \
|
||||
security \
|
||||
iidxhook-util \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-util-config-gfx-test := \
|
||||
iidxhook-util-config-gfx-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += iidxhook-util-config-misc-test
|
||||
|
||||
srcdir_iidxhook-util-config-misc-test := src/test/iidxhook-util
|
||||
|
||||
libs_iidxhook-util-config-misc-test := \
|
||||
security \
|
||||
iidxhook-util \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-util-config-misc-test := \
|
||||
iidxhook-util-config-misc-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += iidxhook-util-config-sec-test
|
||||
|
||||
srcdir_iidxhook-util-config-sec-test := src/test/iidxhook-util
|
||||
|
||||
libs_iidxhook-util-config-sec-test := \
|
||||
security \
|
||||
iidxhook-util \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-util-config-sec-test := \
|
||||
iidxhook-util-config-sec-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,86 @@
|
||||
#include "iidxhook-util/config-eamuse.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering
|
||||
the tests */
|
||||
|
||||
static void test_config_eamuse_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_util_config_eamuse config_eamuse;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_util_config_eamuse_init(config);
|
||||
iidxhook_util_config_eamuse_get(&config_eamuse, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(config_eamuse.card_type, "C02");
|
||||
check_str_eq(net_addr_to_str(&config_eamuse.server), "localhost:80");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.pcbid, false),
|
||||
"0101020304050607086F");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.eamid, false),
|
||||
"0101020304050607086F");
|
||||
}
|
||||
|
||||
static void test_config_eamuse()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_util_config_eamuse config_eamuse;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_util_config_eamuse_init(config);
|
||||
|
||||
cconfig_set2(config, "eamuse.card_type", "D01");
|
||||
cconfig_set2(config, "eamuse.server", "http://myServer.com/legacy");
|
||||
cconfig_set2(config, "eamuse.pcbid", "0101020304050607086F");
|
||||
cconfig_set2(config, "eamuse.eamid", "0101020304050607086F");
|
||||
|
||||
iidxhook_util_config_eamuse_get(&config_eamuse, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(config_eamuse.card_type, "D01");
|
||||
check_str_eq(net_addr_to_str(&config_eamuse.server),
|
||||
"http://myServer.com/legacy");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.pcbid, false),
|
||||
"0101020304050607086F");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.eamid, false),
|
||||
"0101020304050607086F");
|
||||
}
|
||||
|
||||
static void test_config_eamuse_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_util_config_eamuse config_eamuse;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_util_config_eamuse_init(config);
|
||||
|
||||
cconfig_set2(config, "eamuse.card_type", "XXXX");
|
||||
cconfig_set2(config, "eamuse.server", "asdf");
|
||||
cconfig_set2(config, "eamuse.pcbid", "00000000000000000000");
|
||||
cconfig_set2(config, "eamuse.eamid", "00000000000000000000");
|
||||
|
||||
iidxhook_util_config_eamuse_get(&config_eamuse, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(config_eamuse.card_type, "C02");
|
||||
check_str_eq(net_addr_to_str(&config_eamuse.server), "asdf");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.pcbid, false),
|
||||
"00000000000000000000");
|
||||
check_str_eq(security_id_to_str(&config_eamuse.eamid, false),
|
||||
"00000000000000000000");
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-eamuse")
|
||||
TEST_MODULE_TEST(test_config_eamuse_defaults)
|
||||
TEST_MODULE_TEST(test_config_eamuse)
|
||||
TEST_MODULE_TEST(test_config_eamuse_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,107 @@
|
||||
#include "iidxhook-util/config-gfx.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering
|
||||
the tests */
|
||||
|
||||
static void test_config_gfx_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_gfx config_gfx;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_gfx_init(config);
|
||||
iidxhook_config_gfx_get(&config_gfx, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_gfx.bgvideo_uv_fix);
|
||||
check_bool_false(config_gfx.framed);
|
||||
check_float_eq(config_gfx.frame_rate_limit, 0.0f, 0.1f);
|
||||
check_float_eq(config_gfx.monitor_check, -1.0f, 0.1f);
|
||||
check_int_eq(config_gfx.pci_id_vid, 0x1002);
|
||||
check_int_eq(config_gfx.pci_id_pid, 0x7146);
|
||||
check_bool_false(config_gfx.windowed);
|
||||
check_int_eq(config_gfx.scale_back_buffer_width, 0);
|
||||
check_int_eq(config_gfx.scale_back_buffer_height, 0);
|
||||
check_int_eq(config_gfx.scale_back_buffer_width, D3D9_BACK_BUFFER_SCALE_FILTER_NONE);
|
||||
}
|
||||
|
||||
static void test_config_gfx()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_gfx config_gfx;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_gfx_init(config);
|
||||
|
||||
cconfig_set2(config, "gfx.bgvideo_uv_fix", "true");
|
||||
cconfig_set2(config, "gfx.framed", "true");
|
||||
cconfig_set2(config, "gfx.frame_rate_limit", "60.04");
|
||||
cconfig_set2(config, "gfx.monitor_check", "59.999");
|
||||
cconfig_set2(config, "gfx.pci_id", "1111:1234");
|
||||
cconfig_set2(config, "gfx.windowed", "true");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_width", "1920");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_height", "1080");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_filter", "linear");
|
||||
|
||||
iidxhook_config_gfx_get(&config_gfx, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_gfx.bgvideo_uv_fix);
|
||||
check_bool_true(config_gfx.framed);
|
||||
check_float_eq(config_gfx.frame_rate_limit, 60.04f, 0.1f);
|
||||
check_float_eq(config_gfx.monitor_check, 59.999f, 0.001f);
|
||||
check_int_eq(config_gfx.pci_id_vid, 0x1111);
|
||||
check_int_eq(config_gfx.pci_id_pid, 0x1234);
|
||||
check_bool_true(config_gfx.windowed);
|
||||
check_int_eq(config_gfx.scale_back_buffer_width, 1920);
|
||||
check_int_eq(config_gfx.scale_back_buffer_height, 1080);
|
||||
check_int_eq(config_gfx.scale_back_buffer_filter, D3D9_BACK_BUFFER_SCALE_FILTER_LINEAR);
|
||||
}
|
||||
|
||||
static void test_config_gfx_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_gfx config_gfx;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_gfx_init(config);
|
||||
|
||||
cconfig_set2(config, "gfx.bgvideo_uv_fix", "123");
|
||||
cconfig_set2(config, "gfx.framed", "aaa");
|
||||
cconfig_set2(config, "gfx.frame_rate_limit", "-1.0f");
|
||||
cconfig_set2(config, "gfx.monitor_check", "asdf");
|
||||
cconfig_set2(config, "gfx.pci_id", "11111234");
|
||||
cconfig_set2(config, "gfx.windowed", "-5");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_width", "asdf");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_height", "");
|
||||
cconfig_set2(config, "gfx.scale_back_buffer_filter", "ffff");
|
||||
|
||||
iidxhook_config_gfx_get(&config_gfx, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_gfx.bgvideo_uv_fix);
|
||||
check_bool_false(config_gfx.framed);
|
||||
check_float_eq(config_gfx.frame_rate_limit, 0.0f, 0.1f);
|
||||
check_float_eq(config_gfx.monitor_check, -1.0f, 0.1f);
|
||||
check_int_eq(config_gfx.pci_id_vid, 0x1002);
|
||||
check_int_eq(config_gfx.pci_id_pid, 0x7146);
|
||||
check_bool_false(config_gfx.windowed);
|
||||
check_int_eq(config_gfx.scale_back_buffer_width, 0);
|
||||
check_int_eq(config_gfx.scale_back_buffer_height, 0);
|
||||
check_int_eq(config_gfx.scale_back_buffer_width, D3D9_BACK_BUFFER_SCALE_FILTER_NONE);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-gfx")
|
||||
TEST_MODULE_TEST(test_config_gfx_defaults)
|
||||
TEST_MODULE_TEST(test_config_gfx)
|
||||
TEST_MODULE_TEST(test_config_gfx_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "iidxhook-util/config-misc.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_misc_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_misc config_misc;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_misc_init(config);
|
||||
iidxhook_config_misc_get(&config_misc, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_misc.disable_clock_set);
|
||||
check_bool_false(config_misc.rteffect_stub);
|
||||
}
|
||||
|
||||
static void test_config_misc()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_misc config_misc;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_misc_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.disable_clock_set", "true");
|
||||
cconfig_set2(config, "misc.rteffect_stub", "true");
|
||||
|
||||
iidxhook_config_misc_get(&config_misc, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_misc.disable_clock_set);
|
||||
check_bool_true(config_misc.rteffect_stub);
|
||||
}
|
||||
|
||||
static void test_config_misc_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_misc config_misc;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_misc_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.disable_clock_set", "asdf");
|
||||
cconfig_set2(config, "misc.rteffect_stub", "222");
|
||||
|
||||
iidxhook_config_misc_get(&config_misc, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_misc.disable_clock_set);
|
||||
check_bool_false(config_misc.rteffect_stub);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-misc")
|
||||
TEST_MODULE_TEST(test_config_misc_defaults)
|
||||
TEST_MODULE_TEST(test_config_misc)
|
||||
TEST_MODULE_TEST(test_config_misc_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "iidxhook-util/config-sec.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_sec_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_sec config_sec;
|
||||
const uint32_t boot_seeds[3] = {0, 0, 0};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_sec_init(config);
|
||||
iidxhook_config_sec_get(&config_sec, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(security_mcode_to_str(&config_sec.boot_version), "GEC02 ");
|
||||
check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds),
|
||||
(void*) boot_seeds, sizeof(boot_seeds));
|
||||
check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode),
|
||||
"GQC02JAA");
|
||||
}
|
||||
|
||||
static void test_config_sec()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_sec config_sec;
|
||||
const uint32_t boot_seeds[3] = {1, 1, 1};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_sec_init(config);
|
||||
|
||||
cconfig_set2(config, "sec.boot_version", "ASDFG ");
|
||||
cconfig_set2(config, "sec.boot_seeds", "1:1:1");
|
||||
cconfig_set2(config, "sec.black_plug_mcode", "GQD01JAB");
|
||||
|
||||
iidxhook_config_sec_get(&config_sec, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(security_mcode_to_str(&config_sec.boot_version), "ASDFG ");
|
||||
check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds),
|
||||
(void*) boot_seeds, sizeof(boot_seeds));
|
||||
check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode),
|
||||
"GQD01JAB");
|
||||
}
|
||||
|
||||
static void test_config_sec_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_sec config_sec;
|
||||
const uint32_t boot_seeds[3] = {0, 0, 0};
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_sec_init(config);
|
||||
|
||||
cconfig_set2(config, "sec.boot_version", "ASDFG1234");
|
||||
cconfig_set2(config, "sec.boot_seeds", "1:11");
|
||||
cconfig_set2(config, "sec.black_plug_mcode", "GQD01JABA");
|
||||
|
||||
iidxhook_config_sec_get(&config_sec, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_str_eq(security_mcode_to_str(&config_sec.boot_version), "GEC02 ");
|
||||
check_data_eq(config_sec.boot_seeds, sizeof(config_sec.boot_seeds),
|
||||
(void*) boot_seeds, sizeof(boot_seeds));
|
||||
check_str_eq(security_mcode_to_str(&config_sec.black_plug_mcode),
|
||||
"GQC02JAA");
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-sec")
|
||||
TEST_MODULE_TEST(test_config_sec_defaults)
|
||||
TEST_MODULE_TEST(test_config_sec)
|
||||
TEST_MODULE_TEST(test_config_sec_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,29 @@
|
||||
testexes += iidxhook-config-iidxhook1-test
|
||||
|
||||
srcdir_iidxhook-config-iidxhook1-test := src/test/iidxhook
|
||||
|
||||
libs_iidxhook-config-iidxhook1-test := \
|
||||
cconfig \
|
||||
iidxhook1 \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-config-iidxhook1-test := \
|
||||
iidxhook-config-iidxhook1-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += iidxhook-config-iidxhook2-test
|
||||
|
||||
srcdir_iidxhook-config-iidxhook2-test := src/test/iidxhook
|
||||
|
||||
libs_iidxhook-config-iidxhook2-test := \
|
||||
iidxhook2 \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook-config-iidxhook2-test := \
|
||||
iidxhook-config-iidxhook2-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "iidxhook1/config-iidxhook1.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_iidxhook1_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook1 config_iidxhook1;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook1_init(config);
|
||||
iidxhook_config_iidxhook1_get(&config_iidxhook1, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_iidxhook1.happy_sky_ms_bg_fix);
|
||||
check_bool_false(config_iidxhook1.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
static void test_config_iidxhook1()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook1 config_iidxhook1;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook1_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.happy_sky_ms_bg_fix", "true");
|
||||
cconfig_set2(config, "misc.use_d3d9_hooks", "true");
|
||||
|
||||
iidxhook_config_iidxhook1_get(&config_iidxhook1, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_iidxhook1.happy_sky_ms_bg_fix);
|
||||
check_bool_true(config_iidxhook1.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
static void test_config_iidxhook1_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook1 config_iidxhook1;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook1_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.happy_sky_ms_bg_fix", "123");
|
||||
cconfig_set2(config, "misc.use_d3d9_hooks", "sss");
|
||||
|
||||
iidxhook_config_iidxhook1_get(&config_iidxhook1, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_iidxhook1.happy_sky_ms_bg_fix);
|
||||
check_bool_false(config_iidxhook1.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-iidxhook1")
|
||||
TEST_MODULE_TEST(test_config_iidxhook1_defaults)
|
||||
TEST_MODULE_TEST(test_config_iidxhook1)
|
||||
TEST_MODULE_TEST(test_config_iidxhook1_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "iidxhook2/config-iidxhook2.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_iidxhook2_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook2 config_iidxhook2;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook2_init(config);
|
||||
iidxhook_config_iidxhook2_get(&config_iidxhook2, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_iidxhook2.distorted_ms_bg_fix);
|
||||
check_bool_false(config_iidxhook2.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
static void test_config_iidxhook2()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook2 config_iidxhook2;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook2_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.distorted_ms_bg_fix", "true");
|
||||
cconfig_set2(config, "misc.use_d3d9_hooks", "true");
|
||||
|
||||
iidxhook_config_iidxhook2_get(&config_iidxhook2, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_iidxhook2.distorted_ms_bg_fix);
|
||||
check_bool_true(config_iidxhook2.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
static void test_config_iidxhook2_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook_config_iidxhook2 config_iidxhook2;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook_config_iidxhook2_init(config);
|
||||
|
||||
cconfig_set2(config, "misc.distorted_ms_bg_fix", "123");
|
||||
cconfig_set2(config, "misc.use_d3d9_hooks", "sss");
|
||||
|
||||
iidxhook_config_iidxhook2_get(&config_iidxhook2, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_iidxhook2.distorted_ms_bg_fix);
|
||||
check_bool_false(config_iidxhook2.use_d3d9_hooks);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook-config-iidxhook2")
|
||||
TEST_MODULE_TEST(test_config_iidxhook2_defaults)
|
||||
TEST_MODULE_TEST(test_config_iidxhook2)
|
||||
TEST_MODULE_TEST(test_config_iidxhook2_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,27 @@
|
||||
testexes += iidxhook8-config-cam-test
|
||||
|
||||
srcdir_iidxhook8-config-cam-test := src/test/iidxhook8
|
||||
|
||||
libs_iidxhook8-config-cam-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook8-config-cam-test := \
|
||||
iidxhook8-config-cam-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += iidxhook8-config-io-test
|
||||
|
||||
srcdir_iidxhook8-config-io-test := src/test/iidxhook8
|
||||
|
||||
libs_iidxhook8-config-io-test := \
|
||||
cconfig \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_iidxhook8-config-io-test := \
|
||||
iidxhook8-config-io-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "iidxhook8/config-cam.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_cam_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_cam config_cam;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_cam_init(config);
|
||||
iidxhook8_config_cam_get(&config_cam, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_cam.disable_emu);
|
||||
check_str_eq(config_cam.device_id1, "");
|
||||
check_str_eq(config_cam.device_id2, "");
|
||||
}
|
||||
|
||||
static void test_config_cam()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_cam config_cam;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_cam_init(config);
|
||||
|
||||
cconfig_set2(config, "cam.disable_emu", "true");
|
||||
cconfig_set2(config, "cam.device_id1", "asdjkasd");
|
||||
cconfig_set2(config, "cam.device_id2", "1234");
|
||||
|
||||
iidxhook8_config_cam_get(&config_cam, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_cam.disable_emu);
|
||||
check_str_eq(config_cam.device_id1, "asdjkasd");
|
||||
check_str_eq(config_cam.device_id2, "1234");
|
||||
}
|
||||
|
||||
static void test_config_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_cam config_cam;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_cam_init(config);
|
||||
|
||||
cconfig_set2(config, "cam.disable_emu", "123");
|
||||
cconfig_set2(config, "cam.device_id1", "asdjkasd");
|
||||
cconfig_set2(config, "cam.device_id2", "1234");
|
||||
|
||||
iidxhook8_config_cam_get(&config_cam, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_fakse(config_cam.disable_emu);
|
||||
check_str_eq(config_cam.device_id1, "asdjkasd");
|
||||
check_str_eq(config_cam.device_id2, "1234");
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook8-config-cam")
|
||||
TEST_MODULE_TEST(test_config_cam_defaults)
|
||||
TEST_MODULE_TEST(test_config_cam)
|
||||
TEST_MODULE_TEST(test_config_cam_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "iidxhook8/config-io.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
/* We don't care about cleaning up some of the memory to avoid cluttering the tests */
|
||||
|
||||
static void test_config_io_defaults()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_io config_io;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_io_init(config);
|
||||
iidxhook8_config_io_get(&config_io, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_io.disable_card_reader_emu);
|
||||
check_bool_false(config_io.disable_bio2_emu);
|
||||
check_bool_false(config_io.disable_poll_limiter);
|
||||
}
|
||||
|
||||
static void test_config_io()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_io config_io;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_io_init(config);
|
||||
|
||||
cconfig_set2(config, "io.disable_card_reader_emu", "true");
|
||||
cconfig_set2(config, "io.disable_bio2_emu", "true");
|
||||
cconfig_set2(config, "io.disable_poll_limiter", "true");
|
||||
|
||||
iidxhook8_config_io_get(&config_io, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_true(config_io.disable_card_reader_emu);
|
||||
check_bool_true(config_io.disable_bio2_emu);
|
||||
check_bool_true(config_io.disable_poll_limiter);
|
||||
}
|
||||
|
||||
static void test_config_invalid_values()
|
||||
{
|
||||
struct cconfig* config;
|
||||
struct iidxhook8_config_io config_io;
|
||||
|
||||
config = cconfig_init();
|
||||
|
||||
iidxhook8_config_io_init(config);
|
||||
|
||||
cconfig_set2(config, "io.disable_card_reader_emu", "asdf");
|
||||
cconfig_set2(config, "io.disable_bio2_emu", "123");
|
||||
cconfig_set2(config, "io.disable_poll_limiter", "");
|
||||
|
||||
iidxhook8_config_io_get(&config_io, config);
|
||||
|
||||
cconfig_finit(config);
|
||||
|
||||
check_bool_false(config_io.disable_card_reader_emu);
|
||||
check_bool_false(config_io.disable_bio2_emu);
|
||||
check_bool_false(config_io.disable_poll_limiter);
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("iidxhook8-config-io")
|
||||
TEST_MODULE_TEST(test_config_io_defaults)
|
||||
TEST_MODULE_TEST(test_config_io)
|
||||
TEST_MODULE_TEST(test_config_io_invalid_values)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,83 @@
|
||||
testexes += security-id-test
|
||||
|
||||
srcdir_security-id-test := src/test/security
|
||||
|
||||
libs_security-id-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-id-test := \
|
||||
security-id-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += security-mcode-test
|
||||
|
||||
srcdir_security-mcode-test := src/test/security
|
||||
|
||||
libs_security-mcode-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-mcode-test := \
|
||||
security-mcode-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += security-util-test
|
||||
|
||||
srcdir_security-util-test := src/test/security
|
||||
|
||||
libs_security-util-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-util-test := \
|
||||
security-util-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += security-rp-test
|
||||
|
||||
srcdir_security-rp-test := src/test/security
|
||||
|
||||
libs_security-rp-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-rp-test := \
|
||||
security-rp-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += security-rp2-test
|
||||
|
||||
srcdir_security-rp2-test := src/test/security
|
||||
|
||||
libs_security-rp2-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-rp2-test := \
|
||||
security-rp2-test.c \
|
||||
|
||||
################################################################################
|
||||
|
||||
testexes += security-rp3-test
|
||||
|
||||
srcdir_security-rp3-test := src/test/security
|
||||
|
||||
libs_security-rp3-test := \
|
||||
security \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_security-rp3-test := \
|
||||
security-rp3-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "security/id.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_to_str()
|
||||
{
|
||||
check_str_eq(security_id_to_str(&security_id_default, false),
|
||||
"0101020304050607086F");
|
||||
check_str_eq(security_id_to_str(&security_id_default, true),
|
||||
"0102030405060708");
|
||||
}
|
||||
|
||||
static void test_parse_valid()
|
||||
{
|
||||
struct security_id id;
|
||||
|
||||
check_bool_true(security_id_parse("0101020304050607086F", &id));
|
||||
check_bool_true(security_id_verify(&id));
|
||||
}
|
||||
|
||||
static void test_parse_invalid()
|
||||
{
|
||||
struct security_id id;
|
||||
|
||||
check_bool_true(security_id_parse("0102030405060708", &id));
|
||||
check_bool_false(security_id_verify(&id));
|
||||
|
||||
check_bool_true(security_id_parse("010102030405060708FF", &id));
|
||||
check_bool_false(security_id_verify(&id));
|
||||
|
||||
check_bool_false(security_id_parse("asdf", &id));
|
||||
}
|
||||
|
||||
static void test_prepare_and_verify()
|
||||
{
|
||||
struct security_id id;
|
||||
|
||||
check_bool_true(security_id_parse("01AB50E2DC4F832A9A78", &id));
|
||||
check_bool_true(security_id_verify(&id));
|
||||
}
|
||||
|
||||
static void test_prepare_and_verify_invalid()
|
||||
{
|
||||
struct security_id id;
|
||||
|
||||
check_bool_true(security_id_parse("01AB50E2DC4F832A9A79", &id));
|
||||
check_bool_false(security_id_verify(&id));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-id")
|
||||
TEST_MODULE_TEST(test_to_str)
|
||||
TEST_MODULE_TEST(test_parse_valid)
|
||||
TEST_MODULE_TEST(test_parse_invalid)
|
||||
TEST_MODULE_TEST(test_prepare_and_verify)
|
||||
TEST_MODULE_TEST(test_prepare_and_verify_invalid)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "security/mcode.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static void test_parse_valid()
|
||||
{
|
||||
struct security_mcode mcode;
|
||||
|
||||
check_bool_true(security_mcode_parse("GQD01JAA", &mcode));
|
||||
check_char_eq(mcode.header, 'G');
|
||||
check_char_eq(mcode.unkn, 'Q');
|
||||
check_data_eq(mcode.game, sizeof(mcode.game), "D01", 3);
|
||||
check_char_eq(mcode.region, 'J');
|
||||
check_char_eq(mcode.cabinet, 'A');
|
||||
check_char_eq(mcode.revision, 'A');
|
||||
}
|
||||
|
||||
static void test_parse_valid_2()
|
||||
{
|
||||
struct security_mcode mcode;
|
||||
|
||||
check_bool_true(security_mcode_parse("GQD01", &mcode));
|
||||
check_char_eq(mcode.header, 'G');
|
||||
check_char_eq(mcode.unkn, 'Q');
|
||||
check_data_eq(mcode.game, sizeof(mcode.game), "D01", 3);
|
||||
check_char_eq(mcode.region, ' ');
|
||||
check_char_eq(mcode.cabinet, ' ');
|
||||
check_char_eq(mcode.revision, ' ');
|
||||
}
|
||||
|
||||
static void test_parse_invalid()
|
||||
{
|
||||
struct security_mcode mcode;
|
||||
|
||||
check_bool_false(security_mcode_parse("GQD01JAAA", &mcode));
|
||||
check_char_eq(mcode.header, ' ');
|
||||
check_char_eq(mcode.unkn, ' ');
|
||||
check_data_eq(mcode.game, sizeof(mcode.game), " ", 3);
|
||||
check_char_eq(mcode.region, ' ');
|
||||
check_char_eq(mcode.cabinet, ' ');
|
||||
check_char_eq(mcode.revision, ' ');
|
||||
}
|
||||
|
||||
static void test_to_str()
|
||||
{
|
||||
struct security_mcode mcode;
|
||||
mcode.header = 'G';
|
||||
mcode.unkn = 'Q';
|
||||
memcpy(mcode.game, "D01", 3);
|
||||
mcode.region = 'J';
|
||||
mcode.cabinet = 'A';
|
||||
mcode.revision = 'A';
|
||||
|
||||
check_str_eq(security_mcode_to_str(&mcode), "GQD01JAA");
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-mcode")
|
||||
TEST_MODULE_TEST(test_parse_valid)
|
||||
TEST_MODULE_TEST(test_parse_valid_2)
|
||||
TEST_MODULE_TEST(test_parse_invalid)
|
||||
TEST_MODULE_TEST(test_to_str)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,163 @@
|
||||
#include "security/id.h"
|
||||
#include "security/rp.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static const struct security_mcode boot_version_iidx_09_to_13 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_E,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_9,
|
||||
.region = SECURITY_MCODE_FIELD_BLANK,
|
||||
.cabinet = SECURITY_MCODE_FIELD_BLANK,
|
||||
.revision = SECURITY_MCODE_FIELD_BLANK,
|
||||
};
|
||||
|
||||
static const uint32_t boot_seeds_iidx_09[3] = {0, 0, 0};
|
||||
static const uint32_t boot_seeds_iidx_10[3] = {0, 1, 1};
|
||||
static const uint32_t boot_seeds_iidx_11[3] = {0, 2, 2};
|
||||
static const uint32_t boot_seeds_iidx_12[3] = {0, 3, 3};
|
||||
static const uint32_t boot_seeds_iidx_13[3] = {0, 4, 4};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_09 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_9,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_10 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_10,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_11 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_11,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_12 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_12,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_13 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_13,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_rp_eeprom exp_iidx_09_black_eeprom = {
|
||||
.signature = {0x07, 0x5D, 0x45, 0xCB, 0xDA, 0x19},
|
||||
.packed_payload = {0x86, 0x1A, 0x92, 0x42, 0x3C, 0x67},
|
||||
};
|
||||
|
||||
static const struct security_rp_eeprom exp_iidx_10_black_eeprom = {
|
||||
.signature = {0x10, 0x45, 0x30, 0x7D, 0x1C, 0x13},
|
||||
.packed_payload = {0x86, 0x1A, 0x91, 0x42, 0x4C, 0x67},
|
||||
};
|
||||
|
||||
static const struct security_rp_eeprom exp_iidx_11_black_eeprom = {
|
||||
.signature = {0xA2, 0x8B, 0x97, 0xA3, 0x3B, 0x23},
|
||||
.packed_payload = {0x86, 0x1A, 0x91, 0x46, 0x5C, 0x67},
|
||||
};
|
||||
|
||||
static const struct security_rp_eeprom exp_iidx_12_black_eeprom = {
|
||||
.signature = {0x1B, 0xC5, 0xF1, 0x02, 0xF0, 0xB8},
|
||||
.packed_payload = {0x86, 0x1A, 0xAF, 0x8E, 0x5C, 0x67},
|
||||
};
|
||||
|
||||
static const struct security_rp_eeprom exp_iidx_13_black_eeprom = {
|
||||
.signature = {0x37, 0xCE, 0x49, 0x54, 0x20, 0x83},
|
||||
.packed_payload = {0x86, 0x1A, 0xA4, 0x92, 0x6C, 0x67},
|
||||
};
|
||||
|
||||
static void test_encode_iidx_09_black_dongle()
|
||||
{
|
||||
struct security_rp_eeprom result;
|
||||
|
||||
security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13,
|
||||
boot_seeds_iidx_09, &black_plug_mcode_iidx_09, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &exp_iidx_09_black_eeprom,
|
||||
sizeof(struct security_rp_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_10_black_dongle()
|
||||
{
|
||||
struct security_rp_eeprom result;
|
||||
|
||||
security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13,
|
||||
boot_seeds_iidx_10, &black_plug_mcode_iidx_10, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &exp_iidx_10_black_eeprom,
|
||||
sizeof(struct security_rp_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_11_black_dongle()
|
||||
{
|
||||
struct security_rp_eeprom result;
|
||||
|
||||
security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13,
|
||||
boot_seeds_iidx_11, &black_plug_mcode_iidx_11, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &exp_iidx_11_black_eeprom,
|
||||
sizeof(struct security_rp_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_12_black_dongle()
|
||||
{
|
||||
struct security_rp_eeprom result;
|
||||
|
||||
security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13,
|
||||
boot_seeds_iidx_12, &black_plug_mcode_iidx_12, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &exp_iidx_12_black_eeprom,
|
||||
sizeof(struct security_rp_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_13_black_dongle()
|
||||
{
|
||||
struct security_rp_eeprom result;
|
||||
|
||||
security_rp_generate_signed_eeprom_data(&boot_version_iidx_09_to_13,
|
||||
boot_seeds_iidx_13, &black_plug_mcode_iidx_13, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &exp_iidx_13_black_eeprom,
|
||||
sizeof(struct security_rp_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp_eeprom));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-rp")
|
||||
TEST_MODULE_TEST(test_encode_iidx_09_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_10_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_11_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_12_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_13_black_dongle)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,224 @@
|
||||
#include "security/id.h"
|
||||
#include "security/rp2.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static const struct security_mcode boot_version_iidx_14 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_14,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode boot_version_iidx_15 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_15,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode boot_version_iidx_16 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_16,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode boot_version_iidx_17 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_C,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_17,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_A,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_14 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_14,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_FIELD_NULL,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_15 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_15,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_FIELD_NULL,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_16 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_Q,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_16,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_FIELD_NULL,
|
||||
};
|
||||
|
||||
static const struct security_mcode black_plug_mcode_iidx_17 = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_C,
|
||||
.game = SECURITY_MCODE_GAME_IIDX_17,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_FIELD_NULL,
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_14_black_eeprom = {
|
||||
.signature = {0x17, 0xC6, 0x2B, 0x6A, 0xDA, 0x29},
|
||||
.packed_payload = {0x67, 0x7C, 0xB2, 0xA4, 0x1A, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_15_black_eeprom = {
|
||||
.signature = {0xCE, 0xF8, 0xC7, 0xEF, 0xA6, 0xDF},
|
||||
.packed_payload = {0x67, 0x8C, 0x92, 0xA4, 0x1A, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_16_black_eeprom = {
|
||||
.signature = {0xE0, 0x58, 0xDA, 0xE4, 0x61, 0xF9},
|
||||
.packed_payload = {0x67, 0x9C, 0x42, 0x90, 0x1A, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_17_black_eeprom = {
|
||||
.signature = {0xC3, 0x4B, 0xF8, 0xAA, 0xC1, 0x3E},
|
||||
.packed_payload = {0xE7, 0xA8, 0x92, 0xAA, 0x1A, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_14_white_eeprom = {
|
||||
.signature = {0x45, 0xF7, 0xE3, 0x4C, 0x59, 0xE0},
|
||||
.packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_15_white_eeprom = {
|
||||
.signature = {0x45, 0xF7, 0xE3, 0x4C, 0x59, 0xE0},
|
||||
.packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_16_white_eeprom = {
|
||||
.signature = {0x45, 0xF7, 0xE3, 0x4C, 0x59, 0xE0},
|
||||
.packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82},
|
||||
};
|
||||
|
||||
static const struct security_rp2_eeprom exp_iidx_17_white_eeprom = {
|
||||
.signature = {0x45, 0xF7, 0xE3, 0x4C, 0x59, 0xE0},
|
||||
.packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82},
|
||||
};
|
||||
|
||||
static void test_encode_iidx_14_black_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&boot_version_iidx_14, &black_plug_mcode_iidx_14, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_14_black_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_14_white_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&boot_version_iidx_14, &security_mcode_eamuse, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_14_white_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_15_black_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&boot_version_iidx_15, &black_plug_mcode_iidx_15, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_15_black_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_15_white_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&boot_version_iidx_15, &security_mcode_eamuse, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_15_white_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_16_black_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&boot_version_iidx_16, &black_plug_mcode_iidx_16, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_16_black_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_16_white_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&boot_version_iidx_16, &security_mcode_eamuse, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_16_white_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_17_black_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&boot_version_iidx_17, &black_plug_mcode_iidx_17, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_17_black_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
static void test_encode_iidx_17_white_dongle()
|
||||
{
|
||||
struct security_rp2_eeprom result;
|
||||
|
||||
security_rp2_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&boot_version_iidx_17, &security_mcode_eamuse, &security_id_default,
|
||||
&result);
|
||||
|
||||
check_data_eq((void*) &result, sizeof(struct security_rp2_eeprom),
|
||||
(void*) &exp_iidx_17_white_eeprom, sizeof(struct security_rp2_eeprom));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-rp2")
|
||||
TEST_MODULE_TEST(test_encode_iidx_14_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_14_white_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_15_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_15_white_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_16_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_16_white_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_17_black_dongle)
|
||||
TEST_MODULE_TEST(test_encode_iidx_17_white_dongle)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "security/rp3.h"
|
||||
#include "security/rp-sign-key.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static const struct security_mcode black_plug_mcode_jubeat = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_C,
|
||||
.game = SECURITY_MCODE_GAME_JB_1,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_B,
|
||||
};
|
||||
|
||||
static const struct security_rp3_eeprom exp_jubeat_black_eeprom = {
|
||||
.signature = {0x73, 0x66, 0xBA, 0xBD, 0xDE, 0x36},
|
||||
.packed_payload = {0xE7, 0x88, 0x52, 0x94, 0x1A, 0x8A},
|
||||
.zeros = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
.crc = 0xA3,
|
||||
};
|
||||
|
||||
static const struct security_rp3_eeprom exp_jubeat_white_eeprom = {
|
||||
.signature = {0x43, 0x17, 0xB4, 0x2A, 0x3E, 0x87},
|
||||
.packed_payload = {0x20, 0x08, 0x82, 0x20, 0x08, 0x82},
|
||||
.zeros = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
.crc = 0x94,
|
||||
};
|
||||
|
||||
static void test_mcode_encode_black_dongle_jubeat()
|
||||
{
|
||||
struct security_rp3_eeprom result;
|
||||
|
||||
security_rp3_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_BLACK,
|
||||
&security_rp_sign_key_black_gfdmv4, &black_plug_mcode_jubeat,
|
||||
&security_id_default, &result);
|
||||
|
||||
check_data_eq((void*) &exp_jubeat_black_eeprom,
|
||||
sizeof(struct security_rp3_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp3_eeprom));
|
||||
}
|
||||
|
||||
static void test_mcode_encode_white_dongle_jubeat()
|
||||
{
|
||||
struct security_rp3_eeprom result;
|
||||
|
||||
security_rp3_generate_signed_eeprom_data(SECURITY_RP_UTIL_RP_TYPE_WHITE,
|
||||
&security_rp_sign_key_white_eamuse, &security_mcode_eamuse,
|
||||
&security_id_default, &result);
|
||||
|
||||
check_data_eq((void*) &exp_jubeat_white_eeprom,
|
||||
sizeof(struct security_rp3_eeprom), (void*) &result,
|
||||
sizeof(struct security_rp3_eeprom));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-rp3")
|
||||
TEST_MODULE_TEST(test_mcode_encode_black_dongle_jubeat)
|
||||
TEST_MODULE_TEST(test_mcode_encode_white_dongle_jubeat)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "security/mcode.h"
|
||||
#include "security/util.h"
|
||||
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
static const struct security_mcode black_plug_mcode_jubeat = {
|
||||
.header = SECURITY_MCODE_HEADER,
|
||||
.unkn = SECURITY_MCODE_UNKN_C,
|
||||
.game = SECURITY_MCODE_GAME_JB_1,
|
||||
.region = SECURITY_MCODE_REGION_JAPAN,
|
||||
.cabinet = SECURITY_MCODE_CABINET_A,
|
||||
.revision = SECURITY_MCODE_REVISION_B,
|
||||
};
|
||||
|
||||
static void test_mcode_encode_decode_eamuse()
|
||||
{
|
||||
uint8_t buffer[8];
|
||||
uint8_t result[8];
|
||||
|
||||
security_util_8_to_6_encode((const uint8_t*) &security_mcode_eamuse, buffer);
|
||||
security_util_6_to_8_decode(buffer, result);
|
||||
|
||||
check_data_eq(result, sizeof(result), &security_mcode_eamuse,
|
||||
sizeof(security_mcode_eamuse));
|
||||
}
|
||||
|
||||
static void test_mcode_encode_decode_jubeat()
|
||||
{
|
||||
uint8_t buffer[8];
|
||||
uint8_t result[8];
|
||||
|
||||
security_util_8_to_6_encode((const uint8_t*) &black_plug_mcode_jubeat,
|
||||
buffer);
|
||||
security_util_6_to_8_decode(buffer, result);
|
||||
|
||||
check_data_eq(result, sizeof(result), &black_plug_mcode_jubeat,
|
||||
sizeof(black_plug_mcode_jubeat));
|
||||
}
|
||||
|
||||
static void test_mcode_encode_decode_reverse_eamuse()
|
||||
{
|
||||
uint8_t buffer[8];
|
||||
uint8_t result[8];
|
||||
|
||||
security_util_8_to_6_encode_reverse((const uint8_t*) &security_mcode_eamuse,
|
||||
buffer);
|
||||
security_util_6_to_8_decode_reverse(buffer, result);
|
||||
|
||||
check_data_eq(result, sizeof(result), &security_mcode_eamuse,
|
||||
sizeof(security_mcode_eamuse));
|
||||
}
|
||||
|
||||
static void test_mcode_encode_decode_reverse_jubeat()
|
||||
{
|
||||
uint8_t buffer[8];
|
||||
uint8_t result[8];
|
||||
|
||||
security_util_8_to_6_encode_reverse(
|
||||
(const uint8_t*) &black_plug_mcode_jubeat, buffer);
|
||||
security_util_6_to_8_decode_reverse(buffer, result);
|
||||
|
||||
check_data_eq(result, sizeof(result), &black_plug_mcode_jubeat,
|
||||
sizeof(black_plug_mcode_jubeat));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("security-util")
|
||||
TEST_MODULE_TEST(test_mcode_encode_decode_eamuse)
|
||||
TEST_MODULE_TEST(test_mcode_encode_decode_jubeat)
|
||||
TEST_MODULE_TEST(test_mcode_encode_decode_reverse_eamuse)
|
||||
TEST_MODULE_TEST(test_mcode_encode_decode_reverse_jubeat)
|
||||
TEST_MODULE_END()
|
||||
@@ -0,0 +1,6 @@
|
||||
libs += test
|
||||
|
||||
srcdir_test := src/test/test
|
||||
|
||||
src_test := \
|
||||
check.c \
|
||||
@@ -0,0 +1,142 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test/check.h"
|
||||
|
||||
#include "util/hex.h"
|
||||
|
||||
static void _Noreturn __attribute__((format (printf, 4, 5))) fail(
|
||||
const char *file, int line, const char *func, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "%s:%d: In %s:\n", file, line, func);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
abort();
|
||||
}
|
||||
|
||||
void _Noreturn check_char_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, char result, char expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %c\n"
|
||||
"\tExpected %c\n\n",
|
||||
expr, result, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_char_neq_failed(const char *file, int line,
|
||||
const char *func, char *expr, char result, char expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %c\n"
|
||||
"\tNot expected %c\n\n",
|
||||
expr, result, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_int_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, int result, int expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %i\n"
|
||||
"\tExpected %i\n\n",
|
||||
expr, result, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_int_neq_failed(const char *file, int line,
|
||||
const char *func, char *expr, int result, int expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %i\n"
|
||||
"\tNot expected %i\n\n",
|
||||
expr, result, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_bool_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, bool result, bool expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %s\n"
|
||||
"\tExpected %s\n\n",
|
||||
expr, result ? "true" : "false", expected ? "true" : "false");
|
||||
}
|
||||
|
||||
void _Noreturn check_bool_neq_failed(const char *file, int line,
|
||||
const char *func, char *expr, bool result, bool expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %s\n"
|
||||
"\tNot expected %s\n\n",
|
||||
expr, result ? "true" : "false", expected ? "true" : "false");
|
||||
}
|
||||
|
||||
void _Noreturn check_float_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, float result, float expected, float delta)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was %f\n"
|
||||
"\tDelta value %f\n"
|
||||
"\tExpected %f\n\n",
|
||||
expr, result, delta, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_str_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, const char *result,
|
||||
const char *expected)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn value was \"%s\"\n"
|
||||
"\tExpected \"%s\"\n\n",
|
||||
expr, result, expected);
|
||||
}
|
||||
|
||||
void _Noreturn check_data_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, const void *result, const void *expected,
|
||||
size_t result_size, size_t expected_size)
|
||||
{
|
||||
char result_data[result_size * 2 + 1];
|
||||
char expected_data[expected_size * 2 + 1];
|
||||
|
||||
hex_encode_uc(result, result_size, result_data, sizeof(result_data));
|
||||
hex_encode_uc(expected, expected_size, expected_data,
|
||||
sizeof(expected_data));
|
||||
|
||||
fail(file, line, func,
|
||||
"\tIncorrect result: %s\n"
|
||||
"\tReturn size was: %d\n"
|
||||
"\tExected size: %d\n"
|
||||
"\tReturn value was \"%s\"\n"
|
||||
"\tExpected \"%s\"\n\n",
|
||||
expr, result_size, expected_size, result_data, expected_data);
|
||||
}
|
||||
|
||||
void _Noreturn check_non_null_failed(const char *file, int line, const char *func,
|
||||
char *expr)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tValue is not non-null: %s\n"
|
||||
"\tExpected non-null value\n\n",
|
||||
expr);
|
||||
}
|
||||
|
||||
void _Noreturn check_null_failed(const char *file, int line, const char *func,
|
||||
char *expr)
|
||||
{
|
||||
fail(file, line, func,
|
||||
"\tValue is not null: %s\n"
|
||||
"\tExpected null value\n\n",
|
||||
expr);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
#ifndef TEST_CHECK_H
|
||||
#define TEST_CHECK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#define check_char_eq(expr, expected) \
|
||||
{ \
|
||||
char _result = expr; \
|
||||
\
|
||||
if (_result != expected) { \
|
||||
check_char_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_char_neq(expr, expected) \
|
||||
{ \
|
||||
char _result = expr; \
|
||||
\
|
||||
if (_result == expected) { \
|
||||
check_char_neq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_int_eq(expr, expected) \
|
||||
{ \
|
||||
int _result = expr; \
|
||||
\
|
||||
if (_result != expected) { \
|
||||
check_int_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_int_neq(expr, expected) \
|
||||
{ \
|
||||
int _result = expr; \
|
||||
\
|
||||
if (_result == expected) { \
|
||||
check_int_neq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_float_eq(expr, expected, delta) \
|
||||
{ \
|
||||
float _result = expr; \
|
||||
\
|
||||
if (_result - expected > delta) { \
|
||||
check_float_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected, delta); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_bool_true(expr) \
|
||||
{ \
|
||||
bool _result = expr; \
|
||||
\
|
||||
if (!_result) { \
|
||||
check_bool_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, true); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_bool_false(expr) \
|
||||
{ \
|
||||
bool _result = expr; \
|
||||
\
|
||||
if (_result) { \
|
||||
check_bool_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, false); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_str_eq(expr, expected) \
|
||||
{ \
|
||||
const char *_result = expr; \
|
||||
\
|
||||
if (strcmp(_result, expected) != 0) { \
|
||||
check_str_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_data_eq(expr, result_size, expected, expected_size) \
|
||||
{ \
|
||||
const void *_result = expr; \
|
||||
\
|
||||
if (result_size != expected_size || memcmp(expr, expected, \
|
||||
expected_size)) { \
|
||||
check_data_eq_failed(__FILE__, __LINE__, __func__, #expr, \
|
||||
_result, expected, result_size, expected_size); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_non_null(expr) \
|
||||
{ \
|
||||
if (!expr) { \
|
||||
check_non_null_failed(__FILE__, __LINE__, __func__, #expr); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define check_null(expr) \
|
||||
{ \
|
||||
if (expr) { \
|
||||
check_null_failed(__FILE__, __LINE__, __func__, #expr); \
|
||||
} \
|
||||
} \
|
||||
|
||||
void _Noreturn check_char_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, char result, char expected);
|
||||
void _Noreturn check_char_neq_failed(const char *file, int line,
|
||||
const char *func, char *expr, char result, char expected);
|
||||
void _Noreturn check_int_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, int result, int expected);
|
||||
void _Noreturn check_int_neq_failed(const char *file, int line,
|
||||
const char *func, char *expr, int result, int expected);
|
||||
void _Noreturn check_bool_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, bool result, bool expected);
|
||||
void _Noreturn check_float_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, float result, float expected,
|
||||
float delta);
|
||||
void _Noreturn check_str_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, const char *result,
|
||||
const char *expected);
|
||||
void _Noreturn check_data_eq_failed(const char *file, int line,
|
||||
const char *func, char *expr, const void *result, const void *expected,
|
||||
size_t expr_size, size_t expected_size);
|
||||
void _Noreturn check_non_null_failed(const char *file, int line, const char *func,
|
||||
char *expr);
|
||||
void _Noreturn check_null_failed(const char *file, int line, const char *func,
|
||||
char *expr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef TEST_TEST_H
|
||||
#define TEST_TEST_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "util/log.h"
|
||||
|
||||
#define TEST_MODULE_BEGIN(name) \
|
||||
int main(int argc, char** argv) \
|
||||
{ \
|
||||
log_to_writer(log_writer_stderr, NULL); \
|
||||
fprintf(stderr, "Executing test module '%s'...\n", #name); \
|
||||
|
||||
#define TEST_MODULE_TEST(func) \
|
||||
{ \
|
||||
fprintf(stderr, "\tRunning test '%s'...\n", #func); \
|
||||
func(); \
|
||||
} \
|
||||
|
||||
#define TEST_MODULE_END() \
|
||||
fprintf(stderr, "Finished execution of test module\n"); \
|
||||
return 0; \
|
||||
} \
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
testexes += util-net-test
|
||||
|
||||
srcdir_util-net-test := src/test/util
|
||||
|
||||
ldflags_util-net-test := \
|
||||
-lws2_32 \
|
||||
-liphlpapi \
|
||||
|
||||
libs_util-net-test := \
|
||||
test \
|
||||
util \
|
||||
|
||||
src_util-net-test := \
|
||||
util-net-test.c \
|
||||
|
||||
################################################################################
|
||||
@@ -0,0 +1,524 @@
|
||||
#include "test/check.h"
|
||||
#include "test/test.h"
|
||||
|
||||
#include "util/net.h"
|
||||
|
||||
/* Note: Don't care about cleaning up of returned strings to avoid code
|
||||
* clutter
|
||||
*/
|
||||
|
||||
static void test_parse_invalid()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_false(net_str_parse("127.0.0", &addr));
|
||||
}
|
||||
|
||||
static void test_parse_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("127.0.0.1", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.ipv4.port, NET_INVALID_PORT);
|
||||
|
||||
check_bool_true(net_str_parse("127.0.0.1:1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.ipv4.port, 1234);
|
||||
}
|
||||
|
||||
static void test_parse_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse(NET_LOCALHOST_NAME, &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.hostname.host, NET_LOCALHOST_NAME);
|
||||
check_int_eq(addr.hostname.port, NET_INVALID_PORT);
|
||||
|
||||
check_bool_true(net_str_parse(NET_LOCALHOST_NAME ":1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.hostname.host, NET_LOCALHOST_NAME);
|
||||
check_int_eq(addr.hostname.port, 1234);
|
||||
}
|
||||
|
||||
static void test_parse_url_http_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("http://127.0.0.1", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("http://127.0.0.1:1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, 1234);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("http://127.0.0.1/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
|
||||
check_bool_true(net_str_parse("http://127.0.0.1:22/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, 22);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
}
|
||||
|
||||
static void test_parse_url_https_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("https://127.0.0.1", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("https://127.0.0.1:1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, 1234);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("https://127.0.0.1/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
|
||||
check_bool_true(net_str_parse("https://127.0.0.1:22/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_IPV4);
|
||||
check_int_eq(addr.url.ipv4.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.url.ipv4.port, 22);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
}
|
||||
|
||||
static void test_parse_url_http_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("http://www.google.com", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("http://www.google.com:1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, 1234);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("http://www.google.com/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
|
||||
check_bool_true(net_str_parse("http://www.google.com:22/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_false(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, 22);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
}
|
||||
|
||||
static void test_parse_url_https_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("https://www.google.com", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("https://www.google.com:1234", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, 1234);
|
||||
check_str_eq(addr.url.path, "");
|
||||
|
||||
check_bool_true(net_str_parse("https://www.google.com/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, NET_INVALID_PORT);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
|
||||
check_bool_true(net_str_parse("https://www.google.com:22/somewhere", &addr));
|
||||
check_int_eq(addr.type, NET_ADDR_TYPE_URL);
|
||||
check_bool_true(addr.url.is_https);
|
||||
check_int_eq(addr.url.type, NET_ADDR_TYPE_HOSTNAME);
|
||||
check_str_eq(addr.url.hostname.host, "www.google.com");
|
||||
check_int_eq(addr.url.hostname.port, 22);
|
||||
check_str_eq(addr.url.path, "somewhere");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.ipv4.port = NET_INVALID_PORT;
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "127.0.0.1");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.ipv4.port = 1234;
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "127.0.0.1:1234");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.hostname.host, NET_LOCALHOST_NAME);
|
||||
addr.hostname.port = NET_INVALID_PORT;
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "localhost");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.hostname.host, NET_LOCALHOST_NAME);
|
||||
addr.hostname.port = 1234;
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "localhost:1234");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_url_http_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = NET_INVALID_PORT;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://127.0.0.1");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = NET_INVALID_PORT;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://127.0.0.1/somewhere");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = 1234;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://127.0.0.1:1234");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = 1234;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://127.0.0.1:1234/somewhere");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_url_https_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = NET_INVALID_PORT;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://127.0.0.1");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = NET_INVALID_PORT;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://127.0.0.1/somewhere");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = 1234;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://127.0.0.1:1234");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = 1234;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://127.0.0.1:1234/somewhere");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_url_http_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = NET_INVALID_PORT;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://www.google.com");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = NET_INVALID_PORT;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://www.google.com/somewhere");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = 1234;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://www.google.com:1234");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = false;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = 1234;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "http://www.google.com:1234/somewhere");
|
||||
}
|
||||
|
||||
static void test_net_addr_to_str_url_https_hostname()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = NET_INVALID_PORT;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://www.google.com");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = NET_INVALID_PORT;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://www.google.com/somewhere");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = 1234;
|
||||
memset(addr.url.path, 0, sizeof(addr.url.path));
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://www.google.com:1234");
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.is_https = true;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.url.hostname.host, "www.google.com");
|
||||
addr.url.hostname.port = 1234;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
|
||||
check_str_eq(net_addr_to_str(&addr), "https://www.google.com:1234/somewhere");
|
||||
}
|
||||
|
||||
static void test_resolve_hostname_str()
|
||||
{
|
||||
struct net_addr_ipv4 addr;
|
||||
|
||||
addr.addr = NET_INVALID_ADDR;
|
||||
addr.port = NET_INVALID_PORT;
|
||||
|
||||
check_bool_true(net_resolve_hostname("www.google.com", &addr));
|
||||
check_int_neq(addr.addr, NET_INVALID_ADDR);
|
||||
check_int_eq(addr.port, NET_INVALID_PORT);
|
||||
|
||||
addr.addr = NET_INVALID_ADDR;
|
||||
addr.port = NET_INVALID_PORT;
|
||||
|
||||
check_bool_true(net_resolve_hostname(NET_LOCALHOST_NAME, &addr));
|
||||
check_int_eq(addr.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(addr.port, NET_INVALID_PORT);
|
||||
|
||||
addr.addr = NET_INVALID_ADDR;
|
||||
addr.port = NET_INVALID_PORT;
|
||||
|
||||
check_bool_false(net_resolve_hostname("opihjblaksdasd", &addr));
|
||||
check_int_eq(addr.addr, NET_INVALID_ADDR);
|
||||
check_int_eq(addr.port, NET_INVALID_PORT);
|
||||
}
|
||||
|
||||
static void test_resolve_hostname_ipv4_addr()
|
||||
{
|
||||
struct net_addr addr;
|
||||
struct net_addr_ipv4 res_addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.ipv4.port = 1234;
|
||||
|
||||
check_bool_true(net_resolve_hostname_net_addr(&addr, &res_addr));
|
||||
check_int_eq(res_addr.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(res_addr.port, 1234);
|
||||
}
|
||||
|
||||
static void test_resolve_hostname_hostname_addr()
|
||||
{
|
||||
struct net_addr addr;
|
||||
struct net_addr_ipv4 res_addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
strcpy(addr.hostname.host, NET_LOCALHOST_NAME);
|
||||
addr.hostname.port = 1234;
|
||||
|
||||
check_bool_true(net_resolve_hostname_net_addr(&addr, &res_addr));
|
||||
check_int_eq(res_addr.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(res_addr.port, 1234);
|
||||
}
|
||||
|
||||
static void test_resolve_hostname_url_ipv4_addr()
|
||||
{
|
||||
struct net_addr addr;
|
||||
struct net_addr_ipv4 res_addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.type = NET_ADDR_TYPE_IPV4;
|
||||
addr.url.is_https = false;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
addr.url.ipv4.addr = NET_LOCALHOST_ADDR;
|
||||
addr.url.ipv4.port = 1234;
|
||||
|
||||
check_bool_true(net_resolve_hostname_net_addr(&addr, &res_addr));
|
||||
check_int_eq(res_addr.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(res_addr.port, 1234);
|
||||
}
|
||||
|
||||
static void test_resolve_hostname_url_hostname_addr()
|
||||
{
|
||||
struct net_addr addr;
|
||||
struct net_addr_ipv4 res_addr;
|
||||
|
||||
addr.type = NET_ADDR_TYPE_URL;
|
||||
addr.url.type = NET_ADDR_TYPE_HOSTNAME;
|
||||
addr.url.is_https = false;
|
||||
strcpy(addr.url.path, "somewhere");
|
||||
strcpy(addr.url.hostname.host, NET_LOCALHOST_NAME);
|
||||
addr.url.hostname.port = 1234;
|
||||
|
||||
check_bool_true(net_resolve_hostname_net_addr(&addr, &res_addr));
|
||||
check_int_eq(res_addr.addr, NET_LOCALHOST_ADDR);
|
||||
check_int_eq(res_addr.port, 1234);
|
||||
}
|
||||
|
||||
static void test_check_remote_connection()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("127.0.0.1:1", &addr));
|
||||
check_bool_false(net_check_remote_connection(&addr, 2000));
|
||||
|
||||
check_bool_true(net_str_parse("www.google.com:80", &addr));
|
||||
check_bool_true(net_check_remote_connection(&addr, 2000));
|
||||
|
||||
check_bool_true(net_str_parse("www.google.com:22", &addr));
|
||||
check_bool_false(net_check_remote_connection(&addr, 2000));
|
||||
}
|
||||
|
||||
static void test_check_remote_connection_ipv4()
|
||||
{
|
||||
struct net_addr addr;
|
||||
|
||||
check_bool_true(net_str_parse("127.0.0.1:1", &addr));
|
||||
check_bool_false(net_check_remote_connection_ipv4(&addr.ipv4, 2000));
|
||||
}
|
||||
|
||||
TEST_MODULE_BEGIN("util/net")
|
||||
TEST_MODULE_TEST(test_parse_invalid)
|
||||
TEST_MODULE_TEST(test_parse_ipv4)
|
||||
TEST_MODULE_TEST(test_parse_hostname)
|
||||
TEST_MODULE_TEST(test_parse_url_http_ipv4)
|
||||
TEST_MODULE_TEST(test_parse_url_https_ipv4)
|
||||
TEST_MODULE_TEST(test_parse_url_http_hostname)
|
||||
TEST_MODULE_TEST(test_parse_url_https_hostname)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_ipv4)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_hostname)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_url_http_ipv4)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_url_https_ipv4)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_url_http_hostname)
|
||||
TEST_MODULE_TEST(test_net_addr_to_str_url_https_hostname)
|
||||
TEST_MODULE_TEST(test_resolve_hostname_str)
|
||||
TEST_MODULE_TEST(test_resolve_hostname_ipv4_addr)
|
||||
TEST_MODULE_TEST(test_resolve_hostname_hostname_addr)
|
||||
TEST_MODULE_TEST(test_resolve_hostname_url_ipv4_addr)
|
||||
TEST_MODULE_TEST(test_resolve_hostname_url_hostname_addr)
|
||||
TEST_MODULE_TEST(test_check_remote_connection)
|
||||
TEST_MODULE_TEST(test_check_remote_connection_ipv4)
|
||||
TEST_MODULE_END()
|
||||
Reference in New Issue
Block a user