--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include <boost_macros_wrapper.h>
+#include <random>
+#include <string>
+#include "ckm/ckm-raw-buffer.h"
+#include "xml-utils.h"
+
+namespace {
+
+const std::string WHITECHAR_REMOVAL_INPUT =
+ "\t\v\r <some_tag> some_value </some_tag> \n\
+ <some_tag> some_value </some_tag> \t\v\r \n\
+ \t\v\r <some_tag> some_value </some_tag> \t\v\r \n\
+ \t\v\r \n\
+ ";
+
+const std::string WHITECHAR_REMOVAL_OUTPUT =
+ R"(<some_tag> some_value </some_tag>
+<some_tag> some_value </some_tag>
+<some_tag> some_value </some_tag>
+)";
+
+const std::string SINGLE_LINE_INPUT =
+ "\t\v\r <some_tag> some_value </some_tag> \t\v\r";
+
+const std::string SINGLE_LINE_OUTPUT =
+ "<some_tag>some_value</some_tag>";
+
+const std::string WHITECHARS = "\r\n\v\t ";
+
+bool contains_whitespace(const std::string& str) {
+ return str.find_first_of(WHITECHARS) != std::string::npos;
+}
+
+}
+
+BOOST_AUTO_TEST_SUITE(XML_UTILS_TEST)
+
+POSITIVE_TEST_CASE(TrimTest) {
+ BOOST_REQUIRE(CKM::XML::trimEachLine(WHITECHAR_REMOVAL_INPUT) == WHITECHAR_REMOVAL_OUTPUT);
+ BOOST_REQUIRE(CKM::XML::trim(SINGLE_LINE_INPUT) == SINGLE_LINE_OUTPUT);
+
+ const CKM::RawBuffer buffer_input(SINGLE_LINE_INPUT.begin(), SINGLE_LINE_INPUT.end());
+ const CKM::RawBuffer buffer_output(SINGLE_LINE_OUTPUT.begin(), SINGLE_LINE_OUTPUT.end());
+ const CKM::RawBuffer converted = CKM::XML::removeWhiteChars(buffer_input);
+ BOOST_REQUIRE(converted == buffer_output);
+}
+
+NEGATIVE_TEST_CASE(TrimTest) {
+ std::string raw_bytes;
+ for (unsigned int c=0; c < 0x100; ++c)
+ raw_bytes += static_cast<char>(c);
+
+ BOOST_REQUIRE(!contains_whitespace(CKM::XML::trim(raw_bytes)));
+
+ const std::size_t length = 0x1'000'000;
+ std::string long_random_string;
+ std::random_device rd;
+ std::uniform_int_distribution<> distb(0, 0x100);
+ for (std::size_t i=0; i < length; ++i)
+ long_random_string += static_cast<char>(distb(rd));
+ BOOST_REQUIRE(!contains_whitespace(CKM::XML::trim(long_random_string)));
+
+ BOOST_REQUIRE(CKM::XML::trim("") == "");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+