Debian Codegraph @

unittest/gunit/xplugin/xpl/xrow_buffer_t.cc

raw symbols SCIP
1 /* Copyright (c) 2016, 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 <gtest/gtest.h>
25 #include <stddef.h>
26
27 #include "plugin/x/protocol/encoders/encoding_xrow.h"
28 #include "plugin/x/src/ngs/protocol/protocol_protobuf.h"
29 #include "unittest/gunit/xplugin/xpl/encoder_validator.h"
30 #include "unittest/gunit/xplugin/xpl/protobuf_message.h"
31
32 namespace protocol {
33
34 namespace test {
35
36 class Row_encoder_validator_testsuite : public ::testing::Test {
37 public:
38 void TearDown() override {
39 if (!HasFatalFailure()) m_validator.summarize_buffer("Summarize field");
40 }
41
42 Encoder_validator m_validator;
43 protocol::XRow_encoder_base<Encoder_validator> m_encoder{&m_validator};
44 };
45
46 TEST_F(Row_encoder_validator_testsuite, encode_begin_end_row) {
47 m_validator.configure_allow_bigger_buffers(true);
48 m_encoder.begin_row();
49 m_encoder.end_row();
50 }
51
52 TEST_F(Row_encoder_validator_testsuite, encode_begin_abort_row) {
53 m_validator.configure_allow_bigger_buffers(true);
54 m_encoder.begin_row();
55 m_encoder.abort_row();
56 }
57
58 TEST_F(Row_encoder_validator_testsuite, encode_null) { m_encoder.field_null(); }
59
60 TEST_F(Row_encoder_validator_testsuite, encode_signed_longlong) {
61 m_encoder.field_signed_longlong(0);
62 }
63
64 TEST_F(Row_encoder_validator_testsuite, encode_unsigned_longlong) {
65 m_encoder.field_unsigned_longlong(0);
66 }
67
68 TEST_F(Row_encoder_validator_testsuite, encode_bit) {
69 m_encoder.field_bit("", 0);
70 }
71
72 TEST_F(Row_encoder_validator_testsuite, encode_set_empty) {
73 m_encoder.field_set("", 0);
74 }
75
76 TEST_F(Row_encoder_validator_testsuite, encode_set_one) {
77 m_encoder.field_set("one", 3);
78 }
79
80 TEST_F(Row_encoder_validator_testsuite, encode_set_two) {
81 m_encoder.field_set("one,two", 7);
82 }
83
84 TEST_F(Row_encoder_validator_testsuite, encode_string) {
85 m_encoder.field_string("one,two", 7);
86 }
87
88 TEST_F(Row_encoder_validator_testsuite, encode_datetime_empty) {
89 MYSQL_TIME date_time;
90 date_time.year = 0;
91 date_time.month = 0;
92 date_time.day = 0;
93 date_time.hour = 0;
94 date_time.minute = 0;
95 date_time.second = 0;
96 date_time.second_part = 0;
97 m_validator.configure_allow_bigger_buffers(true);
98
99 m_encoder.field_datetime(&date_time);
100 }
101
102 TEST_F(Row_encoder_validator_testsuite, encode_datetime) {
103 MYSQL_TIME date_time;
104 date_time.year = 2012;
105 date_time.month = 12;
106 date_time.day = 28;
107 date_time.hour = 23;
108 date_time.minute = 59;
109 date_time.second = 59;
110 date_time.second_part = 999999;
111
112 m_encoder.field_datetime(&date_time);
113 }
114
115 TEST_F(Row_encoder_validator_testsuite, encode_time_empty) {
116 MYSQL_TIME date_time;
117 date_time.neg = true;
118 date_time.hour = 0;
119 date_time.minute = 0;
120 date_time.second = 0;
121 date_time.second_part = 0;
122
123 m_validator.configure_allow_bigger_buffers(true);
124
125 m_encoder.field_time(&date_time);
126 }
127
128 TEST_F(Row_encoder_validator_testsuite, encode_time) {
129 MYSQL_TIME date_time;
130 date_time.neg = true;
131 date_time.hour = 23;
132 date_time.minute = 59;
133 date_time.second = 59;
134 date_time.second_part = 999999;
135
136 m_encoder.field_time(&date_time);
137 }
138
139 TEST_F(Row_encoder_validator_testsuite, encode_date) {
140 MYSQL_TIME date_time;
141 date_time.year = 2012;
142 date_time.month = 12;
143 date_time.day = 28;
144
145 m_encoder.field_date(&date_time);
146 }
147
148 TEST_F(Row_encoder_validator_testsuite, encode_float) {
149 m_encoder.field_float(0.0f);
150 }
151
152 TEST_F(Row_encoder_validator_testsuite, encode_double) {
153 m_encoder.field_double(0.0);
154 }
155
156 TEST_F(Row_encoder_validator_testsuite, encode_decimal) {
157 const char *k_value = "0.0001";
158 m_encoder.field_decimal(k_value, strlen(k_value));
159 }
160
161 TEST_F(Row_encoder_validator_testsuite, encode_decimal2) {
162 decimal_digit_t buffer[1000];
163 decimal_t d;
164 d.buf = buffer;
165 d.len = sizeof(buffer) / sizeof(buffer[0]);
166 const char *k_value = "0.0001";
167 const char *k_value_end = k_value + strlen(k_value);
168 ASSERT_EQ(E_DEC_OK, string2decimal(k_value, &d, &k_value_end));
169
170 m_encoder.field_decimal(&d);
171 }
172
173 } // namespace test
174
175 } // namespace protocol