17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "field_temporal_utils.h"
21 #include "test_utils.h"
22 #include "fake_table.h"
26 namespace field_date_unittests {
34 virtual void SetUp() { initializer.SetUp(); }
35 virtual void TearDown() { initializer.TearDown(); }
37 THD *thd() {
return initializer.thd(); }
44 static const int no_modes= 4;
45 static const sql_mode_t strict_modes[no_modes];
47 static const type_conversion_status nozero_expected_status[];
50 const sql_mode_t FieldDateTest::strict_modes[no_modes]=
53 MODE_STRICT_TRANS_TABLES,
54 MODE_STRICT_ALL_TABLES,
55 MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES
58 const type_conversion_status FieldDateTest::nozero_expected_status[]=
60 TYPE_NOTE_TIME_TRUNCATED,
70 uchar buffer[PACK_LENGTH];
77 memset(buffer, 0, PACK_LENGTH);
92 void make_writable() { bitmap_set_bit(table->write_set, field_index); }
101 field_date.make_writable();
105 test_store_string(&field_date, STRING_WITH_LEN(
"2001-01-01"),
106 "2001-01-01", 0, TYPE_OK);
110 test_store_string(&field_date, STRING_WITH_LEN(
"0000-00-00"),
111 "0000-00-00", 0, TYPE_OK);
115 test_store_string(&field_date, STRING_WITH_LEN(
"0001-00-00"),
116 "0001-00-00", 0, TYPE_OK);
120 TEST_F(FieldDateTest, StoreIllegalStringValues)
122 Mock_field_date field_date;
125 field_date.make_writable();
126 thd()->count_cuted_fields= CHECK_FIELD_WARN;
131 test_store_string(&field_date, STRING_WITH_LEN(
"2001-01-01 00:00:01"),
133 WARN_DATA_TRUNCATED, TYPE_NOTE_TIME_TRUNCATED);
139 test_store_string(&field_date, STRING_WITH_LEN(
"99999-01-01"),
141 WARN_DATA_TRUNCATED, TYPE_ERR_BAD_VALUE);
147 test_store_string(&field_date, STRING_WITH_LEN(
"2001-13-01"),
"0000-00-00",
148 WARN_DATA_TRUNCATED, TYPE_ERR_BAD_VALUE);
154 test_store_string(&field_date, STRING_WITH_LEN(
"2001-01-32"),
"0000-00-00",
155 WARN_DATA_TRUNCATED, TYPE_ERR_BAD_VALUE);
161 test_store_string(&field_date, STRING_WITH_LEN(
"foo"),
"0000-00-00",
162 WARN_DATA_TRUNCATED, TYPE_ERR_BAD_VALUE);
175 TEST_F(FieldDateTest, StoreZeroDateSqlModeNoZeroRestrictions)
177 Mock_field_date field_date;
180 field_date.make_writable();
181 thd()->count_cuted_fields= CHECK_FIELD_WARN;
183 for (
int i= 0;
i < no_modes;
i++)
186 store_zero_in_sql_mode(&field_date, STRING_WITH_LEN(
"0000-00-00"),
187 "0000-00-00", TYPE_OK, strict_modes[
i], 0);
190 for (
int i= 0;
i < no_modes;
i++)
193 store_zero_in_sql_mode(&field_date, STRING_WITH_LEN(
"0000-01-01"),
194 "0000-01-01", TYPE_OK, strict_modes[
i], 0);
198 for (
int i= 0;
i < no_modes;
i++)
201 store_zero_in_sql_mode(&field_date, STRING_WITH_LEN(
"2001-00-01"),
202 "2001-00-01", TYPE_OK, strict_modes[
i], 0);
206 for (
int i= 0;
i < no_modes;
i++)
209 store_zero_in_sql_mode(&field_date, STRING_WITH_LEN(
"2001-01-00"),
210 "2001-01-00", TYPE_OK, strict_modes[
i], 0);
222 TEST_F(FieldDateTest, StoreZeroDateSqlModeNoZeroDate)
224 Mock_field_date field_date;
227 field_date.make_writable();
228 thd()->count_cuted_fields= CHECK_FIELD_WARN;
231 for (
int i= 0;
i < no_modes;
i++)
234 store_zero_in_sql_mode(&field_date,
235 STRING_WITH_LEN(
"0000-00-00"),
237 nozero_expected_status[
i],
238 MODE_NO_ZERO_DATE | strict_modes[i],
239 ER_WARN_DATA_OUT_OF_RANGE);
243 for (
int i= 0;
i < no_modes;
i++)
246 store_zero_in_sql_mode(&field_date,
247 STRING_WITH_LEN(
"0000-01-01"),
250 MODE_NO_ZERO_DATE | strict_modes[
i],
254 for (
int i= 0;
i < no_modes;
i++)
257 store_zero_in_sql_mode(&field_date,
258 STRING_WITH_LEN(
"2001-00-01"),
261 MODE_NO_ZERO_DATE | strict_modes[
i],
265 for (
int i= 0;
i < no_modes;
i++)
268 store_zero_in_sql_mode(&field_date,
269 STRING_WITH_LEN(
"2001-01-00"),
272 MODE_NO_ZERO_DATE | strict_modes[
i],
283 TEST_F(FieldDateTest, StoreZeroDateSqlModeNoZeroInDate)
285 Mock_field_date field_date;
288 field_date.make_writable();
289 thd()->count_cuted_fields= CHECK_FIELD_WARN;
292 for (
int i= 0;
i < no_modes;
i++)
295 store_zero_in_sql_mode(&field_date,
296 STRING_WITH_LEN(
"0000-00-00"),
299 MODE_NO_ZERO_IN_DATE | strict_modes[
i],
304 for (
int i= 0;
i < no_modes;
i++)
307 store_zero_in_sql_mode(&field_date,
308 STRING_WITH_LEN(
"0000-01-01"),
311 MODE_NO_ZERO_IN_DATE | strict_modes[
i],
316 for (
int i= 0;
i < no_modes;
i++)
319 store_zero_in_sql_mode(&field_date,
320 STRING_WITH_LEN(
"2001-00-01"),
322 nozero_expected_status[
i],
323 MODE_NO_ZERO_IN_DATE | strict_modes[i],
324 ER_WARN_DATA_OUT_OF_RANGE);
328 for (
int i= 0;
i < no_modes;
i++)
331 store_zero_in_sql_mode(&field_date,
332 STRING_WITH_LEN(
"2001-01-00"),
334 nozero_expected_status[
i],
335 MODE_NO_ZERO_IN_DATE | strict_modes[i],
336 ER_WARN_DATA_OUT_OF_RANGE);