Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
get_xtype_from_string.cpp
Go to the documentation of this file.
1
// Copyrights(c) 2017-2021, The Electroneum Project
2
// Copyrights(c) 2014-2019, The Monero Project
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without modification, are
7
// permitted provided that the following conditions are met:
8
//
9
// 1. Redistributions of source code must retain the above copyright notice, this list of
10
// conditions and the following disclaimer.
11
//
12
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
13
// of conditions and the following disclaimer in the documentation and/or other
14
// materials provided with the distribution.
15
//
16
// 3. Neither the name of the copyright holder nor the names of its contributors may be
17
// used to endorse or promote products derived from this software without specific
18
// prior written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
//
30
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31
32
#include "gtest/gtest.h"
33
34
#include <
string_tools.h
>
35
36
using namespace
epee::string_tools
;
37
38
namespace
39
{
40
template
<
typename
T>
41
void
do_pos_test(
T
expected,
const
std::string& str)
42
{
43
T
val;
44
ASSERT_TRUE
(
get_xtype_from_string
(val, str));
45
ASSERT_EQ
(expected, val);
46
}
47
48
template
<
typename
T>
49
void
do_neg_test(
const
std::string& str)
50
{
51
T
val;
52
ASSERT_FALSE
(
get_xtype_from_string
(val, str));
53
}
54
}
55
56
#define TEST_pos(int_type, expected, str) \
57
TEST(get_xtype_from_string, handles_pos_ ## int_type ## _ ## expected) \
58
{ \
59
do_pos_test<int_type>(expected, str); \
60
}
61
62
#define DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) prefix ## int_type ## _ ## ln
63
#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln)
64
65
#define TEST_neg(int_type, str) \
66
TEST(get_xtype_from_string, MAKE_NEG_TEST_NAME(handles_neg, int_type, __LINE__)) \
67
{ \
68
do_neg_test<int_type>(str); \
69
}
70
71
TEST_pos
(
uint16_t
, 0,
"0"
);
72
TEST_pos
(
uint16_t
, 1,
"1"
);
73
TEST_pos
(
uint16_t
, 65535,
"65535"
);
74
75
TEST_neg
(
uint16_t
,
""
);
76
TEST_neg
(
uint16_t
,
"+0"
);
77
TEST_neg
(
uint16_t
,
"+1"
);
78
TEST_neg
(
uint16_t
,
"+65535"
);
79
TEST_neg
(
uint16_t
,
"+65536"
);
80
81
TEST_neg
(
uint16_t
,
"-0"
);
82
TEST_neg
(
uint16_t
,
"-1"
);
83
TEST_neg
(
uint16_t
,
"-65535"
);
84
TEST_neg
(
uint16_t
,
"-65536"
);
85
86
TEST_neg
(
uint16_t
,
".0"
);
87
TEST_neg
(
uint16_t
,
".1"
);
88
TEST_neg
(
uint16_t
,
"0.0"
);
89
TEST_neg
(
uint16_t
,
"0.1"
);
90
TEST_neg
(
uint16_t
,
"1.0"
);
91
TEST_neg
(
uint16_t
,
"1.1"
);
92
93
TEST_neg
(
uint16_t
,
"w"
);
94
TEST_neg
(
uint16_t
,
"0w"
);
95
TEST_neg
(
uint16_t
,
"1w"
);
96
TEST_neg
(
uint16_t
,
"1w1"
);
97
TEST_neg
(
uint16_t
,
"65535w"
);
98
99
TEST_neg
(
uint16_t
,
"65536"
);
100
TEST_neg
(
uint16_t
,
"4294967296"
);
101
TEST_neg
(
uint16_t
,
"18446744073709551616"
);
102
103
104
TEST_pos
(
uint32_t
, 0,
"0"
);
105
TEST_pos
(
uint32_t
, 1,
"1"
);
106
TEST_pos
(
uint32_t
, 4294967295,
"4294967295"
);
107
108
TEST_neg
(
uint32_t
,
""
);
109
TEST_neg
(
uint32_t
,
"+0"
);
110
TEST_neg
(
uint32_t
,
"+1"
);
111
TEST_neg
(
uint32_t
,
"+4294967295"
);
112
TEST_neg
(
uint32_t
,
"+4294967296"
);
113
114
TEST_neg
(
uint32_t
,
"-0"
);
115
TEST_neg
(
uint32_t
,
"-1"
);
116
TEST_neg
(
uint32_t
,
"-4294967295"
);
117
TEST_neg
(
uint32_t
,
"-4294967296"
);
118
119
TEST_neg
(
uint32_t
,
".0"
);
120
TEST_neg
(
uint32_t
,
".1"
);
121
TEST_neg
(
uint32_t
,
"0.0"
);
122
TEST_neg
(
uint32_t
,
"0.1"
);
123
TEST_neg
(
uint32_t
,
"1.0"
);
124
TEST_neg
(
uint32_t
,
"1.1"
);
125
126
TEST_neg
(
uint32_t
,
"w"
);
127
TEST_neg
(
uint32_t
,
"0w"
);
128
TEST_neg
(
uint32_t
,
"1w"
);
129
TEST_neg
(
uint32_t
,
"1w1"
);
130
TEST_neg
(
uint32_t
,
"4294967295w"
);
131
132
TEST_neg
(
uint32_t
,
"4294967296"
);
133
TEST_neg
(
uint32_t
,
"18446744073709551616"
);
134
135
TEST_pos
(
uint64_t
, 0,
"0"
);
136
TEST_pos
(
uint64_t
, 1,
"1"
);
137
TEST_pos
(
uint64_t
, 18446744073709551615ULL,
"18446744073709551615"
);
138
139
TEST_neg
(
uint64_t
,
""
);
140
TEST_neg
(
uint64_t
,
"+0"
);
141
TEST_neg
(
uint64_t
,
"+1"
);
142
TEST_neg
(
uint64_t
,
"+18446744073709551615"
);
143
TEST_neg
(
uint64_t
,
"+18446744073709551616"
);
144
145
TEST_neg
(
uint64_t
,
"-0"
);
146
TEST_neg
(
uint64_t
,
"-1"
);
147
TEST_neg
(
uint64_t
,
"-18446744073709551615"
);
148
TEST_neg
(
uint64_t
,
"-18446744073709551616"
);
149
150
TEST_neg
(
uint64_t
,
".0"
);
151
TEST_neg
(
uint64_t
,
".1"
);
152
TEST_neg
(
uint64_t
,
"0.0"
);
153
TEST_neg
(
uint64_t
,
"0.1"
);
154
TEST_neg
(
uint64_t
,
"1.0"
);
155
TEST_neg
(
uint64_t
,
"1.1"
);
156
157
TEST_neg
(
uint64_t
,
"w"
);
158
TEST_neg
(
uint64_t
,
"0w"
);
159
TEST_neg
(
uint64_t
,
"1w"
);
160
TEST_neg
(
uint64_t
,
"1w1"
);
161
TEST_neg
(
uint64_t
,
"18446744073709551615w"
);
162
163
TEST_neg
(
uint64_t
,
"18446744073709551616"
);
ASSERT_EQ
#define ASSERT_EQ(val1, val2)
Definition
gtest.h:1956
ASSERT_FALSE
#define ASSERT_FALSE(condition)
Definition
gtest.h:1868
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition
gtest.h:1865
TEST_neg
#define TEST_neg(int_type, str)
Definition
get_xtype_from_string.cpp:65
TEST_pos
#define TEST_pos(int_type, expected, str)
Definition
get_xtype_from_string.cpp:56
epee::string_tools
Definition
string_tools.h:85
epee::string_tools::get_xtype_from_string
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
Definition
string_tools.h:125
uint16_t
unsigned short uint16_t
Definition
stdint.h:125
uint32_t
unsigned int uint32_t
Definition
stdint.h:126
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
string_tools.h
T
#define T(x)
tests
unit_tests
get_xtype_from_string.cpp
Generated on
for Electroneum by
1.17.0