y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "Compile.h" |
| 18 | |
| 19 | #include "android-base/file.h" |
| 20 | #include "io/StringStream.h" |
| 21 | #include "java/AnnotationProcessor.h" |
| 22 | #include "test/Test.h" |
| 23 | |
| 24 | namespace aapt { |
| 25 | |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 26 | int TestCompile(const std::string& path, const std::string& outDir, bool legacy, |
| 27 | StdErrDiagnostics& diag) { |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 28 | std::vector<android::StringPiece> args; |
| 29 | args.push_back(path); |
| 30 | args.push_back("-o"); |
| 31 | args.push_back(outDir); |
| 32 | args.push_back("-v"); |
| 33 | if (legacy) { |
| 34 | args.push_back("--legacy"); |
| 35 | } |
Ryan Mitchell | 833a1a6 | 2018-07-10 13:51:36 -0700 | [diff] [blame] | 36 | return CompileCommand(&diag).Execute(args, &std::cerr); |
y | d6b8329 | 2018-04-11 09:54:56 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | TEST(CompilerTest, MultiplePeriods) { |
| 40 | StdErrDiagnostics diag; |
| 41 | std::unique_ptr<IAaptContext> context = test::ContextBuilder().Build(); |
| 42 | const std::string kResDir = android::base::Dirname(android::base::GetExecutablePath()) |
| 43 | + "/integration-tests/CompileTest/res"; |
| 44 | |
| 45 | // Resource files without periods in the file name should not throw errors |
| 46 | const std::string path0 = kResDir + "/values/values.xml"; |
| 47 | const std::string path0_out = kResDir + "/values_values.arsc.flat"; |
| 48 | |
| 49 | remove(path0_out.c_str()); |
| 50 | ASSERT_EQ(TestCompile(path0, kResDir, /** legacy */ false, diag), 0); |
| 51 | ASSERT_EQ(remove(path0_out.c_str()), 0); |
| 52 | ASSERT_EQ(TestCompile(path0, kResDir, /** legacy */ true, diag), 0); |
| 53 | ASSERT_EQ(remove(path0_out.c_str()), 0); |
| 54 | |
| 55 | const std::string path1 = kResDir + "/drawable/image.png"; |
| 56 | const std::string path1_out = kResDir + "/drawable_image.png.flat"; |
| 57 | remove(path1_out.c_str()); |
| 58 | ASSERT_EQ(TestCompile(path1, kResDir, /** legacy */ false, diag), 0); |
| 59 | ASSERT_EQ(remove(path1_out.c_str()), 0); |
| 60 | ASSERT_EQ(TestCompile(path1, kResDir, /** legacy */ true, diag), 0); |
| 61 | ASSERT_EQ(remove(path1_out.c_str()), 0); |
| 62 | |
| 63 | const std::string path2 = kResDir + "/drawable/image.9.png"; |
| 64 | const std::string path2_out = kResDir + "/drawable_image.9.png.flat"; |
| 65 | remove(path2_out.c_str()); |
| 66 | ASSERT_EQ(TestCompile(path2, kResDir, /** legacy */ false, diag), 0); |
| 67 | ASSERT_EQ(remove(path2_out.c_str()), 0); |
| 68 | ASSERT_EQ(TestCompile(path2, kResDir, /** legacy */ true, diag), 0); |
| 69 | ASSERT_EQ(remove(path2_out.c_str()), 0); |
| 70 | |
| 71 | // Resource files with periods in the file name should fail on non-legacy compilations |
| 72 | const std::string path3 = kResDir + "/values/values.all.xml"; |
| 73 | const std::string path3_out = kResDir + "/values_values.all.arsc.flat"; |
| 74 | remove(path3_out.c_str()); |
| 75 | ASSERT_NE(TestCompile(path3, kResDir, /** legacy */ false, diag), 0); |
| 76 | ASSERT_NE(remove(path3_out.c_str()), 0); |
| 77 | ASSERT_EQ(TestCompile(path3, kResDir, /** legacy */ true, diag), 0); |
| 78 | ASSERT_EQ(remove(path3_out.c_str()), 0); |
| 79 | |
| 80 | const std::string path4 = kResDir + "/drawable/image.small.png"; |
| 81 | const std::string path4_out = (kResDir + std::string("/drawable_image.small.png.flat")).c_str(); |
| 82 | remove(path4_out.c_str()); |
| 83 | ASSERT_NE(TestCompile(path4, kResDir, /** legacy */ false, diag), 0); |
| 84 | ASSERT_NE(remove(path4_out.c_str()), 0); |
| 85 | ASSERT_EQ(TestCompile(path4, kResDir, /** legacy */ true, diag), 0); |
| 86 | ASSERT_EQ(remove(path4_out.c_str()), 0); |
| 87 | |
| 88 | const std::string path5 = kResDir + "/drawable/image.small.9.png"; |
| 89 | const std::string path5_out = (kResDir + std::string("/drawable_image.small.9.png.flat")).c_str(); |
| 90 | remove(path5_out.c_str()); |
| 91 | ASSERT_NE(TestCompile(path5, kResDir, /** legacy */ false, diag), 0); |
| 92 | ASSERT_NE(remove(path5_out.c_str()), 0); |
| 93 | ASSERT_EQ(TestCompile(path5, kResDir, /** legacy */ true, diag), 0); |
| 94 | ASSERT_EQ(remove(path5_out.c_str()), 0); |
| 95 | } |
| 96 | |
| 97 | } |