aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-12-04 17:07:19 +0200
committerRiccardo Spagni <ric@spagni.net>2018-12-04 17:07:19 +0200
commit40650b43b852a983af5a8df308aa3abf1a1d61dc (patch)
treeb6462024a452b4defa07e6e9fda5cdf09d45bba4 /tests/unit_tests
parentMerge pull request #4848 (diff)
parentunit_tests: add some hex parsing test for non hex input (diff)
downloadmonero-40650b43b852a983af5a8df308aa3abf1a1d61dc.tar.xz
Merge pull request #4850
b36353e2 unit_tests: add some hex parsing test for non hex input (xiphon) 6671110c unit_tests: add a test for parse_hexstr_to_binbuff (moneromooo-monero) f6187cd8 epee: speed up parse_hexstr_to_binbuff a little (Howard Chu)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/epee_utils.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index c2b0b7647..c384ce9a5 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -456,6 +456,35 @@ TEST(StringTools, PodToHex)
);
}
+TEST(StringTools, ParseHex)
+{
+ static const char data[] = "a10b68c2";
+ for (size_t i = 0; i < sizeof(data); i += 2)
+ {
+ std::string res;
+ ASSERT_TRUE(epee::string_tools::parse_hexstr_to_binbuff(std::string(data, i), res));
+ std::string hex = epee::string_tools::buff_to_hex_nodelimer(res);
+ ASSERT_EQ(hex.size(), i);
+ ASSERT_EQ(memcmp(data, hex.data(), i), 0);
+ }
+}
+
+TEST(StringTools, ParseNotHex)
+{
+ std::string res;
+ for (size_t i = 0; i < 256; ++i)
+ {
+ std::string inputHexString = std::string(2, static_cast<char>(i));
+ if ((i >= '0' && i <= '9') || (i >= 'A' && i <= 'F') || (i >= 'a' && i <= 'f')) {
+ ASSERT_TRUE(epee::string_tools::parse_hexstr_to_binbuff(inputHexString, res));
+ } else {
+ ASSERT_FALSE(epee::string_tools::parse_hexstr_to_binbuff(inputHexString, res));
+ }
+ }
+
+ ASSERT_FALSE(epee::string_tools::parse_hexstr_to_binbuff(std::string("a"), res));
+}
+
TEST(StringTools, GetIpString)
{
EXPECT_EQ(