blob: 3293c44d7487192d3419179253e03ee2ddcb5e05 [file] [log] [blame]
Amin Hassani7fca2862019-03-28 16:09:22 -07001//
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
23using std::string;
24
25namespace chromeos_update_engine {
26
27class OmahaRequestBuilderXmlTest : public ::testing::Test {};
28
29TEST_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&lt;b", output);
35 EXPECT_TRUE(XmlEncode("<&>\"\'\\", &output));
36 EXPECT_EQ("&lt;&amp;&gt;&quot;&apos;\\", output);
37 EXPECT_TRUE(XmlEncode("&lt;&amp;&gt;", &output));
38 EXPECT_EQ("&amp;lt;&amp;amp;&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
45TEST_F(OmahaRequestBuilderXmlTest, XmlEncodeWithDefaultTest) {
46 EXPECT_EQ("&lt;&amp;&gt;", XmlEncodeWithDefault("<&>", "something else"));
47 EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>"));
48}
49
50} // namespace chromeos_update_engine