MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
field_temporal_utils.h
1 /* Copyright (c) 2012, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 #ifndef FIELD_TEMPORAL_UTILS_INCLUDED
17 #define FIELD_TEMPORAL_UTILS_INCLUDED
18 
19 #include "field.h"
20 #include <gtest/gtest.h>
21 #include "test_utils.h"
22 
23 namespace {
24 
26 
27 void store_zero_in_sql_mode(Field_temporal *field,
28  const char *store_value, const int length,
29  const char *expected_result,
30  const type_conversion_status expect_status,
31  const sql_mode_t test_mode,
32  const uint expected_error_code)
33 {
34  THD *thd= field->table->in_use;
35  sql_mode_t save_mode= thd->variables.sql_mode;
36  thd->variables.sql_mode= test_mode;
37 
38  Mock_error_handler error_handler(thd, expected_error_code);
39  type_conversion_status err=
40  field->store(store_value, length, &my_charset_latin1);
41 
42  String unused;
43  String str;
44  field->val_str(&str, &unused);
45 
46  EXPECT_EQ(expect_status, err);
47  EXPECT_STREQ(expected_result, str.ptr());
48  EXPECT_EQ((expected_error_code == 0 ? 0 : 1),
49  error_handler.handle_called());
50 
51  thd->variables.sql_mode= save_mode;
52 }
53 
54 void test_store_string(Field_temporal *field,
55  const char *store_value, const int length,
56  const char *expected_result,
57  const int expected_error_no,
58  const type_conversion_status expected_status)
59 {
60  char buff[MAX_FIELD_WIDTH];
61  String str(buff, sizeof(buff), &my_charset_bin);
62  String unused;
63 
64  Mock_error_handler error_handler(field->table->in_use, expected_error_no);
65  type_conversion_status err= field->store(store_value, length,
66  &my_charset_latin1);
67  field->val_str(&str, &unused);
68  EXPECT_STREQ(expected_result, str.ptr());
69 
70  EXPECT_FALSE(field->is_null());
71  EXPECT_EQ(expected_status, err);
72  EXPECT_EQ((expected_error_no == 0 ? 0 : 1), error_handler.handle_called());
73 }
74 
75 
76 };
77 
78 
79 #endif // FIELD_TEMPORAL_UTILS_INCLUDED