| 1 | /* Copyright (c) 2021, 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 <algorithm> |
| 25 | #include <cctype> |
| 26 | #include <iostream> |
| 27 | #include <string> |
| 28 | |
| 29 | #include <gtest/gtest.h> |
| 30 | |
| 31 | #include "template_utils.h" |
| 32 | |
| 33 | namespace component_load_parser_unittest { |
| 34 | |
| 35 | class ComponentLoadParser_test : public ::testing::Test {}; |
| 36 | |
| 37 | std::string group_separator = ";"; |
| 38 | std::string component_separator = ","; |
| 39 | |
| 40 | void get_next_group(std::string &groups, std::string &one_group) { |
| 41 | if (groups.find(group_separator) != std::string::npos) { |
| 42 | one_group = groups.substr(0, groups.find(group_separator)); |
| 43 | groups.erase(0, groups.find(group_separator) + 1); |
| 44 | } else { |
| 45 | one_group = groups; |
| 46 | groups.clear(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void get_next_component(std::string &components, std::string &one_component) { |
| 51 | if (components.find(component_separator) != std::string::npos) { |
| 52 | one_component = components.substr(0, components.find(component_separator)); |
| 53 | components.erase(0, components.find(component_separator) + 1); |
| 54 | } else { |
| 55 | one_component = components; |
| 56 | components.clear(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Use myu::IsSpace rather than ::isspace to avoid linker warnings on MacOS. |
| 61 | void remove_spaces(std::string &groups) { |
| 62 | groups.erase(std::remove_if(groups.begin(), groups.end(), myu::IsSpace), |
| 63 | groups.end()); |
| 64 | } |
| 65 | |
| 66 | TEST_F(ComponentLoadParser_test, Parser) { |
| 67 | std::string with_spaces = |
| 68 | " file://component1, file://component2, file://component3; " |
| 69 | "file://component4, file://component5, file://component6 ; "; |
| 70 | std::string without_spaces = |
| 71 | "file://component1,file://component2,file://component3;file://" |
| 72 | "component4,file://component5,file://component6;"; |
| 73 | ; |
| 74 | remove_spaces(with_spaces); |
| 75 | EXPECT_TRUE(with_spaces == without_spaces); |
| 76 | EXPECT_TRUE(with_spaces == without_spaces); |
| 77 | } |
| 78 | |
| 79 | } // namespace component_load_parser_unittest |