1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// **********************************************************************
//
// Copyright (c) 2001
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <IceUtil/Unicode.h>
#include <IceUtil/InputUtil.h>
#include <TestCommon.h>
using namespace IceUtil;
using namespace std;
#define WS " \f\n\r\t\v"
int
main(int, char**)
{
cout << "testing string-to-64-bit integer conversion... ";
bool b;
Int64 result;
string::size_type pos;
b = stringToInt64("", result, pos);
test(!b && result == 0 && pos == string::npos);
b = stringToInt64(WS, result, pos);
test(!b && result == 0 && pos == string::npos);
b = stringToInt64("123", result, pos);
test(b && result == 123 && pos == string::npos);
b = stringToInt64("+123", result, pos);
test(b && result == 123 && pos == string::npos);
b = stringToInt64("-123", result, pos);
test(b && result == -123 && pos == string::npos);
b = stringToInt64("0123", result, pos);
test(b && result == 83 && pos == string::npos);
b = stringToInt64("+0123", result, pos);
test(b && result == 83 && pos == string::npos);
b = stringToInt64("-0123", result, pos);
test(b && result == -83 && pos == string::npos);
b = stringToInt64("0x123", result, pos);
test(b && result == 291 && pos == string::npos);
b = stringToInt64("+0x123", result, pos);
test(b && result == 291 && pos == string::npos);
b = stringToInt64("-0x123", result, pos);
test(b && result == -291 && pos == string::npos);
b = stringToInt64(WS "123", result, pos);
test(b && result == 123 && pos == string::npos);
b = stringToInt64("123" WS, result, pos);
test(b && result == 123 && pos == string::npos);
b = stringToInt64(WS "123" WS, result, pos);
test(b && result == 123 && pos == string::npos);
b = stringToInt64("123Q", result, pos);
test(b && result == 123 && pos == 3);
b = stringToInt64(" 123Q", result, pos);
test(b && result == 123 && pos == 4);
b = stringToInt64(" 123Q ", result, pos);
test(b && result == 123 && pos == 4);
b = stringToInt64(" 123 Q", result, pos);
test(b && result == 123 && pos == 4);
b = stringToInt64("Q", result, pos);
test(!b && result == 0 && pos == 0);
b = stringToInt64(" Q", result, pos);
test(!b && result == 0 && pos == 1);
b = stringToInt64("-9223372036854775807", result, pos);
test(b && result == -9223372036854775807 && pos == string::npos);
b = stringToInt64("-9223372036854775808", result, pos);
test(b && result == Int64Min && pos == string::npos);
b = stringToInt64("-9223372036854775809", result, pos);
test(!b && result == Int64Min && pos == string::npos);
b = stringToInt64("9223372036854775806", result, pos);
test(b && result == 9223372036854775806 && pos == string::npos);
b = stringToInt64("9223372036854775807", result, pos);
test(b && result == Int64Max && pos == string::npos);
b = stringToInt64("9223372036854775808", result, pos);
test(!b && result == Int64Max && pos == string::npos);
b = stringToInt64("-9223372036854775807Q", result, pos);
test(b && result == -9223372036854775807 && pos == 20);
b = stringToInt64("-9223372036854775808Q", result, pos);
test(b && result == Int64Min && pos == 20);
b = stringToInt64("-9223372036854775809Q", result, pos);
test(!b && result == Int64Min && pos == 20);
b = stringToInt64("-9223372036854775809999Q", result, pos);
test(!b && result == Int64Min && pos == 23);
cout << "ok" << endl;
return EXIT_SUCCESS;
}
|