FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
livecode/libfoundation/test/test_typeconvert.cpp at develop · livecode/livecode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
livecode
/
livecode
Public archive
Notifications
You must be signed in to change notification settings
Fork
223
Star
517
Code
Pull requests
189
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
livecode
/
libfoundation
/
test
/
test_typeconvert.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
127 lines (104 loc) · 3.46 KB
Breadcrumbs
livecode
/
libfoundation
/
test
/
test_typeconvert.cpp
Copy path
File metadata and controls
127 lines (104 loc) · 3.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
-*-C++-*-
* Copyright (C) 2016 LiveCode Ltd.
*
* This file is part of LiveCode.
*
* LiveCode is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License v3 as published
* by the Free Software Foundation.
*
* LiveCode is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiveCode. If not see
* <http://www.gnu.org/licenses/>.
*/
#
include
"
gtest/gtest.h
"
#
include
"
foundation.h
"
#
include
"
foundation-auto.h
"
TEST
(typeconvert, narrowcast)
{
/*
MCNarrowCast never does any checking
*/
EXPECT_EQ
(MCNarrowCast<
int
>(
4.0
),
4
);
EXPECT_EQ
(MCNarrowCast<
int
>(
4.5
),
4
);
}
TEST
(typeconvert, narrow)
{
uint8_t
dummy_uint8_t
=
0
;
EXPECT_TRUE
(
MCNarrow
(
INT8_MAX
,
dummy_uint8_t
));
EXPECT_EQ
(
dummy_uint8_t
,
INT8_MAX
);
EXPECT_FALSE
(
MCNarrow
(
UINT8_MAX
+
1
,
dummy_uint8_t
));
EXPECT_EQ
(
dummy_uint8_t
,
INT8_MAX
);
/*
Unmodified
*/
EXPECT_FALSE
(
MCNarrow
(
INT8_MIN
,
dummy_uint8_t
));
EXPECT_EQ
(
dummy_uint8_t
,
INT8_MAX
);
/*
Unmodified
*/
int
dummy_int_t
=
0
;
EXPECT_TRUE
(
MCNarrow
(
3.0
,
dummy_int_t
));
EXPECT_EQ
(
dummy_int_t
,
3
);
EXPECT_FALSE
(
MCNarrow
(-
1.5
,
dummy_int_t
));
EXPECT_EQ
(
dummy_int_t
,
3
);
/*
Unmodified
*/
}
TEST
(typeconvert, string_integer)
//
//
Checks string-to-integer conversion
//
{
integer_t
t_value;
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToLongInteger
(
kMCEmptyString
, t_value));
EXPECT_EQ
(t_value,
0
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
42
"
), t_value));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
0x42
"
), t_value));
EXPECT_EQ
(t_value,
0x42
);
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
42 43
"
), t_value));
EXPECT_EQ
(t_value,
0
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
42
"
), t_value));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
+42
"
), t_value));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
-42
"
), t_value));
EXPECT_EQ
(t_value, -
42
);
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToLongInteger
(
MCSTR
(
"
0x
"
), t_value));
EXPECT_EQ
(t_value,
0
);
}
TEST
(typeconvert, string_real)
//
//
Checks string-to-integer conversion
//
{
real64_t
t_value;
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToReal
(
kMCEmptyString
, t_value,
false
));
EXPECT_EQ
(t_value,
0
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
42
"
), t_value,
false
));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
0x42
"
), t_value,
false
));
EXPECT_EQ
(t_value,
0x42
);
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
42 43
"
), t_value,
false
));
EXPECT_EQ
(t_value,
0
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
42
"
), t_value,
false
));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
+42
"
), t_value,
false
));
EXPECT_EQ
(t_value,
42
);
t_value =
0
;
EXPECT_TRUE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
-42
"
), t_value,
false
));
EXPECT_EQ
(t_value, -
42
);
t_value =
0
;
EXPECT_FALSE
(
MCTypeConvertStringToReal
(
MCSTR
(
"
0x
"
), t_value,
false
));
EXPECT_EQ
(t_value,
0
);
}
Back
|
FazBrowse Home
|
New Git URL