summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceParser_test.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-09-15 16:57:21 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-09-15 16:57:21 +0000
commite33de76a16f6acc42858766460976f44e629657d (patch)
treece962def3f718730407e6863a14aaf0df9a66787 /tools/aapt2/ResourceParser_test.cpp
parentd2d6c257f141ed38da2cf0d0a2f84c6f7f055e92 (diff)
parente02983681ae85212c2263055fd4bcfd8097f19bc (diff)
Merge changes Id8bdb14e,I573a6735,Ia804777f,Ia68122cb,Ia1997800, ... into oc-mr1-dev
am: e02983681a Change-Id: I42369e6fb7bd121e45b5a002cd5f00e05221ead3
Diffstat (limited to 'tools/aapt2/ResourceParser_test.cpp')
-rw-r--r--tools/aapt2/ResourceParser_test.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/tools/aapt2/ResourceParser_test.cpp b/tools/aapt2/ResourceParser_test.cpp
index 1683c64a6a5c..144ebd22e105 100644
--- a/tools/aapt2/ResourceParser_test.cpp
+++ b/tools/aapt2/ResourceParser_test.cpp
@@ -22,9 +22,11 @@
#include "ResourceTable.h"
#include "ResourceUtils.h"
#include "ResourceValues.h"
+#include "io/StringInputStream.h"
#include "test/Test.h"
#include "xml/XmlPullParser.h"
+using ::aapt::io::StringInputStream;
using ::aapt::test::StrValueEq;
using ::aapt::test::ValueEq;
using ::android::ResTable_map;
@@ -43,11 +45,13 @@ constexpr const char* kXmlPreamble = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
TEST(ResourceParserSingleTest, FailToParseWithNoRootResourcesElement) {
std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build();
- std::stringstream input(kXmlPreamble);
- input << R"(<attr name="foo"/>)" << std::endl;
ResourceTable table;
ResourceParser parser(context->GetDiagnostics(), &table, Source{"test"}, {});
- xml::XmlPullParser xml_parser(input);
+
+ std::string input = kXmlPreamble;
+ input += R"(<attr name="foo"/>)";
+ StringInputStream in(input);
+ xml::XmlPullParser xml_parser(&in);
ASSERT_FALSE(parser.Parse(&xml_parser));
}
@@ -62,12 +66,16 @@ class ResourceParserTest : public ::testing::Test {
}
::testing::AssertionResult TestParse(const StringPiece& str, const ConfigDescription& config) {
- std::stringstream input(kXmlPreamble);
- input << "<resources>\n" << str << "\n</resources>" << std::endl;
ResourceParserOptions parserOptions;
ResourceParser parser(context_->GetDiagnostics(), &table_, Source{"test"}, config,
parserOptions);
- xml::XmlPullParser xmlParser(input);
+
+ std::string input = kXmlPreamble;
+ input += "<resources>\n";
+ input.append(str.data(), str.size());
+ input += "\n</resources>";
+ StringInputStream in(input);
+ xml::XmlPullParser xmlParser(&in);
if (parser.Parse(&xmlParser)) {
return ::testing::AssertionSuccess();
}
@@ -532,11 +540,11 @@ TEST_F(ResourceParserTest, ParseArray) {
Array* array = test::GetValue<Array>(&table_, "array/foo");
ASSERT_THAT(array, NotNull());
- ASSERT_THAT(array->items, SizeIs(3));
+ ASSERT_THAT(array->elements, SizeIs(3));
- EXPECT_THAT(ValueCast<Reference>(array->items[0].get()), NotNull());
- EXPECT_THAT(ValueCast<String>(array->items[1].get()), NotNull());
- EXPECT_THAT(ValueCast<BinaryPrimitive>(array->items[2].get()), NotNull());
+ EXPECT_THAT(ValueCast<Reference>(array->elements[0].get()), NotNull());
+ EXPECT_THAT(ValueCast<String>(array->elements[1].get()), NotNull());
+ EXPECT_THAT(ValueCast<BinaryPrimitive>(array->elements[2].get()), NotNull());
}
TEST_F(ResourceParserTest, ParseStringArray) {
@@ -557,9 +565,9 @@ TEST_F(ResourceParserTest, ParseArrayWithFormat) {
Array* array = test::GetValue<Array>(&table_, "array/foo");
ASSERT_THAT(array, NotNull());
- ASSERT_THAT(array->items, SizeIs(1));
+ ASSERT_THAT(array->elements, SizeIs(1));
- String* str = ValueCast<String>(array->items[0].get());
+ String* str = ValueCast<String>(array->elements[0].get());
ASSERT_THAT(str, NotNull());
EXPECT_THAT(*str, StrValueEq("100"));
}