]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/g_octtoint.cpp
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / g_octtoint.cpp
1 #include "g_libntptest.h"
2
3 class octtointTest : public libntptest {
4 };
5
6 TEST_F(octtointTest, SingleDigit) {
7         const char* str = "5";
8         u_long actual;
9
10         ASSERT_TRUE(octtoint(str, &actual));
11         EXPECT_EQ(5, actual);
12 }
13
14 TEST_F(octtointTest, MultipleDigits) {
15         const char* str = "271";
16         u_long actual;
17
18         ASSERT_TRUE(octtoint(str, &actual));
19         EXPECT_EQ(185, actual);
20 }
21
22 TEST_F(octtointTest, Zero) {
23         const char* str = "0";
24         u_long actual;
25
26         ASSERT_TRUE(octtoint(str, &actual));
27         EXPECT_EQ(0, actual);
28 }
29
30 TEST_F(octtointTest, MaximumUnsigned32bit) {
31         const char* str = "37777777777";
32         u_long actual;
33
34         ASSERT_TRUE(octtoint(str, &actual));
35         EXPECT_EQ(4294967295UL, actual);
36 }
37
38 TEST_F(octtointTest, Overflow) {
39         const char* str = "40000000000";
40         u_long actual;
41
42         ASSERT_FALSE(octtoint(str, &actual));
43 }
44
45 TEST_F(octtointTest, IllegalCharacter) {
46         const char* str = "5ac2";
47         u_long actual;
48
49         ASSERT_FALSE(octtoint(str, &actual));
50 }
51
52 TEST_F(octtointTest, IllegalDigit) {
53         const char* str = "5283";
54         u_long actual;
55
56         ASSERT_FALSE(octtoint(str, &actual));
57 }