Electroneum
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
36using namespace epee::string_tools;
37
38namespace
39{
40 template<typename T>
41 void do_pos_test(T expected, const std::string& str)
42 {
43 T val;
45 ASSERT_EQ(expected, val);
46 }
47
48 template<typename T>
49 void do_neg_test(const std::string& str)
50 {
51 T val;
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
73TEST_pos(uint16_t, 65535, "65535");
74
78TEST_neg(uint16_t, "+65535");
79TEST_neg(uint16_t, "+65536");
80
83TEST_neg(uint16_t, "-65535");
84TEST_neg(uint16_t, "-65536");
85
92
97TEST_neg(uint16_t, "65535w");
98
100TEST_neg(uint16_t, "4294967296");
101TEST_neg(uint16_t, "18446744073709551616");
102
103
106TEST_pos(uint32_t, 4294967295, "4294967295");
107
111TEST_neg(uint32_t, "+4294967295");
112TEST_neg(uint32_t, "+4294967296");
113
116TEST_neg(uint32_t, "-4294967295");
117TEST_neg(uint32_t, "-4294967296");
118
125
130TEST_neg(uint32_t, "4294967295w");
131
132TEST_neg(uint32_t, "4294967296");
133TEST_neg(uint32_t, "18446744073709551616");
134
137TEST_pos(uint64_t, 18446744073709551615ULL, "18446744073709551615");
138
142TEST_neg(uint64_t, "+18446744073709551615");
143TEST_neg(uint64_t, "+18446744073709551616");
144
147TEST_neg(uint64_t, "-18446744073709551615");
148TEST_neg(uint64_t, "-18446744073709551616");
149
156
161TEST_neg(uint64_t, "18446744073709551615w");
162
163TEST_neg(uint64_t, "18446744073709551616");
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1956
#define ASSERT_FALSE(condition)
Definition gtest.h:1868
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
#define TEST_neg(int_type, str)
#define TEST_pos(int_type, expected, str)
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
#define T(x)