]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
octtoint.cpp converted to unity framework
authorLokesh Walase <lokeshw24@ntp.org>
Fri, 12 Jun 2015 10:20:51 +0000 (15:50 +0530)
committerLokesh Walase <lokeshw24@ntp.org>
Fri, 12 Jun 2015 10:20:51 +0000 (15:50 +0530)
bk: 557ab283KzgURGb65oTA0qgS4EJ1bg

tests/libntp/g_octtoint.cpp [new file with mode: 0644]
tests/libntp/octtoint.c [new file with mode: 0644]
tests/libntp/run-test-octtoint.c [new file with mode: 0644]

diff --git a/tests/libntp/g_octtoint.cpp b/tests/libntp/g_octtoint.cpp
new file mode 100644 (file)
index 0000000..14a993e
--- /dev/null
@@ -0,0 +1,57 @@
+#include "libntptest.h"
+
+class octtointTest : public libntptest {
+};
+
+TEST_F(octtointTest, SingleDigit) {
+       const char* str = "5";
+       u_long actual;
+
+       ASSERT_TRUE(octtoint(str, &actual));
+       EXPECT_EQ(5, actual);
+}
+
+TEST_F(octtointTest, MultipleDigits) {
+       const char* str = "271";
+       u_long actual;
+
+       ASSERT_TRUE(octtoint(str, &actual));
+       EXPECT_EQ(185, actual);
+}
+
+TEST_F(octtointTest, Zero) {
+       const char* str = "0";
+       u_long actual;
+
+       ASSERT_TRUE(octtoint(str, &actual));
+       EXPECT_EQ(0, actual);
+}
+
+TEST_F(octtointTest, MaximumUnsigned32bit) {
+       const char* str = "37777777777";
+       u_long actual;
+
+       ASSERT_TRUE(octtoint(str, &actual));
+       EXPECT_EQ(4294967295UL, actual);
+}
+
+TEST_F(octtointTest, Overflow) {
+       const char* str = "40000000000";
+       u_long actual;
+
+       ASSERT_FALSE(octtoint(str, &actual));
+}
+
+TEST_F(octtointTest, IllegalCharacter) {
+       const char* str = "5ac2";
+       u_long actual;
+
+       ASSERT_FALSE(octtoint(str, &actual));
+}
+
+TEST_F(octtointTest, IllegalDigit) {
+       const char* str = "5283";
+       u_long actual;
+
+       ASSERT_FALSE(octtoint(str, &actual));
+}
diff --git a/tests/libntp/octtoint.c b/tests/libntp/octtoint.c
new file mode 100644 (file)
index 0000000..b2ceeed
--- /dev/null
@@ -0,0 +1,63 @@
+#include "testcalshims.h"
+//#include "ntp_fp.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) );
+
+}
diff --git a/tests/libntp/run-test-octtoint.c b/tests/libntp/run-test-octtoint.c
new file mode 100644 (file)
index 0000000..be9d09b
--- /dev/null
@@ -0,0 +1,60 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+//=======Test Runner Used To Run Each Test Below=====
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+  Unity.CurrentTestName = #TestFunc; \
+  Unity.CurrentTestLineNumber = TestLineNum; \
+  Unity.NumberOfTests++; \
+  if (TEST_PROTECT()) \
+  { \
+      setUp(); \
+      TestFunc(); \
+  } \
+  if (TEST_PROTECT() && !TEST_IS_IGNORED) \
+  { \
+    tearDown(); \
+  } \
+  UnityConcludeTest(); \
+}
+
+//=======Automagically Detected Files To Include=====
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_SingleDigit(void);
+extern void test_MultipleDigits(void);
+extern void test_Zero(void);
+extern void test_MaximumUnsigned32bit(void);
+extern void test_Overflow(void);
+extern void test_IllegalCharacter(void);
+extern void test_IllegalDigit(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+  Unity.TestFile = "octtoint.c";
+  UnityBegin("octtoint.c");
+  RUN_TEST(test_SingleDigit, 5);
+  RUN_TEST(test_MultipleDigits, 14);
+  RUN_TEST(test_Zero, 23);
+  RUN_TEST(test_MaximumUnsigned32bit, 32);
+  RUN_TEST(test_Overflow, 41);
+  RUN_TEST(test_IllegalCharacter, 49);
+  RUN_TEST(test_IllegalDigit, 57);
+
+  return (UnityEnd());
+}