MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string-tests.cc
1 /* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 /*
17  Common tests for client/sql_string and sql/sql_string.
18  TODO: Why do we have two versions of String?
19  */
20 
21 
22 CHARSET_INFO *system_charset_info= NULL;
23 
24 TEST(StringTest, EmptyString)
25 {
26  String s;
27  const uint32 len= 0;
28  EXPECT_EQ(len, s.length());
29  EXPECT_EQ(len, s.alloced_length());
30 }
31 
32 
33 TEST(StringTest, ShrinkString)
34 {
35  const uint32 len= 3;
36  char foo[len]= {'a', 'b', 0};
37  String foos(foo, len, &my_charset_bin);
38  foos.shrink(1);
39  EXPECT_EQ(len, foos.length());
40  EXPECT_STREQ("ab", foo);
41 }
42 
43 
44 TEST(StringDeathTest, AppendEmptyString)
45 {
46  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
47  String tbl_name;
48  const char db_name[]= "aaaaaaa";
49  const char table_name[]= "";
50  tbl_name.append(String(db_name, system_charset_info));
51  tbl_name.append('.');
52  tbl_name.append(String(table_name, system_charset_info));
53  // We now have eight characters, c_ptr() is not safe.
54 #ifndef DBUG_OFF
55  EXPECT_DEATH_IF_SUPPORTED(tbl_name.c_ptr(), ".*Alloced_length >= .*");
56 #endif
57  EXPECT_STREQ("aaaaaaa.", tbl_name.c_ptr_safe());
58 }