1 /* Copyright (c) 2012, 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 St, Fifth Floor, Boston, MA  02110-1301  USA */
22 
23 
24 // With PFS: get it from pfs_server_stubs.cc
25 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
26 extern "C" CHARSET_INFO *system_charset_info;
27 #else
28 CHARSET_INFO *system_charset_info= NULL;
29 #endif
30 
TEST(StringTest,EmptyString)31 TEST(StringTest, EmptyString)
32 {
33   String s;
34   const uint32 len= 0;
35   EXPECT_EQ(len, s.length());
36   EXPECT_EQ(len, s.alloced_length());
37 }
38 
39 
TEST(StringTest,ShrinkString)40 TEST(StringTest, ShrinkString)
41 {
42   const uint32 len= 3;
43   char foo[len]= {'a', 'b', 0};
44   String foos(foo, len, &my_charset_bin);
45   foos.shrink(1);
46   EXPECT_EQ(len, foos.length());
47   EXPECT_STREQ("ab", foo);
48 }
49 
50 
TEST(StringDeathTest,AppendEmptyString)51 TEST(StringDeathTest, AppendEmptyString)
52 {
53   ::testing::FLAGS_gtest_death_test_style = "threadsafe";
54   String tbl_name;
55   const char db_name[]= "aaaaaaa";
56   const char table_name[]= "";
57   tbl_name.append(String(db_name, system_charset_info));
58   tbl_name.append('.');
59   tbl_name.append(String(table_name, system_charset_info));
60   // We now have eight characters, c_ptr() is not safe.
61 #ifndef NDEBUG
62   MY_EXPECT_DEATH_IF_SUPPORTED(tbl_name.c_ptr(), ".*m_alloced_length >= .*");
63 #endif
64   EXPECT_STREQ("aaaaaaa.", tbl_name.c_ptr_safe());
65 }
66