Debian Codegraph @

unittest/gunit/dd_table-t.cc

raw symbols SCIP
1 /* Copyright (c) 2013, 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 "my_config.h"
25
26 #include <gtest/gtest.h>
27 #include <memory>
28 #include <vector>
29
30 #include "sql/dd/dd.h"
31 #include "sql/dd/impl/types/table_impl.h"
32 #include "sql/dd/properties.h"
33 #include "sql/dd/types/column.h"
34
35 namespace dd_columns_unittest {
36
37 class ColumnsTest : public ::testing::Test {
38 protected:
39 typedef dd::Collection<dd::Column *> Column_collection;
40 Column_collection m_columns;
41 dd::Table_impl *m_table;
42
43 void SetUp() override {
44 m_table = dynamic_cast<dd::Table_impl *>(dd::create_object<dd::Table>());
45 }
46
47 void TearDown() override { delete m_table; }
48
49 dd::Column *add_column() { return m_table->add_column(); }
50
51 const dd::Column *get_column(dd::String_type name) {
52 return m_table->get_column(name);
53 }
54
55 const Column_collection &columns() { return *m_table->columns(); }
56
57 ColumnsTest() = default;
58
59 private:
60 ColumnsTest(ColumnsTest const &) = delete;
61 ColumnsTest &operator=(ColumnsTest const &) = delete;
62 };
63
64 TEST_F(ColumnsTest, ColumnsConstIterator) {
65 dd::Column *c1 = add_column();
66 c1->set_name("col1");
67
68 dd::Column *c2 = add_column();
69 c2->set_name("col2");
70
71 dd::Column *c3 = add_column();
72 c3->set_name("Col3");
73
74 dd::Column *c4 = add_column();
75 c4->set_name("col3");
76
77 dd::Column *c5 = add_column();
78 c5->set_name("col4");
79
80 const dd::Column *found_c3 = get_column("Col3");
81 // Column names are case insensitive
82 const dd::Column *found_c3_2 = get_column("col3");
83 const dd::Column *found_c5 = get_column("col4");
84
85 EXPECT_TRUE(found_c3 == c3);
86 EXPECT_TRUE(found_c3_2 == c3);
87 EXPECT_TRUE(found_c5 == c5);
88 }
89
90 TEST_F(ColumnsTest, Collection) {
91 dd::Column *c1 = add_column();
92 c1->set_name("col1");
93
94 dd::Column *c2 = add_column();
95 c2->set_name("col2");
96
97 dd::Column *c3 = add_column();
98 c3->set_name("Col3");
99
100 dd::Column *c4 = add_column();
101 c4->set_name("col3");
102
103 dd::Column *c5 = add_column();
104 c5->set_name("col4");
105
106 EXPECT_EQ(c1, columns().front());
107 EXPECT_EQ(c5, columns().back());
108 EXPECT_EQ(c1, columns()[0]);
109 EXPECT_EQ(c2, columns()[1]);
110 EXPECT_EQ(c3, columns()[2]);
111 EXPECT_EQ(c4, columns()[3]);
112 EXPECT_EQ(c5, columns()[4]);
113 }
114
115 } // namespace dd_columns_unittest