Jeremy Meyer | 16c83af | 2024-07-26 16:21:49 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2022 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 "LoadedApk.h" |
| 18 | #include "cmd/Dump.h" |
| 19 | #include "io/StringStream.h" |
| 20 | #include "test/Test.h" |
| 21 | #include "text/Printer.h" |
| 22 | |
| 23 | using ::aapt::io::StringOutputStream; |
| 24 | using ::aapt::text::Printer; |
| 25 | using testing::Eq; |
| 26 | using testing::Ne; |
| 27 | |
| 28 | namespace aapt { |
| 29 | |
| 30 | using FlaggedResourcesTest = CommandTestFixture; |
| 31 | |
| 32 | static android::NoOpDiagnostics noop_diag; |
| 33 | |
| 34 | void DumpStringPoolToString(LoadedApk* loaded_apk, std::string* output) { |
| 35 | StringOutputStream output_stream(output); |
| 36 | Printer printer(&output_stream); |
| 37 | |
| 38 | DumpStringsCommand command(&printer, &noop_diag); |
| 39 | ASSERT_EQ(command.Dump(loaded_apk), 0); |
| 40 | output_stream.Flush(); |
| 41 | } |
| 42 | |
| 43 | TEST_F(FlaggedResourcesTest, DisabledStringRemoved) { |
| 44 | auto apk_path = file::BuildPath({android::base::GetExecutableDirectory(), "resapp.apk"}); |
| 45 | auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag); |
| 46 | |
| 47 | std::string output; |
| 48 | DumpStringPoolToString(loaded_apk.get(), &output); |
| 49 | |
| 50 | std::string excluded = "DONTFIND"; |
| 51 | ASSERT_EQ(output.find(excluded), std::string::npos); |
| 52 | } |
| 53 | |
| 54 | } // namespace aapt |