blob: 03da364f4f3e7bfbd8c7430cf070d22c32be2b27 [file] [log] [blame]
Iurii Makhnodcead622022-04-13 18:00:03 +00001/*
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 "Dump.h"
18
19#include "LoadedApk.h"
20#include "io/StringStream.h"
21#include "test/Test.h"
22#include "text/Printer.h"
23
24using ::aapt::io::StringOutputStream;
25using ::aapt::text::Printer;
26using testing::Eq;
27using testing::Ne;
28
29namespace aapt {
30
31using DumpTest = CommandTestFixture;
32
Jeremy Meyer56f36e82022-05-20 20:35:42 +000033static android::NoOpDiagnostics noop_diag;
Iurii Makhnodcead622022-04-13 18:00:03 +000034
35void DumpBadgingToString(LoadedApk* loaded_apk, std::string* output, bool include_meta_data = false,
36 bool only_permissions = false) {
37 StringOutputStream output_stream(output);
38 Printer printer(&output_stream);
39
40 DumpBadgingCommand command(&printer, &noop_diag);
41 command.SetIncludeMetaData(include_meta_data);
42 command.SetOnlyPermissions(only_permissions);
43 ASSERT_EQ(command.Dump(loaded_apk), 0);
44 output_stream.Flush();
45}
46
47TEST_F(DumpTest, DumpBadging) {
48 auto apk_path = file::BuildPath(
49 {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "minimal.apk"});
50 auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
51
52 std::string output;
53 DumpBadgingToString(loaded_apk.get(), &output);
54
55 std::string expected;
56 auto expected_path = file::BuildPath({android::base::GetExecutableDirectory(),
57 "integration-tests", "DumpTest", "minimal_expected.txt"});
58 ::android::base::ReadFileToString(expected_path, &expected);
59 ASSERT_EQ(output, expected);
60}
61
62TEST_F(DumpTest, DumpBadgingAllComponents) {
63 auto apk_path = file::BuildPath(
64 {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"});
65 auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
66
67 std::string output;
68 DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ true);
69
70 std::string expected;
71 auto expected_path =
72 file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
73 "components_expected.txt"});
74 ::android::base::ReadFileToString(expected_path, &expected);
75 ASSERT_EQ(output, expected);
76}
77
78TEST_F(DumpTest, DumpBadgingPermissionsOnly) {
79 auto apk_path = file::BuildPath(
80 {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"});
81 auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
82
83 std::string output;
84 DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ false,
85 /* only_permissions= */ true);
86
87 std::string expected;
88 auto expected_path =
89 file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
90 "components_permissions_expected.txt"});
91 ::android::base::ReadFileToString(expected_path, &expected);
92 ASSERT_EQ(output, expected);
93}
94
Jeremy Meyer56f36e82022-05-20 20:35:42 +000095} // namespace aapt