| 1 | /* Copyright (c) 2020, 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 | #include <memory> |
| 25 | |
| 26 | #include <gtest/gtest.h> |
| 27 | |
| 28 | #include "sql/cmp_varlen_keys.h" |
| 29 | #include "sql/sort_param.h" |
| 30 | |
| 31 | namespace filesort_mergechunk_unittest { |
| 32 | |
| 33 | class FileSortMergeChunkTest : public ::testing::Test { |
| 34 | public: |
| 35 | void SetUp() override { |
| 36 | memset(&m_sort_field, 0, sizeof(m_sort_field)); |
| 37 | m_sort_field.is_varlen = true; |
| 38 | m_param.init_for_unittest(make_array(&m_sort_field, 1)); |
| 39 | m_mcg = std::make_unique<Merge_chunk_greater>(&m_param); |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | st_sort_field m_sort_field; |
| 44 | Sort_param m_param; |
| 45 | std::unique_ptr<Merge_chunk_greater> m_mcg; |
| 46 | }; |
| 47 | |
| 48 | TEST_F(FileSortMergeChunkTest, BasicCompareOperations) { |
| 49 | EXPECT_TRUE(m_param.using_varlen_keys()); |
| 50 | |
| 51 | uchar chunk_a_buf[10]; |
| 52 | uchar chunk_b_buf[10]; |
| 53 | |
| 54 | Merge_chunk chunk_a; |
| 55 | Merge_chunk chunk_b; |
| 56 | chunk_a.set_buffer_start(chunk_a_buf); |
| 57 | chunk_b.set_buffer_start(chunk_b_buf); |
| 58 | chunk_a.init_current_key(); |
| 59 | chunk_b.init_current_key(); |
| 60 | |
| 61 | int4store(chunk_a_buf + 4, 1 + VARLEN_PREFIX); |
| 62 | int4store(chunk_b_buf + 4, 1 + VARLEN_PREFIX); |
| 63 | chunk_a_buf[4 + VARLEN_PREFIX] = 1; |
| 64 | chunk_b_buf[4 + VARLEN_PREFIX] = 1; |
| 65 | |
| 66 | EXPECT_FALSE((*m_mcg)(&chunk_a, &chunk_b)); |
| 67 | EXPECT_FALSE((*m_mcg)(&chunk_b, &chunk_a)); |
| 68 | |
| 69 | chunk_a_buf[4 + VARLEN_PREFIX] = 0; |
| 70 | EXPECT_FALSE((*m_mcg)(&chunk_a, &chunk_b)); |
| 71 | EXPECT_TRUE((*m_mcg)(&chunk_b, &chunk_a)); |
| 72 | } |
| 73 | |
| 74 | } // namespace filesort_mergechunk_unittest |