diff options
author | Bill Peckham <bpeckham@google.com> | 2018-10-09 17:33:34 -0700 |
---|---|---|
committer | Bill Peckham <bpeckham@google.com> | 2018-10-15 17:46:00 -0700 |
commit | ddcaa93e851eb5e57692799446f2ef3fe31436ae (patch) | |
tree | 41f5481541b8c4e26dd8fef5cbba7a24aa1003c7 /tools/aapt2/cmd/Compile_test.cpp | |
parent | 760f366150e46580bfa808a897bc99c3e8907ded (diff) | |
parent | ef229d9195a2bdff34f94420687c0c05f4447a88 (diff) |
Merge QP1A.181008.001
Change-Id: Iff68e8d0501ac5c2998c96f9df4042a94a1ce9e1
Diffstat (limited to 'tools/aapt2/cmd/Compile_test.cpp')
-rw-r--r-- | tools/aapt2/cmd/Compile_test.cpp | 145 |
1 files changed, 84 insertions, 61 deletions
diff --git a/tools/aapt2/cmd/Compile_test.cpp b/tools/aapt2/cmd/Compile_test.cpp index dd5198ce86da..c0c05cda35e7 100644 --- a/tools/aapt2/cmd/Compile_test.cpp +++ b/tools/aapt2/cmd/Compile_test.cpp @@ -17,6 +17,9 @@ #include "Compile.h" #include "android-base/file.h" +#include "android-base/stringprintf.h" +#include "android-base/utf8.h" + #include "io/StringStream.h" #include "io/ZipArchive.h" #include "java/AnnotationProcessor.h" @@ -24,8 +27,20 @@ namespace aapt { +std::string BuildPath(std::vector<std::string> args) { + std::string out; + if (args.empty()) { + return out; + } + out = args[0]; + for (int i = 1; i < args.size(); i++) { + file::AppendPath(&out, args[i]); + } + return out; +} + int TestCompile(const std::string& path, const std::string& outDir, bool legacy, - StdErrDiagnostics& diag) { + StdErrDiagnostics& diag) { std::vector<android::StringPiece> args; args.push_back(path); args.push_back("-o"); @@ -39,95 +54,101 @@ int TestCompile(const std::string& path, const std::string& outDir, bool legacy, TEST(CompilerTest, MultiplePeriods) { StdErrDiagnostics diag; std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); - const std::string kResDir = android::base::Dirname(android::base::GetExecutablePath()) - + "/integration-tests/CompileTest/res"; + const std::string kResDir = BuildPath({android::base::Dirname(android::base::GetExecutablePath()), + "integration-tests", "CompileTest", "res"}); // Resource files without periods in the file name should not throw errors - const std::string path0 = kResDir + "/values/values.xml"; - const std::string path0_out = kResDir + "/values_values.arsc.flat"; - - remove(path0_out.c_str()); + const std::string path0 = BuildPath({kResDir, "values", "values.xml"}); + const std::string path0_out = BuildPath({kResDir, "values_values.arsc.flat"}); + ::android::base::utf8::unlink(path0_out.c_str()); ASSERT_EQ(TestCompile(path0, kResDir, /** legacy */ false, diag), 0); - ASSERT_EQ(remove(path0_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path0_out.c_str()), 0); ASSERT_EQ(TestCompile(path0, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path0_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path0_out.c_str()), 0); - const std::string path1 = kResDir + "/drawable/image.png"; - const std::string path1_out = kResDir + "/drawable_image.png.flat"; - remove(path1_out.c_str()); + const std::string path1 = BuildPath({kResDir, "drawable", "image.png"}); + const std::string path1_out = BuildPath({kResDir, "drawable_image.png.flat"}); + ::android::base::utf8::unlink(path1_out.c_str()); ASSERT_EQ(TestCompile(path1, kResDir, /** legacy */ false, diag), 0); - ASSERT_EQ(remove(path1_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path1_out.c_str()), 0); ASSERT_EQ(TestCompile(path1, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path1_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path1_out.c_str()), 0); - const std::string path2 = kResDir + "/drawable/image.9.png"; - const std::string path2_out = kResDir + "/drawable_image.9.png.flat"; - remove(path2_out.c_str()); + const std::string path2 = BuildPath({kResDir, "drawable", "image.9.png"}); + const std::string path2_out = BuildPath({kResDir, "drawable_image.9.png.flat"}); + ::android::base::utf8::unlink(path2_out.c_str()); ASSERT_EQ(TestCompile(path2, kResDir, /** legacy */ false, diag), 0); - ASSERT_EQ(remove(path2_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path2_out.c_str()), 0); ASSERT_EQ(TestCompile(path2, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path2_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path2_out.c_str()), 0); // Resource files with periods in the file name should fail on non-legacy compilations - const std::string path3 = kResDir + "/values/values.all.xml"; - const std::string path3_out = kResDir + "/values_values.all.arsc.flat"; - remove(path3_out.c_str()); + const std::string path3 = BuildPath({kResDir, "values", "values.all.xml"}); + const std::string path3_out = BuildPath({kResDir, "values_values.all.arsc.flat"}); + ::android::base::utf8::unlink(path3_out.c_str()); ASSERT_NE(TestCompile(path3, kResDir, /** legacy */ false, diag), 0); - ASSERT_NE(remove(path3_out.c_str()), 0); + ASSERT_NE(::android::base::utf8::unlink(path3_out.c_str()), 0); ASSERT_EQ(TestCompile(path3, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path3_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path3_out.c_str()), 0); - const std::string path4 = kResDir + "/drawable/image.small.png"; - const std::string path4_out = (kResDir + std::string("/drawable_image.small.png.flat")).c_str(); - remove(path4_out.c_str()); + const std::string path4 = BuildPath({kResDir, "drawable", "image.small.png"}); + const std::string path4_out = BuildPath({kResDir, "drawable_image.small.png.flat"}); + ::android::base::utf8::unlink(path4_out.c_str()); ASSERT_NE(TestCompile(path4, kResDir, /** legacy */ false, diag), 0); - ASSERT_NE(remove(path4_out.c_str()), 0); + ASSERT_NE(::android::base::utf8::unlink(path4_out.c_str()), 0); ASSERT_EQ(TestCompile(path4, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path4_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path4_out.c_str()), 0); - const std::string path5 = kResDir + "/drawable/image.small.9.png"; - const std::string path5_out = (kResDir + std::string("/drawable_image.small.9.png.flat")).c_str(); - remove(path5_out.c_str()); + const std::string path5 = BuildPath({kResDir, "drawable", "image.small.9.png"}); + const std::string path5_out = BuildPath({kResDir, "drawable_image.small.9.png.flat"}); + ::android::base::utf8::unlink(path5_out.c_str()); ASSERT_NE(TestCompile(path5, kResDir, /** legacy */ false, diag), 0); - ASSERT_NE(remove(path5_out.c_str()), 0); + ASSERT_NE(::android::base::utf8::unlink(path5_out.c_str()), 0); ASSERT_EQ(TestCompile(path5, kResDir, /** legacy */ true, diag), 0); - ASSERT_EQ(remove(path5_out.c_str()), 0); + ASSERT_EQ(::android::base::utf8::unlink(path5_out.c_str()), 0); } TEST(CompilerTest, DirInput) { StdErrDiagnostics diag; std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); - const std::string kResDir = android::base::Dirname(android::base::GetExecutablePath()) - + "/integration-tests/CompileTest/DirInput/res"; - const std::string kOutputFlata = android::base::Dirname(android::base::GetExecutablePath()) - + "/integration-tests/CompileTest/DirInput/compiled.flata"; - remove(kOutputFlata.c_str()); + const std::string kResDir = BuildPath({android::base::Dirname(android::base::GetExecutablePath()), + "integration-tests", "CompileTest", "DirInput", "res"}); + const std::string kOutputFlata = + BuildPath({android::base::Dirname(android::base::GetExecutablePath()), "integration-tests", + "CompileTest", "DirInput", "compiled.flata"}); + ::android::base::utf8::unlink(kOutputFlata.c_str()); std::vector<android::StringPiece> args; args.push_back("--dir"); args.push_back(kResDir); args.push_back("-o"); args.push_back(kOutputFlata); + args.push_back("-v"); ASSERT_EQ(CompileCommand(&diag).Execute(args, &std::cerr), 0); - // Check for the presence of the compiled files - std::string err; - std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::Create(kOutputFlata, &err); - ASSERT_NE(zip, nullptr) << err; - ASSERT_NE(zip->FindFile("drawable_image.png.flat"), nullptr); - ASSERT_NE(zip->FindFile("layout_layout.xml.flat"), nullptr); - ASSERT_NE(zip->FindFile("values_values.arsc.flat"), nullptr); - ASSERT_EQ(remove(kOutputFlata.c_str()), 0); + { + // Check for the presence of the compiled files + std::string err; + std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::Create(kOutputFlata, &err); + ASSERT_NE(zip, nullptr) << err; + ASSERT_NE(zip->FindFile("drawable_image.png.flat"), nullptr); + ASSERT_NE(zip->FindFile("layout_layout.xml.flat"), nullptr); + ASSERT_NE(zip->FindFile("values_values.arsc.flat"), nullptr); + } + ASSERT_EQ(::android::base::utf8::unlink(kOutputFlata.c_str()), 0); } TEST(CompilerTest, ZipInput) { StdErrDiagnostics diag; std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); - const std::string kResZip = android::base::Dirname(android::base::GetExecutablePath()) - + "/integration-tests/CompileTest/ZipInput/res.zip"; - const std::string kOutputFlata = android::base::Dirname(android::base::GetExecutablePath()) - + "/integration-tests/CompileTest/ZipInput/compiled.flata"; - remove(kOutputFlata.c_str()); + const std::string kResZip = + BuildPath({android::base::Dirname(android::base::GetExecutablePath()), "integration-tests", + "CompileTest", "ZipInput", "res.zip"}); + const std::string kOutputFlata = + BuildPath({android::base::Dirname(android::base::GetExecutablePath()), "integration-tests", + "CompileTest", "ZipInput", "compiled.flata"}); + + ::android::base::utf8::unlink(kOutputFlata.c_str()); std::vector<android::StringPiece> args; args.push_back("--zip"); @@ -136,14 +157,16 @@ TEST(CompilerTest, ZipInput) { args.push_back(kOutputFlata); ASSERT_EQ(CompileCommand(&diag).Execute(args, &std::cerr), 0); - // Check for the presence of the compiled files - std::string err; - std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::Create(kOutputFlata, &err); - ASSERT_NE(zip, nullptr) << err; - ASSERT_NE(zip->FindFile("drawable_image.png.flat"), nullptr); - ASSERT_NE(zip->FindFile("layout_layout.xml.flat"), nullptr); - ASSERT_NE(zip->FindFile("values_values.arsc.flat"), nullptr); - ASSERT_EQ(remove(kOutputFlata.c_str()), 0); + { + // Check for the presence of the compiled files + std::string err; + std::unique_ptr<io::ZipFileCollection> zip = io::ZipFileCollection::Create(kOutputFlata, &err); + ASSERT_NE(zip, nullptr) << err; + ASSERT_NE(zip->FindFile("drawable_image.png.flat"), nullptr); + ASSERT_NE(zip->FindFile("layout_layout.xml.flat"), nullptr); + ASSERT_NE(zip->FindFile("values_values.arsc.flat"), nullptr); + } + ASSERT_EQ(::android::base::utf8::unlink(kOutputFlata.c_str()), 0); } -} // namespace aapt
\ No newline at end of file +} // namespace aapt
\ No newline at end of file |