Amin Hassani | 7fca286 | 2019-03-28 16:09:22 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2019 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include "update_engine/omaha_request_builder_xml.h" |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | #include <gtest/gtest.h> |
| 22 | |
| 23 | using std::string; |
| 24 | |
| 25 | namespace chromeos_update_engine { |
| 26 | |
| 27 | class OmahaRequestBuilderXmlTest : public ::testing::Test {}; |
| 28 | |
| 29 | TEST_F(OmahaRequestBuilderXmlTest, XmlEncodeTest) { |
| 30 | string output; |
| 31 | EXPECT_TRUE(XmlEncode("ab", &output)); |
| 32 | EXPECT_EQ("ab", output); |
| 33 | EXPECT_TRUE(XmlEncode("a<b", &output)); |
| 34 | EXPECT_EQ("a<b", output); |
| 35 | EXPECT_TRUE(XmlEncode("<&>\"\'\\", &output)); |
| 36 | EXPECT_EQ("<&>"'\\", output); |
| 37 | EXPECT_TRUE(XmlEncode("<&>", &output)); |
| 38 | EXPECT_EQ("&lt;&amp;&gt;", output); |
| 39 | // Check that unterminated UTF-8 strings are handled properly. |
| 40 | EXPECT_FALSE(XmlEncode("\xc2", &output)); |
| 41 | // Fail with invalid ASCII-7 chars. |
| 42 | EXPECT_FALSE(XmlEncode("This is an 'n' with a tilde: \xc3\xb1", &output)); |
| 43 | } |
| 44 | |
| 45 | TEST_F(OmahaRequestBuilderXmlTest, XmlEncodeWithDefaultTest) { |
| 46 | EXPECT_EQ("<&>", XmlEncodeWithDefault("<&>", "something else")); |
| 47 | EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>")); |
| 48 | } |
| 49 | |
| 50 | } // namespace chromeos_update_engine |