| 1 |
/* Copyright (c) 2018, 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 |
|
| 25 |
#include <gtest/gtest.h> |
| 26 |
#include <string> |
| 27 |
#include <vector> |
| 28 |
#include "plugin/group_replication/include/mysql_version_gcs_protocol_map.h" |
| 29 |
|
| 30 |
namespace mysql_version_gcs_protocol_map_unittest { |
| 31 |
|
| 32 |
class MysqlVerGcsProtoMapTest : public ::testing::Test { |
| 33 |
public: |
| 34 |
MysqlVerGcsProtoMapTest() = default; |
| 35 |
}; |
| 36 |
|
| 37 |
TEST_F(MysqlVerGcsProtoMapTest, ParseMysqlVersionInvalidFormat) { |
| 38 |
std::vector<std::string> versions = { |
| 39 |
"", "a", "5", ".", "..", "5..", "5.7.", |
| 40 |
"5.7.14.", "5.7.100", " 5.7.14", "5.7.14 ", " 5.7.14 ", "5 .7.14"}; |
| 41 |
for (auto const &version : versions) { |
| 42 |
bool valid = valid_mysql_version_string(version.c_str()); |
| 43 |
ASSERT_FALSE(valid); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
TEST_F(MysqlVerGcsProtoMapTest, ParseMysqlVersionValidFormat) { |
| 48 |
std::vector<std::string> versions = {"5.7.14", "8.0.16", "00.00.00", |
| 49 |
"99.99.99"}; |
| 50 |
for (auto const &version : versions) { |
| 51 |
bool valid = valid_mysql_version_string(version.c_str()); |
| 52 |
ASSERT_TRUE(valid); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
TEST_F(MysqlVerGcsProtoMapTest, ConvertToMemberVersion) { |
| 57 |
std::vector<Member_version> versions = { |
| 58 |
Member_version(0x050714), Member_version(0x080015), |
| 59 |
Member_version(0x000000), Member_version(0x999999)}; |
| 60 |
for (auto const &version : versions) { |
| 61 |
Member_version member_version = |
| 62 |
convert_to_member_version(version.get_version_string().c_str()); |
| 63 |
ASSERT_EQ(version, member_version); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
TEST_F(MysqlVerGcsProtoMapTest, ConvertToMysqlVersion) { |
| 68 |
std::vector<std::pair<Gcs_protocol_version, Member_version>> versions = { |
| 69 |
{Gcs_protocol_version::V1, Member_version(0x050714)}, |
| 70 |
{Gcs_protocol_version::V2, Member_version(0x080016)}, |
| 71 |
{Gcs_protocol_version::V3, Member_version(0x080027)}}; |
| 72 |
for (auto const &version_pair : versions) { |
| 73 |
Member_version member_version = |
| 74 |
convert_to_mysql_version(version_pair.first); |
| 75 |
ASSERT_EQ(version_pair.second, member_version); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
TEST_F(MysqlVerGcsProtoMapTest, ConvertToGcsProtocol) { |
| 80 |
std::vector<std::pair<Member_version, Gcs_protocol_version>> versions = { |
| 81 |
{Member_version(0x050714), Gcs_protocol_version::V1}, |
| 82 |
{Member_version(0x080015), Gcs_protocol_version::V1}, |
| 83 |
{Member_version(0x080016), Gcs_protocol_version::V2}, |
| 84 |
{Member_version(0x080027), Gcs_protocol_version::V3}}; |
| 85 |
for (auto const &version_pair : versions) { |
| 86 |
Gcs_protocol_version gcs_protocol = |
| 87 |
convert_to_gcs_protocol(version_pair.first, Member_version(0x080027)); |
| 88 |
ASSERT_EQ(version_pair.second, gcs_protocol); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
} // namespace mysql_version_gcs_protocol_map_unittest |