Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dcead62a authored by Iurii Makhno's avatar Iurii Makhno
Browse files

Tests for 'aapt2 dump badging' command.

Bug: b/228949376
Test: Dump_test.cpp
Change-Id: If07e77b9281bdfd456df7c84f4a912bdf0851490
parent d6233c3f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ cc_test_host {
        "integration-tests/CompileTest/**/*",
        "integration-tests/CommandTests/**/*",
        "integration-tests/ConvertTest/**/*",
        "integration-tests/DumpTest/**/*",
    ],
}

+8 −0
Original line number Diff line number Diff line
@@ -131,6 +131,14 @@ class DumpBadgingCommand : public DumpApkCommand {
                      &options_.include_meta_data);
  }

  void SetIncludeMetaData(bool value) {
    options_.include_meta_data = value;
  }

  void SetOnlyPermissions(bool value) {
    options_.only_permissions = value;
  }

  int Dump(LoadedApk* apk) override {
    return DumpManifest(apk, options_, GetPrinter(), GetDiagnostics());
  }
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Dump.h"

#include "LoadedApk.h"
#include "io/StringStream.h"
#include "test/Test.h"
#include "text/Printer.h"

using ::aapt::io::StringOutputStream;
using ::aapt::text::Printer;
using testing::Eq;
using testing::Ne;

namespace aapt {

using DumpTest = CommandTestFixture;

class NoopDiagnostics : public IDiagnostics {
 public:
  void Log(Level level, DiagMessageActual& actualMsg) override {
  }
};
static NoopDiagnostics noop_diag;

void DumpBadgingToString(LoadedApk* loaded_apk, std::string* output, bool include_meta_data = false,
                         bool only_permissions = false) {
  StringOutputStream output_stream(output);
  Printer printer(&output_stream);

  DumpBadgingCommand command(&printer, &noop_diag);
  command.SetIncludeMetaData(include_meta_data);
  command.SetOnlyPermissions(only_permissions);
  ASSERT_EQ(command.Dump(loaded_apk), 0);
  output_stream.Flush();
}

TEST_F(DumpTest, DumpBadging) {
  auto apk_path = file::BuildPath(
      {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "minimal.apk"});
  auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);

  std::string output;
  DumpBadgingToString(loaded_apk.get(), &output);

  std::string expected;
  auto expected_path = file::BuildPath({android::base::GetExecutableDirectory(),
                                        "integration-tests", "DumpTest", "minimal_expected.txt"});
  ::android::base::ReadFileToString(expected_path, &expected);
  ASSERT_EQ(output, expected);
}

TEST_F(DumpTest, DumpBadgingAllComponents) {
  auto apk_path = file::BuildPath(
      {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"});
  auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);

  std::string output;
  DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ true);

  std::string expected;
  auto expected_path =
      file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
                       "components_expected.txt"});
  ::android::base::ReadFileToString(expected_path, &expected);
  ASSERT_EQ(output, expected);
}

TEST_F(DumpTest, DumpBadgingPermissionsOnly) {
  auto apk_path = file::BuildPath(
      {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"});
  auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);

  std::string output;
  DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ false,
                      /* only_permissions= */ true);

  std::string expected;
  auto expected_path =
      file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
                       "components_permissions_expected.txt"});
  ::android::base::ReadFileToString(expected_path, &expected);
  ASSERT_EQ(output, expected);
}

}  // namespace aapt
 No newline at end of file
+82.6 KiB

File added.

No diff preview for this file type.

+56 −0
Original line number Diff line number Diff line
package: name='com.example.bundletool.minimal' versionCode='1' versionName='1.0' platformBuildVersionName='12' platformBuildVersionCode='31' compileSdkVersion='31' compileSdkVersionCodename='12'
sdkVersion:'21'
targetSdkVersion:'31'
uses-configuration: reqTouchScreen='3' reqKeyboardType='2' reqHardKeyboard='-1' reqNavigation='3' reqFiveWayNav='-1'
supports-gl-texture:'GL_OES_compressed_paletted_texture'
uses-permission: name='android.permission.BIND_ACCESSIBILITY_SERVICE' maxSdkVersion='24'
uses-permission-sdk-23: name='android.permission.RECEIVE_SMS'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
compatible-screens:'500/240','400/160'
application-label:'minimal'
application-icon-160:'res/uF.xml'
application-icon-240:'res/uF.xml'
application-icon-320:'res/uF.xml'
application-icon-480:'res/uF.xml'
application-icon-640:'res/uF.xml'
application-icon-65534:'res/uF.xml'
application: label='minimal' icon='res/uF.xml'
uses-library:'mylib1'
uses-library-not-required:'my_optional_lib'
uses-native-library:'native1'
uses-native-library-not-required:'optional'
launchable-activity: name='com.example.bundletool.minimal.MainActivity'  label='minimal' icon=''
meta-data: name='android.nfc.cardemulation.host_apdu_service' resource='res/dU.xml'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
uses-implied-permission: name='android.permission.READ_EXTERNAL_STORAGE' reason='requested WRITE_EXTERNAL_STORAGE'
feature-group: label=''
  uses-feature: name='android.hardware.bluetooth'
  uses-feature: name='android.hardware.camera'
  uses-feature: name='android.hardware.faketouch'
  uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps'
  uses-feature-sdk-23: name='android.hardware.telephony'
  uses-implied-feature-sdk-23: name='android.hardware.telephony' reason='requested a telephony permission'
provides-component:'app-widget'
provides-component:'device-admin'
provides-component:'ime'
provides-component:'wallpaper'
provides-component:'accessibility'
provides-component:'print-service'
provides-component:'search'
provides-component:'document-provider'
provides-component:'notification-listener'
provides-component:'dream'
provides-component:'camera'
provides-component:'camera-secure'
main
other-receivers
other-services
supports-screens: 'normal' 'large' 'xlarge'
supports-any-density: 'true'
requires-smallest-width:'240'
compatible-width-limit:'360'
largest-width-limit:'480'
locales: '--_--'
densities: '160' '240' '320' '480' '640' '65534'
native-code: 'x86_64'
alt-native-code: 'x86'
Loading