]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/hextoint.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / hextoint.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
5 #include "ntp_fp.h"
6
7 #include "unity.h"
8
9
10 void test_SingleDigit(void) {
11         const char *str = "a"; // 10 decimal
12         u_long actual;
13
14         TEST_ASSERT_TRUE(hextoint(str, &actual));
15         TEST_ASSERT_EQUAL(10, actual);
16 }
17
18 void test_MultipleDigits(void) {
19         const char *str = "8F3"; // 2291 decimal
20         u_long actual;
21
22         TEST_ASSERT_TRUE(hextoint(str, &actual));
23         TEST_ASSERT_EQUAL(2291, actual);
24 }
25
26 void test_MaxUnsigned(void) {
27         const char *str = "ffffffff"; // 4294967295 decimal
28         u_long actual;
29
30         TEST_ASSERT_TRUE(hextoint(str, &actual));
31         TEST_ASSERT_EQUAL(4294967295UL, actual);
32 }
33
34 void test_Overflow(void) {
35         const char *str = "100000000"; // Overflow by 1
36         u_long actual;
37
38         TEST_ASSERT_FALSE(hextoint(str, &actual));
39 }
40
41 void test_IllegalChar(void) {
42         const char *str = "5gb"; // Illegal character g
43         u_long actual;
44
45         TEST_ASSERT_FALSE(hextoint(str, &actual));
46 }
47