1 /* $NetBSD: octtoint.c,v 1.1.1.3 2015/10/23 17:47:45 christos Exp $ */ 2 3 #include "config.h" 4 5 #include "ntp_stdlib.h" 6 7 #include "unity.h" 8 9 10 void test_SingleDigit(void); 11 void test_MultipleDigits(void); 12 void test_Zero(void); 13 void test_MaximumUnsigned32bit(void); 14 void test_Overflow(void); 15 void test_IllegalCharacter(void); 16 void test_IllegalDigit(void); 17 18 19 void test_SingleDigit(void) { 20 const char* str = "5"; 21 u_long actual; 22 23 TEST_ASSERT_TRUE(octtoint(str, &actual) ); 24 TEST_ASSERT_EQUAL(5, actual); 25 } 26 27 void test_MultipleDigits(void){ 28 const char* str = "271"; 29 u_long actual; 30 31 TEST_ASSERT_TRUE(octtoint(str, &actual) ); 32 TEST_ASSERT_EQUAL(185, actual); 33 34 } 35 36 void test_Zero(void){ 37 const char* str = "0"; 38 u_long actual; 39 40 TEST_ASSERT_TRUE(octtoint(str, &actual) ); 41 TEST_ASSERT_EQUAL(0, actual); 42 43 } 44 45 void test_MaximumUnsigned32bit(void){ 46 const char* str = "37777777777"; 47 u_long actual; 48 49 TEST_ASSERT_TRUE(octtoint(str, &actual) ); 50 TEST_ASSERT_EQUAL(4294967295UL, actual); 51 52 } 53 54 void test_Overflow(void){ 55 const char* str = "40000000000"; 56 u_long actual; 57 58 TEST_ASSERT_FALSE(octtoint(str, &actual) ); 59 60 } 61 62 void test_IllegalCharacter(void){ 63 const char* str = "5ac2"; 64 u_long actual; 65 66 TEST_ASSERT_FALSE(octtoint(str, &actual) ); 67 68 } 69 70 void test_IllegalDigit(void){ 71 const char* str = "5283"; 72 u_long actual; 73 74 TEST_ASSERT_FALSE(octtoint(str, &actual) ); 75 76 } 77