2014-11-14 14:48:12 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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 "ResourceParser.h"
|
|
|
|
#include "ResourceTable.h"
|
2015-08-14 14:26:04 -07:00
|
|
|
#include "ResourceUtils.h"
|
2014-11-14 14:48:12 -08:00
|
|
|
#include "ResourceValues.h"
|
2016-07-08 15:00:32 -07:00
|
|
|
#include "test/Test.h"
|
2015-11-16 17:35:44 -08:00
|
|
|
#include "xml/XmlPullParser.h"
|
2014-11-14 14:48:12 -08:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace aapt {
|
|
|
|
|
|
|
|
constexpr const char* kXmlPreamble = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
TEST(ResourceParserSingleTest, FailToParseWithNoRootResourcesElement) {
|
|
|
|
std::unique_ptr<IAaptContext> context = test::ContextBuilder().build();
|
|
|
|
std::stringstream input(kXmlPreamble);
|
|
|
|
input << "<attr name=\"foo\"/>" << std::endl;
|
|
|
|
ResourceTable table;
|
|
|
|
ResourceParser parser(context->getDiagnostics(), &table, Source{ "test" }, {});
|
2015-11-16 17:35:44 -08:00
|
|
|
xml::XmlPullParser xmlParser(input);
|
2015-08-14 14:26:04 -07:00
|
|
|
ASSERT_FALSE(parser.parse(&xmlParser));
|
2015-04-10 19:43:55 -07:00
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
struct ResourceParserTest : public ::testing::Test {
|
2015-08-14 14:26:04 -07:00
|
|
|
ResourceTable mTable;
|
|
|
|
std::unique_ptr<IAaptContext> mContext;
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
mContext = test::ContextBuilder().build();
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2016-01-11 13:10:24 -08:00
|
|
|
::testing::AssertionResult testParse(const StringPiece& str) {
|
2016-02-12 22:18:51 -08:00
|
|
|
return testParse(str, ConfigDescription{});
|
2016-01-11 13:10:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
::testing::AssertionResult testParse(const StringPiece& str, const ConfigDescription& config) {
|
2014-11-14 14:48:12 -08:00
|
|
|
std::stringstream input(kXmlPreamble);
|
2015-04-24 19:19:30 -07:00
|
|
|
input << "<resources>\n" << str << "\n</resources>" << std::endl;
|
2015-11-04 13:51:45 -08:00
|
|
|
ResourceParserOptions parserOptions;
|
2016-01-11 13:10:24 -08:00
|
|
|
ResourceParser parser(mContext->getDiagnostics(), &mTable, Source{ "test" }, config,
|
2015-11-04 13:51:45 -08:00
|
|
|
parserOptions);
|
2015-11-16 17:35:44 -08:00
|
|
|
xml::XmlPullParser xmlParser(input);
|
2015-08-14 14:26:04 -07:00
|
|
|
if (parser.parse(&xmlParser)) {
|
2014-11-14 14:48:12 -08:00
|
|
|
return ::testing::AssertionSuccess();
|
|
|
|
}
|
|
|
|
return ::testing::AssertionFailure();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseQuotedString) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<string name=\"foo\"> \" hey there \" </string>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* str = test::getValue<String>(&mTable, "string/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(nullptr, str);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(std::string(" hey there "), *str->value);
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseEscapedString) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<string name=\"foo\">\\?123</string>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* str = test::getValue<String>(&mTable, "string/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(nullptr, str);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(std::string("?123"), *str->value);
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2015-11-04 13:51:45 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseFormattedString) {
|
|
|
|
std::string input = "<string name=\"foo\">%d %s</string>";
|
|
|
|
ASSERT_FALSE(testParse(input));
|
|
|
|
|
|
|
|
input = "<string name=\"foo\">%1$d %2$s</string>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
}
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
TEST_F(ResourceParserTest, IgnoreXliffTags) {
|
|
|
|
std::string input = "<string name=\"foo\" \n"
|
|
|
|
" xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">\n"
|
|
|
|
" There are <xliff:g id=\"count\">%1$d</xliff:g> apples</string>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* str = test::getValue<String>(&mTable, "string/foo");
|
2015-08-14 14:26:04 -07:00
|
|
|
ASSERT_NE(nullptr, str);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(StringPiece("There are %1$d apples"), StringPiece(*str->value));
|
2015-08-14 14:26:04 -07:00
|
|
|
}
|
|
|
|
|
2015-05-12 21:42:59 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseNull) {
|
|
|
|
std::string input = "<integer name=\"foo\">@null</integer>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
|
|
|
// The Android runtime treats a value of android::Res_value::TYPE_NULL as
|
|
|
|
// a non-existing value, and this causes problems in styles when trying to resolve
|
|
|
|
// an attribute. Null values must be encoded as android::Res_value::TYPE_REFERENCE
|
|
|
|
// with a data value of 0.
|
2016-07-25 17:56:58 -07:00
|
|
|
BinaryPrimitive* integer = test::getValue<BinaryPrimitive>(&mTable, "integer/foo");
|
2015-05-12 21:42:59 -07:00
|
|
|
ASSERT_NE(nullptr, integer);
|
|
|
|
EXPECT_EQ(uint16_t(android::Res_value::TYPE_REFERENCE), integer->value.dataType);
|
|
|
|
EXPECT_EQ(0u, integer->value.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseEmpty) {
|
|
|
|
std::string input = "<integer name=\"foo\">@empty</integer>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
BinaryPrimitive* integer = test::getValue<BinaryPrimitive>(&mTable, "integer/foo");
|
2015-05-12 21:42:59 -07:00
|
|
|
ASSERT_NE(nullptr, integer);
|
|
|
|
EXPECT_EQ(uint16_t(android::Res_value::TYPE_NULL), integer->value.dataType);
|
|
|
|
EXPECT_EQ(uint32_t(android::Res_value::DATA_NULL_EMPTY), integer->value.data);
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseAttr) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<attr name=\"foo\" format=\"string\"/>\n"
|
|
|
|
"<attr name=\"bar\"/>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2015-08-14 14:26:04 -07:00
|
|
|
ASSERT_NE(nullptr, attr);
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_STRING), attr->typeMask);
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
attr = test::getValue<Attribute>(&mTable, "attr/bar");
|
2015-08-14 14:26:04 -07:00
|
|
|
ASSERT_NE(nullptr, attr);
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_ANY), attr->typeMask);
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:10:24 -08:00
|
|
|
// Old AAPT allowed attributes to be defined under different configurations, but ultimately
|
|
|
|
// stored them with the default configuration. Check that we have the same behavior.
|
|
|
|
TEST_F(ResourceParserTest, ParseAttrAndDeclareStyleableUnderConfigButRecordAsNoConfig) {
|
|
|
|
const ConfigDescription watchConfig = test::parseConfigOrDie("watch");
|
|
|
|
std::string input = R"EOF(
|
|
|
|
<attr name="foo" />
|
|
|
|
<declare-styleable name="bar">
|
|
|
|
<attr name="baz" />
|
|
|
|
</declare-styleable>)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input, watchConfig));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(nullptr, test::getValueForConfig<Attribute>(&mTable, "attr/foo", watchConfig));
|
|
|
|
EXPECT_EQ(nullptr, test::getValueForConfig<Attribute>(&mTable, "attr/baz", watchConfig));
|
|
|
|
EXPECT_EQ(nullptr, test::getValueForConfig<Styleable>(&mTable, "styleable/bar", watchConfig));
|
2016-01-11 13:10:24 -08:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValue<Attribute>(&mTable, "attr/foo"));
|
|
|
|
EXPECT_NE(nullptr, test::getValue<Attribute>(&mTable, "attr/baz"));
|
|
|
|
EXPECT_NE(nullptr, test::getValue<Styleable>(&mTable, "styleable/bar"));
|
2016-01-11 13:10:24 -08:00
|
|
|
}
|
|
|
|
|
2015-11-20 15:32:30 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseAttrWithMinMax) {
|
|
|
|
std::string input = "<attr name=\"foo\" min=\"10\" max=\"23\" format=\"integer\"/>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2015-11-20 15:32:30 -08:00
|
|
|
ASSERT_NE(nullptr, attr);
|
|
|
|
EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_INTEGER), attr->typeMask);
|
|
|
|
EXPECT_EQ(10, attr->minInt);
|
|
|
|
EXPECT_EQ(23, attr->maxInt);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, FailParseAttrWithMinMaxButNotInteger) {
|
|
|
|
std::string input = "<attr name=\"foo\" min=\"10\" max=\"23\" format=\"string\"/>";
|
|
|
|
ASSERT_FALSE(testParse(input));
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseUseAndDeclOfAttr) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<declare-styleable name=\"Styleable\">\n"
|
|
|
|
" <attr name=\"foo\" />\n"
|
|
|
|
"</declare-styleable>\n"
|
|
|
|
"<attr name=\"foo\" format=\"string\"/>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(nullptr, attr);
|
|
|
|
EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_STRING), attr->typeMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseDoubleUseOfAttr) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<declare-styleable name=\"Theme\">"
|
|
|
|
" <attr name=\"foo\" />\n"
|
|
|
|
"</declare-styleable>\n"
|
|
|
|
"<declare-styleable name=\"Window\">\n"
|
|
|
|
" <attr name=\"foo\" format=\"boolean\"/>\n"
|
|
|
|
"</declare-styleable>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(nullptr, attr);
|
|
|
|
EXPECT_EQ(uint32_t(android::ResTable_map::TYPE_BOOLEAN), attr->typeMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseEnumAttr) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<attr name=\"foo\">\n"
|
|
|
|
" <enum name=\"bar\" value=\"0\"/>\n"
|
|
|
|
" <enum name=\"bat\" value=\"1\"/>\n"
|
|
|
|
" <enum name=\"baz\" value=\"2\"/>\n"
|
|
|
|
"</attr>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* enumAttr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(enumAttr, nullptr);
|
|
|
|
EXPECT_EQ(enumAttr->typeMask, android::ResTable_map::TYPE_ENUM);
|
|
|
|
ASSERT_EQ(enumAttr->symbols.size(), 3u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(enumAttr->symbols[0].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(enumAttr->symbols[0].symbol.name.value().entry, "bar");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(enumAttr->symbols[0].value, 0u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(enumAttr->symbols[1].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(enumAttr->symbols[1].symbol.name.value().entry, "bat");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(enumAttr->symbols[1].value, 1u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(enumAttr->symbols[2].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(enumAttr->symbols[2].symbol.name.value().entry, "baz");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(enumAttr->symbols[2].value, 2u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseFlagAttr) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<attr name=\"foo\">\n"
|
|
|
|
" <flag name=\"bar\" value=\"0\"/>\n"
|
|
|
|
" <flag name=\"bat\" value=\"1\"/>\n"
|
|
|
|
" <flag name=\"baz\" value=\"2\"/>\n"
|
|
|
|
"</attr>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* flagAttr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, flagAttr);
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(flagAttr->typeMask, android::ResTable_map::TYPE_FLAGS);
|
|
|
|
ASSERT_EQ(flagAttr->symbols.size(), 3u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(flagAttr->symbols[0].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(flagAttr->symbols[0].symbol.name.value().entry, "bar");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(flagAttr->symbols[0].value, 0u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(flagAttr->symbols[1].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(flagAttr->symbols[1].symbol.name.value().entry, "bat");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(flagAttr->symbols[1].value, 1u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(flagAttr->symbols[2].symbol.name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(flagAttr->symbols[2].symbol.name.value().entry, "baz");
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(flagAttr->symbols[2].value, 2u);
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
std::unique_ptr<BinaryPrimitive> flagValue = ResourceUtils::tryParseFlagSymbol(flagAttr,
|
2016-07-08 15:00:32 -07:00
|
|
|
"baz|bat");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, flagValue);
|
2014-11-14 14:48:12 -08:00
|
|
|
EXPECT_EQ(flagValue->value.data, 1u | 2u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, FailToParseEnumAttrWithNonUniqueKeys) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<attr name=\"foo\">\n"
|
|
|
|
" <enum name=\"bar\" value=\"0\"/>\n"
|
|
|
|
" <enum name=\"bat\" value=\"1\"/>\n"
|
|
|
|
" <enum name=\"bat\" value=\"2\"/>\n"
|
|
|
|
"</attr>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_FALSE(testParse(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseStyle) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<style name=\"foo\" parent=\"@style/fu\">\n"
|
|
|
|
" <item name=\"bar\">#ffffffff</item>\n"
|
|
|
|
" <item name=\"bat\">@string/hey</item>\n"
|
|
|
|
" <item name=\"baz\"><b>hey</b></item>\n"
|
|
|
|
"</style>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(style->parent);
|
|
|
|
AAPT_ASSERT_TRUE(style->parent.value().name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("style/fu"), style->parent.value().name.value());
|
2015-08-14 14:26:04 -07:00
|
|
|
ASSERT_EQ(3u, style->entries.size());
|
|
|
|
|
|
|
|
AAPT_ASSERT_TRUE(style->entries[0].key.name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("attr/bar"), style->entries[0].key.name.value());
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
AAPT_ASSERT_TRUE(style->entries[1].key.name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("attr/bat"), style->entries[1].key.name.value());
|
2015-08-14 14:26:04 -07:00
|
|
|
|
|
|
|
AAPT_ASSERT_TRUE(style->entries[2].key.name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("attr/baz"), style->entries[2].key.name.value());
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2015-04-10 19:43:55 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithShorthandParent) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<style name=\"foo\" parent=\"com.app:Theme\"/>";
|
2015-04-10 19:43:55 -07:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(style->parent);
|
|
|
|
AAPT_ASSERT_TRUE(style->parent.value().name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("com.app:style/Theme"), style->parent.value().name.value());
|
2015-04-10 19:43:55 -07:00
|
|
|
}
|
|
|
|
|
2015-04-24 19:19:30 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedParent) {
|
|
|
|
std::string input = "<style xmlns:app=\"http://schemas.android.com/apk/res/android\"\n"
|
|
|
|
" name=\"foo\" parent=\"app:Theme\"/>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(style->parent);
|
|
|
|
AAPT_ASSERT_TRUE(style->parent.value().name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("android:style/Theme"), style->parent.value().name.value());
|
2015-04-24 19:19:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithPackageAliasedItems) {
|
|
|
|
std::string input =
|
|
|
|
"<style xmlns:app=\"http://schemas.android.com/apk/res/android\" name=\"foo\">\n"
|
|
|
|
" <item name=\"app:bar\">0</item>\n"
|
|
|
|
"</style>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-04-24 19:19:30 -07:00
|
|
|
ASSERT_EQ(1u, style->entries.size());
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("android:attr/bar"), style->entries[0].key.name.value());
|
2015-04-24 19:19:30 -07:00
|
|
|
}
|
|
|
|
|
2015-05-08 20:16:23 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithInferredParent) {
|
|
|
|
std::string input = "<style name=\"foo.bar\"/>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo.bar");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_ASSERT_TRUE(style->parent);
|
|
|
|
AAPT_ASSERT_TRUE(style->parent.value().name);
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(style->parent.value().name.value(), test::parseNameOrDie("style/foo"));
|
2015-05-08 20:16:23 -07:00
|
|
|
EXPECT_TRUE(style->parentInferred);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithInferredParentOverridenByEmptyParentAttribute) {
|
|
|
|
std::string input = "<style name=\"foo.bar\" parent=\"\"/>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo.bar");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
2015-08-14 14:26:04 -07:00
|
|
|
AAPT_EXPECT_FALSE(style->parent);
|
2015-05-08 20:16:23 -07:00
|
|
|
EXPECT_FALSE(style->parentInferred);
|
|
|
|
}
|
|
|
|
|
2015-12-16 14:01:57 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseStyleWithPrivateParentReference) {
|
|
|
|
std::string input = R"EOF(<style name="foo" parent="*android:style/bar" />)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Style* style = test::getValue<Style>(&mTable, "style/foo");
|
2015-12-16 14:01:57 -08:00
|
|
|
ASSERT_NE(nullptr, style);
|
|
|
|
AAPT_ASSERT_TRUE(style->parent);
|
|
|
|
EXPECT_TRUE(style->parent.value().privateReference);
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseAutoGeneratedIdReference) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<string name=\"foo\">@+id/bar</string>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Id* id = test::getValue<Id>(&mTable, "id/bar");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(id, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseAttributesDeclareStyleable) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<declare-styleable name=\"foo\">\n"
|
|
|
|
" <attr name=\"bar\" />\n"
|
|
|
|
" <attr name=\"bat\" format=\"string|reference\"/>\n"
|
2015-10-13 11:37:10 -07:00
|
|
|
" <attr name=\"baz\">\n"
|
|
|
|
" <enum name=\"foo\" value=\"1\"/>\n"
|
|
|
|
" </attr>\n"
|
2015-04-24 19:19:30 -07:00
|
|
|
"</declare-styleable>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2015-11-04 13:51:45 -08:00
|
|
|
Maybe<ResourceTable::SearchResult> result =
|
2016-07-25 17:56:58 -07:00
|
|
|
mTable.findResource(test::parseNameOrDie("styleable/foo"));
|
2015-11-04 13:51:45 -08:00
|
|
|
AAPT_ASSERT_TRUE(result);
|
|
|
|
EXPECT_EQ(SymbolState::kPublic, result.value().entry->symbolStatus.state);
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/bar");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(attr, nullptr);
|
|
|
|
EXPECT_TRUE(attr->isWeak());
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
attr = test::getValue<Attribute>(&mTable, "attr/bat");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(attr, nullptr);
|
|
|
|
EXPECT_TRUE(attr->isWeak());
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
attr = test::getValue<Attribute>(&mTable, "attr/baz");
|
2015-10-13 11:37:10 -07:00
|
|
|
ASSERT_NE(attr, nullptr);
|
|
|
|
EXPECT_TRUE(attr->isWeak());
|
|
|
|
EXPECT_EQ(1u, attr->symbols.size());
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValue<Id>(&mTable, "id/foo"));
|
2015-10-13 11:37:10 -07:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Styleable* styleable = test::getValue<Styleable>(&mTable, "styleable/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(styleable, nullptr);
|
2015-10-13 11:37:10 -07:00
|
|
|
ASSERT_EQ(3u, styleable->entries.size());
|
2014-11-14 14:48:12 -08:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_EQ(test::parseNameOrDie("attr/bar"), styleable->entries[0].name.value());
|
|
|
|
EXPECT_EQ(test::parseNameOrDie("attr/bat"), styleable->entries[1].name.value());
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2015-11-16 17:35:44 -08:00
|
|
|
TEST_F(ResourceParserTest, ParsePrivateAttributesDeclareStyleable) {
|
|
|
|
std::string input = "<declare-styleable name=\"foo\" xmlns:privAndroid=\"http://schemas.android.com/apk/prv/res/android\">\n"
|
|
|
|
" <attr name=\"*android:bar\" />\n"
|
|
|
|
" <attr name=\"privAndroid:bat\" />\n"
|
|
|
|
"</declare-styleable>";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
2016-07-25 17:56:58 -07:00
|
|
|
Styleable* styleable = test::getValue<Styleable>(&mTable, "styleable/foo");
|
2015-11-16 17:35:44 -08:00
|
|
|
ASSERT_NE(nullptr, styleable);
|
|
|
|
ASSERT_EQ(2u, styleable->entries.size());
|
|
|
|
|
|
|
|
EXPECT_TRUE(styleable->entries[0].privateReference);
|
|
|
|
AAPT_ASSERT_TRUE(styleable->entries[0].name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(std::string("android"), styleable->entries[0].name.value().package);
|
2015-11-16 17:35:44 -08:00
|
|
|
|
|
|
|
EXPECT_TRUE(styleable->entries[1].privateReference);
|
|
|
|
AAPT_ASSERT_TRUE(styleable->entries[1].name);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(std::string("android"), styleable->entries[1].name.value().package);
|
2015-11-16 17:35:44 -08:00
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseArray) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<array name=\"foo\">\n"
|
|
|
|
" <item>@string/ref</item>\n"
|
|
|
|
" <item>hey</item>\n"
|
|
|
|
" <item>23</item>\n"
|
|
|
|
"</array>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Array* array = test::getValue<Array>(&mTable, "array/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(array, nullptr);
|
|
|
|
ASSERT_EQ(3u, array->items.size());
|
|
|
|
|
2015-08-14 14:26:04 -07:00
|
|
|
EXPECT_NE(nullptr, valueCast<Reference>(array->items[0].get()));
|
|
|
|
EXPECT_NE(nullptr, valueCast<String>(array->items[1].get()));
|
|
|
|
EXPECT_NE(nullptr, valueCast<BinaryPrimitive>(array->items[2].get()));
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2015-10-13 11:37:10 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseStringArray) {
|
|
|
|
std::string input = "<string-array name=\"foo\">\n"
|
|
|
|
" <item>\"Werk\"</item>\n"
|
|
|
|
"</string-array>\n";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValue<Array>(&mTable, "array/foo"));
|
2015-10-13 11:37:10 -07:00
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
TEST_F(ResourceParserTest, ParsePlural) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<plurals name=\"foo\">\n"
|
|
|
|
" <item quantity=\"other\">apples</item>\n"
|
|
|
|
" <item quantity=\"one\">apple</item>\n"
|
|
|
|
"</plurals>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, ParseCommentsWithResource) {
|
2015-10-22 12:48:43 -07:00
|
|
|
std::string input = "<!--This is a comment-->\n"
|
2015-04-24 19:19:30 -07:00
|
|
|
"<string name=\"foo\">Hi</string>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* value = test::getValue<String>(&mTable, "string/foo");
|
2015-10-22 12:48:43 -07:00
|
|
|
ASSERT_NE(nullptr, value);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(value->getComment(), "This is a comment");
|
2015-10-22 12:48:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, DoNotCombineMultipleComments) {
|
|
|
|
std::string input = "<!--One-->\n"
|
|
|
|
"<!--Two-->\n"
|
|
|
|
"<string name=\"foo\">Hi</string>";
|
|
|
|
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* value = test::getValue<String>(&mTable, "string/foo");
|
2015-10-22 12:48:43 -07:00
|
|
|
ASSERT_NE(nullptr, value);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(value->getComment(), "Two");
|
2015-10-22 12:48:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ResourceParserTest, IgnoreCommentBeforeEndTag) {
|
|
|
|
std::string input = "<!--One-->\n"
|
|
|
|
"<string name=\"foo\">\n"
|
|
|
|
" Hi\n"
|
|
|
|
"<!--Two-->\n"
|
|
|
|
"</string>";
|
|
|
|
|
|
|
|
ASSERT_TRUE(testParse(input));
|
2015-08-14 14:26:04 -07:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
String* value = test::getValue<String>(&mTable, "string/foo");
|
2015-10-22 12:48:43 -07:00
|
|
|
ASSERT_NE(nullptr, value);
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(value->getComment(), "One");
|
2014-11-14 14:48:12 -08:00
|
|
|
}
|
|
|
|
|
2015-10-21 14:42:43 -07:00
|
|
|
TEST_F(ResourceParserTest, ParseNestedComments) {
|
|
|
|
// We only care about declare-styleable and enum/flag attributes because comments
|
|
|
|
// from those end up in R.java
|
|
|
|
std::string input = R"EOF(
|
|
|
|
<declare-styleable name="foo">
|
|
|
|
<!-- The name of the bar -->
|
|
|
|
<attr name="barName" format="string|reference" />
|
|
|
|
</declare-styleable>
|
|
|
|
|
|
|
|
<attr name="foo">
|
|
|
|
<!-- The very first -->
|
|
|
|
<enum name="one" value="1" />
|
|
|
|
</attr>)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Styleable* styleable = test::getValue<Styleable>(&mTable, "styleable/foo");
|
2015-10-21 14:42:43 -07:00
|
|
|
ASSERT_NE(nullptr, styleable);
|
|
|
|
ASSERT_EQ(1u, styleable->entries.size());
|
|
|
|
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(StringPiece("The name of the bar"), styleable->entries.front().getComment());
|
2015-10-21 14:42:43 -07:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Attribute* attr = test::getValue<Attribute>(&mTable, "attr/foo");
|
2015-10-21 14:42:43 -07:00
|
|
|
ASSERT_NE(nullptr, attr);
|
|
|
|
ASSERT_EQ(1u, attr->symbols.size());
|
|
|
|
|
2016-07-08 15:00:32 -07:00
|
|
|
EXPECT_EQ(StringPiece("The very first"), attr->symbols.front().symbol.getComment());
|
2015-10-21 14:42:43 -07:00
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
/*
|
|
|
|
* Declaring an ID as public should not require a separate definition
|
|
|
|
* (as an ID has no value).
|
|
|
|
*/
|
|
|
|
TEST_F(ResourceParserTest, ParsePublicIdAsDefinition) {
|
2015-04-24 19:19:30 -07:00
|
|
|
std::string input = "<public type=\"id\" name=\"foo\"/>";
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
Id* id = test::getValue<Id>(&mTable, "id/foo");
|
2014-11-14 14:48:12 -08:00
|
|
|
ASSERT_NE(nullptr, id);
|
|
|
|
}
|
|
|
|
|
2016-02-12 22:18:51 -08:00
|
|
|
TEST_F(ResourceParserTest, KeepAllProducts) {
|
2016-01-06 15:45:28 -08:00
|
|
|
std::string input = R"EOF(
|
|
|
|
<string name="foo" product="phone">hi</string>
|
|
|
|
<string name="foo" product="no-sdcard">ho</string>
|
|
|
|
<string name="bar" product="">wee</string>
|
|
|
|
<string name="baz">woo</string>
|
|
|
|
<string name="bit" product="phablet">hoot</string>
|
|
|
|
<string name="bot" product="default">yes</string>
|
|
|
|
)EOF";
|
2016-02-12 22:18:51 -08:00
|
|
|
ASSERT_TRUE(testParse(input));
|
2015-10-13 11:37:10 -07:00
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/foo",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
"phone"));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/foo",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
"no-sdcard"));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/bar",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
""));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/baz",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
""));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/bit",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
"phablet"));
|
2016-07-25 17:56:58 -07:00
|
|
|
EXPECT_NE(nullptr, test::getValueForConfigAndProduct<String>(&mTable, "string/bot",
|
2016-02-12 22:18:51 -08:00
|
|
|
ConfigDescription::defaultConfig(),
|
|
|
|
"default"));
|
2015-10-13 11:37:10 -07:00
|
|
|
}
|
|
|
|
|
2015-11-06 18:25:04 -08:00
|
|
|
TEST_F(ResourceParserTest, AutoIncrementIdsInPublicGroup) {
|
|
|
|
std::string input = R"EOF(
|
|
|
|
<public-group type="attr" first-id="0x01010040">
|
|
|
|
<public name="foo" />
|
|
|
|
<public name="bar" />
|
|
|
|
</public-group>)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
|
|
|
Maybe<ResourceTable::SearchResult> result = mTable.findResource(
|
2016-07-25 17:56:58 -07:00
|
|
|
test::parseNameOrDie("attr/foo"));
|
2015-11-06 18:25:04 -08:00
|
|
|
AAPT_ASSERT_TRUE(result);
|
|
|
|
|
|
|
|
AAPT_ASSERT_TRUE(result.value().package->id);
|
|
|
|
AAPT_ASSERT_TRUE(result.value().type->id);
|
|
|
|
AAPT_ASSERT_TRUE(result.value().entry->id);
|
|
|
|
ResourceId actualId(result.value().package->id.value(),
|
|
|
|
result.value().type->id.value(),
|
|
|
|
result.value().entry->id.value());
|
|
|
|
EXPECT_EQ(ResourceId(0x01010040), actualId);
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
result = mTable.findResource(test::parseNameOrDie("attr/bar"));
|
2015-11-06 18:25:04 -08:00
|
|
|
AAPT_ASSERT_TRUE(result);
|
|
|
|
|
|
|
|
AAPT_ASSERT_TRUE(result.value().package->id);
|
|
|
|
AAPT_ASSERT_TRUE(result.value().type->id);
|
|
|
|
AAPT_ASSERT_TRUE(result.value().entry->id);
|
|
|
|
actualId = ResourceId(result.value().package->id.value(),
|
|
|
|
result.value().type->id.value(),
|
|
|
|
result.value().entry->id.value());
|
|
|
|
EXPECT_EQ(ResourceId(0x01010041), actualId);
|
|
|
|
}
|
|
|
|
|
2015-11-07 13:34:39 -08:00
|
|
|
TEST_F(ResourceParserTest, ExternalTypesShouldOnlyBeReferences) {
|
|
|
|
std::string input = R"EOF(<item type="layout" name="foo">@layout/bar</item>)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
|
|
|
input = R"EOF(<item type="layout" name="bar">"this is a string"</item>)EOF";
|
|
|
|
ASSERT_FALSE(testParse(input));
|
|
|
|
}
|
|
|
|
|
2015-12-09 15:20:52 -08:00
|
|
|
TEST_F(ResourceParserTest, AddResourcesElementShouldAddEntryWithUndefinedSymbol) {
|
|
|
|
std::string input = R"EOF(<add-resource name="bar" type="string" />)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
|
|
|
Maybe<ResourceTable::SearchResult> result = mTable.findResource(
|
2016-07-25 17:56:58 -07:00
|
|
|
test::parseNameOrDie("string/bar"));
|
2015-12-09 15:20:52 -08:00
|
|
|
AAPT_ASSERT_TRUE(result);
|
|
|
|
const ResourceEntry* entry = result.value().entry;
|
|
|
|
ASSERT_NE(nullptr, entry);
|
|
|
|
EXPECT_EQ(SymbolState::kUndefined, entry->symbolStatus.state);
|
|
|
|
}
|
|
|
|
|
2015-12-14 16:08:50 -08:00
|
|
|
TEST_F(ResourceParserTest, ParseItemElementWithFormat) {
|
|
|
|
std::string input = R"EOF(<item name="foo" type="integer" format="float">0.3</item>)EOF";
|
|
|
|
ASSERT_TRUE(testParse(input));
|
|
|
|
|
2016-07-25 17:56:58 -07:00
|
|
|
BinaryPrimitive* val = test::getValue<BinaryPrimitive>(&mTable, "integer/foo");
|
2015-12-14 16:08:50 -08:00
|
|
|
ASSERT_NE(nullptr, val);
|
|
|
|
|
|
|
|
EXPECT_EQ(uint32_t(android::Res_value::TYPE_FLOAT), val->value.dataType);
|
|
|
|
}
|
|
|
|
|
2014-11-14 14:48:12 -08:00
|
|
|
} // namespace aapt
|