Debian Codegraph @

unittest/gunit/field_temporal_utils.h

raw symbols SCIP
1 /* Copyright (c) 2012, 2026, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #ifndef FIELD_TEMPORAL_UTILS_INCLUDED
25 #define FIELD_TEMPORAL_UTILS_INCLUDED
26
27 #include <gtest/gtest.h>
28
29 #include "sql/field.h"
30 #include "unittest/gunit/test_utils.h"
31
32 namespace {
33
34 using my_testing::Mock_error_handler;
35
36 void store_zero_in_sql_mode(Field_temporal *field, const char *store_value,
37 const int length, const char *expected_result,
38 const type_conversion_status expect_status,
39 const sql_mode_t test_mode,
40 const uint expected_error_code) {
41 THD *thd = field->table->in_use;
42 sql_mode_t save_mode = thd->variables.sql_mode;
43 thd->variables.sql_mode = test_mode;
44
45 Mock_error_handler error_handler(thd, expected_error_code);
46 type_conversion_status err =
47 field->store(store_value, length, &my_charset_latin1);
48
49 String unused;
50 String str;
51 field->val_str(&str, &unused);
52
53 EXPECT_EQ(expect_status, err);
54 EXPECT_STREQ(expected_result, str.ptr());
55 EXPECT_EQ((expected_error_code == 0 ? 0 : 1), error_handler.handle_called());
56
57 thd->variables.sql_mode = save_mode;
58 }
59
60 void test_store_string(Field_temporal *field, const char *store_value,
61 const int length, const sql_mode_t modes,
62 const char *expected_result, const int expected_error_no,
63 const type_conversion_status expected_status) {
64 THD *thd = field->table->in_use;
65 sql_mode_t save_mode = thd->variables.sql_mode;
66 thd->variables.sql_mode = MODE_NO_ENGINE_SUBSTITUTION | modes;
67 char buff[MAX_FIELD_WIDTH];
68 String str(buff, sizeof(buff), &my_charset_bin);
69 String unused;
70
71 Mock_error_handler error_handler(field->table->in_use, expected_error_no);
72 type_conversion_status err =
73 field->store(store_value, length, &my_charset_latin1);
74 field->val_str(&str, &unused);
75 EXPECT_STREQ(expected_result, str.ptr());
76
77 EXPECT_FALSE(field->is_null());
78 EXPECT_EQ(expected_status, err);
79 EXPECT_EQ((expected_error_no == 0 ? 0 : 1), error_handler.handle_called());
80 thd->variables.sql_mode = save_mode;
81 }
82
83 } // namespace
84
85 #endif // FIELD_TEMPORAL_UTILS_INCLUDED