aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests/epee_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests/epee_utils.cpp')
-rw-r--r--tests/unit_tests/epee_utils.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 1c756e77c..110cebf6a 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1836,3 +1836,60 @@ TEST(parsing, unicode)
epee::misc_utils::parse::match_string2(si, s.end(), bs);
EXPECT_EQ(bs, "あまやかす");
}
+
+TEST(parsing, strtoul)
+{
+ long ul;
+ const char* p;
+ const char* endp;
+
+ errno = 0; // Some libc's only set errno on failure, some set it to 0 on success
+
+ p = "0";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(0, ul);
+ EXPECT_EQ(p + 1, endp);
+
+ p = "000000";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(0, ul);
+ EXPECT_EQ(p + 6, endp);
+
+ p = "1";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(1, ul);
+ EXPECT_EQ(p + 1, endp);
+
+ p = "0q";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(0, ul);
+ EXPECT_EQ(p + 1, endp);
+
+ p = " \t 0";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(0, ul);
+ EXPECT_EQ(p + 9, endp);
+
+ p = "q";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(0, ul);
+ EXPECT_EQ(p, endp);
+
+ p = "999999999999999999999999999999999999999";
+ endp = nullptr;
+ ul = std::strtoul(p, const_cast<char**>(&endp), 10);
+ EXPECT_EQ(ERANGE, errno);
+ EXPECT_EQ(ULLONG_MAX, ul);
+}