blob: f9030724b80be632372a99714c9b1fb1debbfc5c [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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 "SourceXmlPullParser.h"
18#include "XliffXmlPullParser.h"
19
20#include <gtest/gtest.h>
21#include <sstream>
22#include <string>
23
24namespace aapt {
25
26TEST(XliffXmlPullParserTest, IgnoreXliffTags) {
27 std::stringstream input;
28 input << "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << std::endl
29 << "<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">" << std::endl
30 << "<string name=\"foo\">"
31 << "Hey <xliff:g><xliff:it>there</xliff:it></xliff:g> world</string>" << std::endl
32 << "</resources>" << std::endl;
33 std::shared_ptr<XmlPullParser> sourceParser = std::make_shared<SourceXmlPullParser>(input);
34 XliffXmlPullParser parser(sourceParser);
35 EXPECT_EQ(XmlPullParser::Event::kStartDocument, parser.getEvent());
36
37 EXPECT_EQ(XmlPullParser::Event::kStartNamespace, parser.next());
38 EXPECT_EQ(parser.getNamespaceUri(), u"urn:oasis:names:tc:xliff:document:1.2");
39 EXPECT_EQ(parser.getNamespacePrefix(), u"xliff");
40
41 EXPECT_EQ(XmlPullParser::Event::kStartElement, parser.next());
42 EXPECT_EQ(parser.getElementNamespace(), u"");
43 EXPECT_EQ(parser.getElementName(), u"resources");
44 EXPECT_EQ(XmlPullParser::Event::kText, parser.next()); // Account for newline/whitespace.
45
46 EXPECT_EQ(XmlPullParser::Event::kStartElement, parser.next());
47 EXPECT_EQ(parser.getElementNamespace(), u"");
48 EXPECT_EQ(parser.getElementName(), u"string");
49
50 EXPECT_EQ(XmlPullParser::Event::kText, parser.next());
51 EXPECT_EQ(parser.getText(), u"Hey ");
52
53 EXPECT_EQ(XmlPullParser::Event::kText, parser.next());
54 EXPECT_EQ(parser.getText(), u"there");
55
56 EXPECT_EQ(XmlPullParser::Event::kText, parser.next());
57 EXPECT_EQ(parser.getText(), u" world");
58
59 EXPECT_EQ(XmlPullParser::Event::kEndElement, parser.next());
60 EXPECT_EQ(parser.getElementNamespace(), u"");
61 EXPECT_EQ(parser.getElementName(), u"string");
62 EXPECT_EQ(XmlPullParser::Event::kText, parser.next()); // Account for newline/whitespace.
63
64 EXPECT_EQ(XmlPullParser::Event::kEndElement, parser.next());
65 EXPECT_EQ(parser.getElementNamespace(), u"");
66 EXPECT_EQ(parser.getElementName(), u"resources");
67
68 EXPECT_EQ(XmlPullParser::Event::kEndNamespace, parser.next());
69 EXPECT_EQ(parser.getNamespacePrefix(), u"xliff");
70 EXPECT_EQ(parser.getNamespaceUri(), u"urn:oasis:names:tc:xliff:document:1.2");
71
72 EXPECT_EQ(XmlPullParser::Event::kEndDocument, parser.next());
73}
74
75} // namespace aapt