18 #include "my_config.h"
19 #include <gtest/gtest.h>
20 #include <gmock/gmock.h>
22 #include "mock_field_timestamp.h"
23 #include "fake_table.h"
24 #include "test_utils.h"
27 namespace copy_info_unittest {
32 using ::testing::StrictMock;
45 virtual void SetUp() { initializer.SetUp(); }
46 virtual void TearDown() { initializer.TearDown(); }
62 Field_long(NULL, 0, &null_byte, 0, unireg,
"",
false,
false)
79 EXPECT_EQ(a.error_count, b.error_count);
80 EXPECT_EQ(a.touched, b.touched);
92 enum_duplicates duplicate_handling,
119 COPY_INFO(COPY_INFO::INSERT_OPERATION, fields,
137 :
COPY_INFO(COPY_INFO::UPDATE_OPERATION, NULL, NULL)
152 COPY_INFO insert(COPY_INFO::INSERT_OPERATION,
158 EXPECT_EQ(0
U, insert.stats.records);
159 EXPECT_EQ(0
U, insert.stats.deleted);
160 EXPECT_EQ(0
U, insert.stats.updated);
161 EXPECT_EQ(0
U, insert.stats.copied);
162 EXPECT_EQ(0
U, insert.stats.error_count);
163 EXPECT_EQ(0
U, insert.stats.touched);
167 COPY_INFO update(COPY_INFO::UPDATE_OPERATION, &columns, &values);
169 EXPECT_EQ(0
U, update.stats.records);
170 EXPECT_EQ(0
U, update.stats.deleted);
171 EXPECT_EQ(0
U, update.stats.updated);
172 EXPECT_EQ(0
U, update.stats.copied);
173 EXPECT_EQ(0
U, update.stats.error_count);
174 EXPECT_EQ(0
U, update.stats.touched);
182 TEST_F(CopyInfoTest, insertAccessors)
186 COPY_INFO insert(COPY_INFO::INSERT_OPERATION,
192 EXPECT_EQ(COPY_INFO::INSERT_OPERATION, insert.get_operation_type());
193 EXPECT_EQ(&inserted_columns, insert.get_changed_columns());
194 EXPECT_EQ(
static_cast<List<Item>*
>(NULL), insert.get_changed_columns2());
195 EXPECT_TRUE(insert.get_manage_defaults());
196 EXPECT_EQ(DUP_REPLACE, insert.get_duplicate_handling());
197 EXPECT_TRUE(insert.get_ignore_errors());
205 TEST_F(CopyInfoTest, loadDataAccessors)
210 COPY_INFO load_data(COPY_INFO::INSERT_OPERATION,
218 EXPECT_EQ(COPY_INFO::INSERT_OPERATION, load_data.get_operation_type());
219 EXPECT_EQ(&inserted_columns, load_data.get_changed_columns());
220 EXPECT_EQ(&inserted_columns2, load_data.get_changed_columns2());
221 EXPECT_TRUE(load_data.get_manage_defaults());
222 EXPECT_EQ(DUP_UPDATE, load_data.get_duplicate_handling());
223 EXPECT_TRUE(load_data.get_ignore_errors());
230 TEST_F(CopyInfoTest, updateAccessors)
235 COPY_INFO update(COPY_INFO::UPDATE_OPERATION, &columns, &values);
237 EXPECT_EQ(COPY_INFO::UPDATE_OPERATION, update.get_operation_type());
238 EXPECT_EQ(&columns, update.get_changed_columns());
239 EXPECT_EQ(
static_cast<List<Item>*
>(NULL), update.get_changed_columns2());
240 EXPECT_TRUE(update.get_manage_defaults());
241 EXPECT_EQ(DUP_ERROR, update.get_duplicate_handling());
242 EXPECT_FALSE(update.get_ignore_errors());
248 static uchar unused_null_byte;
254 Field::TIMESTAMP_DN_FIELD,
275 TEST_F(CopyInfoTest, getFunctionDefaultColumns)
277 Mock_COPY_INFO_insert insert;
278 Mock_COPY_INFO_update update;
285 EXPECT_EQ(initial_value, insert.get_cached_bitmap());
287 insert.get_function_default_columns(&
table);
288 EXPECT_NE(initial_value, insert.get_cached_bitmap())
289 <<
"The output parameter must be set!";
291 const MY_BITMAP *function_default_columns= insert.get_cached_bitmap();
292 insert.get_function_default_columns(&
table);
293 EXPECT_EQ(function_default_columns, insert.get_cached_bitmap())
294 <<
"Not supposed to allocate a new bitmap on second call.";
296 EXPECT_EQ(initial_value, update.get_cached_bitmap());
297 update.get_function_default_columns(&
table);
298 EXPECT_NE(initial_value, update.get_cached_bitmap())
299 <<
"The output parameter must be set!";
301 function_default_columns= update.get_cached_bitmap();
302 update.get_function_default_columns(&
table);
303 EXPECT_EQ(function_default_columns, update.get_cached_bitmap())
304 <<
"Not supposed to allocate a new bitmap on second call.";
315 TEST_F(CopyInfoTest, setFunctionDefaults)
317 StrictMock<Mock_field> a(Field::TIMESTAMP_UN_FIELD);
318 StrictMock<Mock_field> b(Field::TIMESTAMP_DNUN_FIELD);
319 StrictMock<Mock_field> c(Field::TIMESTAMP_DNUN_FIELD);
321 EXPECT_TRUE(a.has_update_default_function());
322 EXPECT_TRUE(b.has_update_default_function());
323 EXPECT_TRUE(c.has_update_default_function());
328 assigned_columns.push_front(
new Item_field(&a));
330 Mock_COPY_INFO insert(COPY_INFO::INSERT_OPERATION,
335 ASSERT_FALSE(insert.get_function_default_columns(&
table)) <<
"Out of memory";
337 insert.ignore_last_columns(&
table, 1);
338 insert.add_function_default_columns(&
table,
table.write_set);
339 EXPECT_FALSE(bitmap_is_set(
table.write_set, 0));
340 EXPECT_TRUE (bitmap_is_set(
table.write_set, 1));
341 EXPECT_FALSE(bitmap_is_set(
table.write_set, 2));
343 EXPECT_TRUE(insert.function_defaults_apply(&
table)) <<
"They do apply";
347 EXPECT_CALL(b, store_timestamp(_)).Times(1);
348 EXPECT_CALL(c, store_timestamp(_)).Times(0);
349 insert.set_function_defaults(&
table);