From: Lokesh Walase Date: Fri, 12 Jun 2015 10:20:51 +0000 (+0530) Subject: octtoint.cpp converted to unity framework X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29311a2c798833596f8e0f43d3a9745020b4d5ce;p=thirdparty%2Fntp.git octtoint.cpp converted to unity framework bk: 557ab283KzgURGb65oTA0qgS4EJ1bg --- diff --git a/tests/libntp/g_octtoint.cpp b/tests/libntp/g_octtoint.cpp new file mode 100644 index 000000000..14a993e03 --- /dev/null +++ b/tests/libntp/g_octtoint.cpp @@ -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 index 000000000..b2ceeed09 --- /dev/null +++ b/tests/libntp/octtoint.c @@ -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 index 000000000..be9d09b11 --- /dev/null +++ b/tests/libntp/run-test-octtoint.c @@ -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 +#include + +//=======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()); +}