OEMCrypto and OPK v19.3

This commit is contained in:
John W. Bruce
2024-09-05 07:21:15 +00:00
parent 482b0923ca
commit 365ea19c9a
95 changed files with 4332 additions and 528 deletions

View File

@@ -189,4 +189,115 @@ TEST_F(HtoNLL64Test, NegativeNumber) {
int64_t host_byte_order = htonll64(*network_byte_order);
EXPECT_EQ(-0x01FdFcFbFaF9F8F8, host_byte_order);
}
TEST(SafeByteIdToString, EmptyId) {
const std::string kEmptyString;
EXPECT_EQ(SafeByteIdToString(kEmptyString), "<empty>");
const std::vector<uint8_t> kEmptyVector;
EXPECT_EQ(SafeByteIdToString(kEmptyVector), "<empty>");
}
TEST(SafeByteIdToString, AllAlphaNumeric_NoEscape) {
const std::string sid("Hello, World!");
const std::vector<uint8_t> vid(sid.begin(), sid.end());
EXPECT_EQ(SafeByteIdToString(sid), "\"Hello, World!\"");
EXPECT_EQ(SafeByteIdToString(vid), "\"Hello, World!\"");
}
TEST(SafeByteIdToString, AllAlphaNumeric_NoEscape_Exhaustive) {
for (char ch = 'a'; ch <= 'z'; ch++) {
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
for (char ch = 'A'; ch <= 'Z'; ch++) {
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
for (char ch = '0'; ch <= '9'; ch++) {
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
}
TEST(SafeByteIdToString, AllSymbols_NoEscape) {
for (char ch = ' '; ch <= '/'; ch++) {
if (ch == '"') continue;
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
for (char ch = ':'; ch <= '@'; ch++) {
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
for (char ch = '['; ch <= '`'; ch++) {
if (ch == '\\') continue;
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
for (char ch = '{'; ch <= '~'; ch++) {
const std::string sid(1, ch);
const std::vector<uint8_t> vid(1, ch);
std::string expected(1, '"');
expected.push_back(ch);
expected.push_back('"');
EXPECT_EQ(SafeByteIdToString(sid), expected);
EXPECT_EQ(SafeByteIdToString(vid), expected);
}
}
TEST(SafeByteIdToString, Escapable_NoEscape) {
const std::string quote_sid(1, '"');
const std::vector<uint8_t> quote_vid(1, '"');
EXPECT_EQ(SafeByteIdToString(quote_sid), "\"\\\"\"");
EXPECT_EQ(SafeByteIdToString(quote_vid), "\"\\\"\"");
const std::string backslash_sid(1, '\\');
const std::vector<uint8_t> backslash_vid(1, '\\');
EXPECT_EQ(SafeByteIdToString(backslash_sid), "\"\\\\\"");
EXPECT_EQ(SafeByteIdToString(backslash_vid), "\"\\\\\"");
}
TEST(SafeByteIdToString, AllNonPrintable) {
const std::vector<uint8_t> vid = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const std::string sid(vid.begin(), vid.end());
EXPECT_EQ(SafeByteIdToString(vid), "00010203040506070809");
EXPECT_EQ(SafeByteIdToString(sid), "00010203040506070809");
}
} // namespace wvutil