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