1 /* Copyright (c) 2013, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
22
23 // First include (the generated) my_config.h, to get correct platform defines.
24 #include "my_config.h"
25 #include <gtest/gtest.h>
26 /*
27
28 ==== Purpose ====
29
30 Test if my_strtoll10 overflows values above unsigned long long
31 limit correctly.
32
33 ==== Related Bugs and Worklogs ====
34
35 BUG#16997513: MY_STRTOLL10 ACCEPTING OVERFLOWED UNSIGNED LONG LONG
36 VALUES AS NORMAL ONES
37
38 ==== Implementation ====
39
40 Check if my_strtoll10 returns the larger unsigned long long and raise
41 the overflow error when receiving a number like 18446744073709551915
42
43 */
44 #include <m_string.h>
45 #include <my_sys.h>
46
TEST(StringToULLTest,OverflowedNumber)47 TEST(StringToULLTest, OverflowedNumber)
48 {
49 unsigned long long number;
50 int error;
51 const char * str= "18446744073709551915";
52 number= my_strtoll10(str, 0, &error);
53 EXPECT_EQ(number, ULLONG_MAX);
54 EXPECT_EQ(error, MY_ERRNO_ERANGE);
55 }
56