summaryrefslogtreecommitdiff
path: root/tests/libntp/hextoint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libntp/hextoint.cpp')
-rw-r--r--tests/libntp/hextoint.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/libntp/hextoint.cpp b/tests/libntp/hextoint.cpp
new file mode 100644
index 0000000..54c9a67
--- /dev/null
+++ b/tests/libntp/hextoint.cpp
@@ -0,0 +1,42 @@
+#include "libntptest.h"
+
+class hextointTest : public libntptest {
+};
+
+TEST_F(hextointTest, SingleDigit) {
+ const char *str = "a"; // 10 decimal
+ u_long actual;
+
+ ASSERT_TRUE(hextoint(str, &actual));
+ EXPECT_EQ(10, actual);
+}
+
+TEST_F(hextointTest, MultipleDigits) {
+ const char *str = "8F3"; // 2291 decimal
+ u_long actual;
+
+ ASSERT_TRUE(hextoint(str, &actual));
+ EXPECT_EQ(2291, actual);
+}
+
+TEST_F(hextointTest, MaxUnsigned) {
+ const char *str = "ffffffff"; // 4294967295 decimal
+ u_long actual;
+
+ ASSERT_TRUE(hextoint(str, &actual));
+ EXPECT_EQ(4294967295UL, actual);
+}
+
+TEST_F(hextointTest, Overflow) {
+ const char *str = "100000000"; // Overflow by 1
+ u_long actual;
+
+ ASSERT_FALSE(hextoint(str, &actual));
+}
+
+TEST_F(hextointTest, IllegalChar) {
+ const char *str = "5gb"; // Illegal character g
+ u_long actual;
+
+ ASSERT_FALSE(hextoint(str, &actual));
+}