17 #include "my_config.h"
18 #include <gtest/gtest.h>
21 #include "filesort_utils.h"
24 namespace filesort_buffer_unittest {
29 virtual void TearDown()
31 fs_info.free_sort_buffer();
32 std::pair<uint, uint> buffer_properties= fs_info.sort_buffer_properties();
33 EXPECT_EQ(0
U, buffer_properties.first);
34 EXPECT_EQ(0
U, buffer_properties.second);
35 EXPECT_TRUE(NULL == fs_info.get_sort_keys());
44 const char letters[10]=
"abcdefghi";
45 std::pair<uint, uint> buffer_properties= fs_info.sort_buffer_properties();
46 EXPECT_EQ(0
U, buffer_properties.first);
47 EXPECT_EQ(0
U, buffer_properties.second);
49 uchar **sort_keys= fs_info.alloc_sort_buffer(10,
sizeof(
char));
50 buffer_properties= fs_info.sort_buffer_properties();
51 EXPECT_EQ(10
U, buffer_properties.first);
52 EXPECT_EQ(
sizeof(
char), buffer_properties.second);
54 uchar **null_sort_keys= NULL;
55 EXPECT_NE(null_sort_keys, sort_keys);
56 EXPECT_NE(null_sort_keys, fs_info.get_sort_keys());
57 for (uint ix= 0; ix < 10; ++ix)
59 uchar *ptr= fs_info.get_record_buffer(ix);
62 uchar *data= *fs_info.get_sort_keys();
63 const char *str=
reinterpret_cast<const char*
>(data);
64 EXPECT_STREQ(letters, str);
66 const size_t expected_size= 10 * (
sizeof(
char*) +
sizeof(
char));
67 EXPECT_EQ(expected_size, fs_info.sort_buffer_size());
71 TEST_F(FileSortBufferTest, InitRecordPointers)
73 fs_info.alloc_sort_buffer(10,
sizeof(
char));
74 fs_info.init_record_pointers();
75 uchar **ptr= fs_info.get_sort_keys();
76 for (uint ix= 0; ix < 10 - 1; ++ix)
79 EXPECT_EQ(1, *nxt - *ptr);
85 TEST_F(FileSortBufferTest, AssignmentOperator)
87 fs_info.alloc_sort_buffer(10,
sizeof(
char));
90 for (uint ix= 0; ix < 10 - 1; ++ix)
94 EXPECT_EQ(fs_copy.get_sort_keys(), fs_info.get_sort_keys());
95 EXPECT_EQ(fs_copy.sort_buffer_size(), fs_info.sort_buffer_size());