Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/tests/test_ModIo.h
Show All 36 Lines | if (sodium_init() < 0) | ||||
LOGERROR("failed to initialize libsodium"); | LOGERROR("failed to initialize libsodium"); | ||||
} | } | ||||
// TODO: One could probably fuzz these parsing functions to | // TODO: One could probably fuzz these parsing functions to | ||||
// make sure they handle malformed input nicely. | // make sure they handle malformed input nicely. | ||||
void test_id_parsing() | void test_id_parsing() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
#define TS_ASSERT_PARSE(input, expected_error, expected_id) \ | #define TS_ASSERT_PARSE(input, expected_error, expected_id) \ | ||||
{ \ | { \ | ||||
TestLogger logger; \ | TestLogger logger; \ | ||||
int id = -1; \ | int id = -1; \ | ||||
std::string err; \ | std::string err; \ | ||||
TS_ASSERT(!ModIo::ParseGameIdResponse(script, input, id, err)); \ | TS_ASSERT(!ModIo::ParseGameIdResponse(script, input, id, err)); \ | ||||
TS_ASSERT_STR_EQUALS(err, expected_error); \ | TS_ASSERT_STR_EQUALS(err, expected_error); \ | ||||
Show All 31 Lines | // Correctly formed input | ||||
TS_ASSERT(ModIo::ParseGameIdResponse(script, "{\"data\": [{\"id\": 42}]}", id, err)); | TS_ASSERT(ModIo::ParseGameIdResponse(script, "{\"data\": [{\"id\": 42}]}", id, err)); | ||||
TS_ASSERT(err.empty()); | TS_ASSERT(err.empty()); | ||||
TS_ASSERT_EQUALS(id, 42); | TS_ASSERT_EQUALS(id, 42); | ||||
} | } | ||||
} | } | ||||
void test_mods_parsing() | void test_mods_parsing() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
PKStruct pk; | PKStruct pk; | ||||
const std::string pk_str = "RWTA6VIoth2Q1PFLsRILr3G7NB+mwwO8BSGoXs63X6TQgNGM4cE8Pvd6"; | const std::string pk_str = "RWTA6VIoth2Q1PFLsRILr3G7NB+mwwO8BSGoXs63X6TQgNGM4cE8Pvd6"; | ||||
size_t bin_len = 0; | size_t bin_len = 0; | ||||
if (sodium_base642bin((unsigned char*)&pk, sizeof pk, pk_str.c_str(), pk_str.size(), NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) != 0 || bin_len != sizeof pk) | if (sodium_base642bin((unsigned char*)&pk, sizeof pk, pk_str.c_str(), pk_str.size(), NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) != 0 || bin_len != sizeof pk) | ||||
LOGERROR("failed to decode base64 public key"); | LOGERROR("failed to decode base64 public key"); | ||||
▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator