summaryrefslogtreecommitdiff
path: root/tools/aapt2/flatten/XmlFlattener_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/flatten/XmlFlattener_test.cpp')
-rw-r--r--tools/aapt2/flatten/XmlFlattener_test.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/tools/aapt2/flatten/XmlFlattener_test.cpp b/tools/aapt2/flatten/XmlFlattener_test.cpp
index 4e6eb811e572..9efee1ea1fe6 100644
--- a/tools/aapt2/flatten/XmlFlattener_test.cpp
+++ b/tools/aapt2/flatten/XmlFlattener_test.cpp
@@ -16,13 +16,11 @@
#include "flatten/XmlFlattener.h"
#include "link/Linkers.h"
-#include "test/Builders.h"
-#include "test/Context.h"
+#include "test/Test.h"
#include "util/BigBuffer.h"
#include "util/Util.h"
#include <androidfw/ResourceTypes.h>
-#include <gtest/gtest.h>
namespace aapt {
@@ -30,15 +28,15 @@ class XmlFlattenerTest : public ::testing::Test {
public:
void SetUp() override {
mContext = test::ContextBuilder()
- .setCompilationPackage(u"com.app.test")
- .setNameManglerPolicy(NameManglerPolicy{ u"com.app.test" })
+ .setCompilationPackage("com.app.test")
+ .setNameManglerPolicy(NameManglerPolicy{ "com.app.test" })
.addSymbolSource(test::StaticSymbolSourceBuilder()
- .addSymbol(u"@android:attr/id", ResourceId(0x010100d0),
+ .addSymbol("@android:attr/id", ResourceId(0x010100d0),
test::AttributeBuilder().build())
- .addSymbol(u"@com.app.test:id/id", ResourceId(0x7f020000))
- .addSymbol(u"@android:attr/paddingStart", ResourceId(0x010103b3),
+ .addSymbol("@com.app.test:id/id", ResourceId(0x7f020000))
+ .addSymbol("@android:attr/paddingStart", ResourceId(0x010103b3),
test::AttributeBuilder().build())
- .addSymbol(u"@android:attr/colorAccent", ResourceId(0x01010435),
+ .addSymbol("@android:attr/colorAccent", ResourceId(0x01010435),
test::AttributeBuilder().build())
.build())
.build();
@@ -207,4 +205,23 @@ TEST_F(XmlFlattenerTest, NoNamespaceIsNotTheSameAsEmptyNamespace) {
EXPECT_GE(tree.indexOfAttribute(nullptr, 0, kPackage.data(), kPackage.size()), 0);
}
+TEST_F(XmlFlattenerTest, EmptyStringValueInAttributeIsNotNull) {
+ std::unique_ptr<xml::XmlResource> doc = test::buildXmlDom("<View package=\"\"/>");
+
+ android::ResXMLTree tree;
+ ASSERT_TRUE(flatten(doc.get(), &tree));
+
+ while (tree.next() != android::ResXMLTree::START_TAG) {
+ ASSERT_NE(tree.getEventType(), android::ResXMLTree::BAD_DOCUMENT);
+ ASSERT_NE(tree.getEventType(), android::ResXMLTree::END_DOCUMENT);
+ }
+
+ const StringPiece16 kPackage = u"package";
+ ssize_t idx = tree.indexOfAttribute(nullptr, 0, kPackage.data(), kPackage.size());
+ ASSERT_GE(idx, 0);
+
+ size_t len;
+ EXPECT_NE(nullptr, tree.getAttributeStringValue(idx, &len));
+}
+
} // namespace aapt