summaryrefslogtreecommitdiff
path: root/tests/libntp/hextoint.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2014-12-02 09:01:21 +0000
committer <>2014-12-04 16:11:25 +0000
commitbdab5265fcbf3f472545073a23f8999749a9f2b9 (patch)
treec6018dd03dea906f8f1fb5f105f05b71a7dc250a /tests/libntp/hextoint.cpp
downloadntp-dev-4.2.7p482.tar.gz
Imported from /home/lorry/working-area/delta_ntp/ntp-dev-4.2.7p482.tar.gz.ntp-dev-4.2.7p482
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));
+}