mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 15:00:12 +00:00
fix ut display_manager_service_test
Signed-off-by: zhangkai <zhangkai324@huawei.com> Change-Id: I68fd3737f713a47c65d1d38fe5a126ecfc142d5e
This commit is contained in:
parent
2fc71f6d7b
commit
e78eee384b
@ -18,6 +18,8 @@
|
||||
#include "display_manager_config.h"
|
||||
#include "display_manager_service.h"
|
||||
#include "display_manager_agent_default.h"
|
||||
#include "common_test_utils.h"
|
||||
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -31,6 +33,7 @@ public:
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
void SetAceessTokenPermission(const std::string processName);
|
||||
static sptr<DisplayManagerService> dms_;
|
||||
};
|
||||
|
||||
@ -49,6 +52,9 @@ void DisplayManagerServiceTest::SetUpTestCase()
|
||||
dms_->abstractScreenController_->screenIdManager_.dms2RsScreenIdMap_ = {
|
||||
{0, 0}
|
||||
};
|
||||
const char** perms = new const char *[1];
|
||||
perms[0] = "ohos.permission.CAPTURE_SCREEN";
|
||||
CommonTestUtils::SetAceessTokenPermission("DisplayManagerServiceTest", perms, 1);
|
||||
}
|
||||
|
||||
void DisplayManagerServiceTest::TearDownTestCase()
|
||||
|
@ -27,6 +27,8 @@ public:
|
||||
static constexpr int32_t TEST_IMAGE_HEIGHT = 1080;
|
||||
static constexpr int32_t TEST_IMAGE_WIDTH = 1920;
|
||||
static void SetAceessTokenPermission(const std::string processName);
|
||||
static void SetAceessTokenPermission(const std::string processName,
|
||||
const char** perms, const int permCount);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // TEST_UTILS_H
|
@ -83,4 +83,26 @@ void CommonTestUtils::SetAceessTokenPermission(const std::string processName)
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
|
||||
void CommonTestUtils::SetAceessTokenPermission(const std::string processName,
|
||||
const char** perms, const int permCount)
|
||||
{
|
||||
if (perms == nullptr || permCount == 0) {
|
||||
return;
|
||||
}
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = permCount,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = processName.c_str(),
|
||||
.aplStr = "system_basic",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
@ -72,12 +72,12 @@ sptr<DisplayPowerEventListener> DisplayPowerTest::listener_ = new DisplayPowerEv
|
||||
|
||||
void DisplayPowerTest::SetUpTestCase()
|
||||
{
|
||||
CommonTestUtils::SetAceessTokenPermission("SetDisplayState");
|
||||
defaultId_ = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
if (defaultId_ == DISPLAY_ID_INVALID) {
|
||||
WLOGFE("GetDefaultDisplayId failed!");
|
||||
}
|
||||
DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_);
|
||||
CommonTestUtils::SetAceessTokenPermission("SetDisplayState");
|
||||
}
|
||||
|
||||
void DisplayPowerTest::TearDownTestCase()
|
||||
|
Loading…
Reference in New Issue
Block a user