summaryrefslogtreecommitdiff
path: root/tools/aapt2/cmd/Convert_test.cpp
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-02-11 10:57:59 -0800
committerSteven Moreland <smoreland@google.com>2019-02-11 11:00:44 -0800
commit567b4cf7b54062947b5eabe6ecef7b70fbb7301b (patch)
treee7ffe81f03f43359763c39a8c5cf307ba7e96ba7 /tools/aapt2/cmd/Convert_test.cpp
parent4f7ea9f121ef0b81ab9688636cb8ef570f15559c (diff)
parent0932a16cdf085a16b2b6bf46d457745e317eb4ad (diff)
Merge QP1A.190205.002
Change-Id: I8e29d3d840642579119f10af2f90dd536304070f
Diffstat (limited to 'tools/aapt2/cmd/Convert_test.cpp')
-rw-r--r--tools/aapt2/cmd/Convert_test.cpp54
1 files changed, 52 insertions, 2 deletions
diff --git a/tools/aapt2/cmd/Convert_test.cpp b/tools/aapt2/cmd/Convert_test.cpp
index 2e4315086105..3c0fe370c516 100644
--- a/tools/aapt2/cmd/Convert_test.cpp
+++ b/tools/aapt2/cmd/Convert_test.cpp
@@ -18,6 +18,7 @@
#include "LoadedApk.h"
#include "test/Test.h"
+#include "ziparchive/zip_archive.h"
using testing::Eq;
using testing::Ne;
@@ -53,7 +54,11 @@ TEST_F(ConvertTest, RemoveRawXmlStrings) {
// Load the binary xml tree
android::ResXMLTree tree;
std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_convert_apk, &diag);
- AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ std::unique_ptr<io::IData> data = OpenFileAsData(apk.get(), "res/xml/test.xml");
+ ASSERT_THAT(data, Ne(nullptr));
+
+ AssertLoadXml(apk.get(), data.get(), &tree);
// Check that the raw string index has not been assigned
EXPECT_THAT(tree.getAttributeValueStringID(0), Eq(-1));
@@ -87,7 +92,11 @@ TEST_F(ConvertTest, KeepRawXmlStrings) {
// Load the binary xml tree
android::ResXMLTree tree;
std::unique_ptr<LoadedApk> apk = LoadedApk::LoadApkFromPath(out_convert_apk, &diag);
- AssertLoadXml(apk.get(), "res/xml/test.xml", &tree);
+
+ std::unique_ptr<io::IData> data = OpenFileAsData(apk.get(), "res/xml/test.xml");
+ ASSERT_THAT(data, Ne(nullptr));
+
+ AssertLoadXml(apk.get(), data.get(), &tree);
// Check that the raw string index has been set to the correct string pool entry
int32_t raw_index = tree.getAttributeValueStringID(0);
@@ -95,4 +104,45 @@ TEST_F(ConvertTest, KeepRawXmlStrings) {
EXPECT_THAT(util::GetString(tree.getStrings(), static_cast<size_t>(raw_index)), Eq("007"));
}
+TEST_F(ConvertTest, DuplicateEntriesWrittenOnce) {
+ StdErrDiagnostics diag;
+ const std::string apk_path =
+ file::BuildPath({android::base::GetExecutableDirectory(),
+ "integration-tests", "ConvertTest", "duplicate_entries.apk"});
+
+ const std::string out_convert_apk = GetTestPath("out_convert.apk");
+ std::vector<android::StringPiece> convert_args = {
+ "-o", out_convert_apk,
+ "--output-format", "proto",
+ apk_path
+ };
+ ASSERT_THAT(ConvertCommand().Execute(convert_args, &std::cerr), Eq(0));
+
+ ZipArchiveHandle handle;
+ ASSERT_THAT(OpenArchive(out_convert_apk.c_str(), &handle), Eq(0));
+
+ void* cookie = nullptr;
+
+ ZipString prefix("res/theme/10");
+ int32_t result = StartIteration(handle, &cookie, &prefix, nullptr);
+
+ // If this is -5, that means we've found a duplicate entry and this test has failed
+ EXPECT_THAT(result, Eq(0));
+
+ // But if read succeeds, verify only one res/theme/10 entry
+ int count = 0;
+
+ // Can't pass nullptrs into Next()
+ ZipString zip_name;
+ ZipEntry zip_data;
+
+ while ((result = Next(cookie, &zip_data, &zip_name)) == 0) {
+ count++;
+ }
+
+ EndIteration(cookie);
+
+ EXPECT_THAT(count, Eq(1));
+}
+
} // namespace aapt \ No newline at end of file