summaryrefslogtreecommitdiff
path: root/contrib/ntp/tests/libntp/octtoint.c
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2015-07-05 15:42:16 +0000
committerCy Schubert <cy@FreeBSD.org>2015-07-05 15:42:16 +0000
commit276da39af92f48350aa01091a2b8b3e735217eea (patch)
treefb96356e3ef85aaa8d1f5939a9decd315a7ca596 /contrib/ntp/tests/libntp/octtoint.c
parent31c98473c1337a238b00342edd7ef85dfb378e24 (diff)
parent873997f35a991eee09ed91148a0cf332360380da (diff)
Notes
Diffstat (limited to 'contrib/ntp/tests/libntp/octtoint.c')
-rw-r--r--contrib/ntp/tests/libntp/octtoint.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/ntp/tests/libntp/octtoint.c b/contrib/ntp/tests/libntp/octtoint.c
new file mode 100644
index 0000000000000..4b0f94ceaa36a
--- /dev/null
+++ b/contrib/ntp/tests/libntp/octtoint.c
@@ -0,0 +1,64 @@
+#include "config.h"
+
+#include "ntp_stdlib.h"
+
+#include "unity.h"
+
+void test_SingleDigit(void) {
+ const char* str = "5";
+ u_long actual;
+
+ TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_EQUAL(5, actual);
+}
+
+void test_MultipleDigits(void){
+ const char* str = "271";
+ u_long actual;
+
+ TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_EQUAL(185, actual);
+
+}
+
+void test_Zero(void){
+ const char* str = "0";
+ u_long actual;
+
+ TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_EQUAL(0, actual);
+
+}
+
+void test_MaximumUnsigned32bit(void){
+ const char* str = "37777777777";
+ u_long actual;
+
+ TEST_ASSERT_TRUE(octtoint(str, &actual) );
+ TEST_ASSERT_EQUAL(4294967295UL, actual);
+
+}
+
+void test_Overflow(void){
+ const char* str = "40000000000";
+ u_long actual;
+
+ TEST_ASSERT_FALSE(octtoint(str, &actual) );
+
+}
+
+void test_IllegalCharacter(void){
+ const char* str = "5ac2";
+ u_long actual;
+
+ TEST_ASSERT_FALSE(octtoint(str, &actual) );
+
+}
+
+void test_IllegalDigit(void){
+ const char* str = "5283";
+ u_long actual;
+
+ TEST_ASSERT_FALSE(octtoint(str, &actual) );
+
+}