1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "disallow_power_long_press_plugin_test.h"
17 #include "disallow_power_long_press_plugin.h"
18 #include "edm_ipc_interface_code.h"
19 #include "iplugin.h"
20 #include "utils.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace EDM {
26 namespace TEST {
SetUpTestSuite(void)27 void DisallowPowerLongPressPluginTest::SetUpTestSuite(void)
28 {
29 Utils::SetEdmInitialEnv();
30 }
31
TearDownTestSuite(void)32 void DisallowPowerLongPressPluginTest::TearDownTestSuite(void)
33 {
34 Utils::ResetTokenTypeAndUid();
35 ASSERT_TRUE(Utils::IsOriginalUTEnv());
36 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
37 }
38
39 /**
40 * @tc.name: TestDisallowPowerLongPressPlugin
41 * @tc.desc: Test DisallowPowerLongPressPlugin::OnSetPolicy function.
42 * @tc.type: FUNC
43 */
44 HWTEST_F(DisallowPowerLongPressPluginTest, TestDisallowPowerLongPressPluginTest001, TestSize.Level1)
45 {
46 MessageParcel data;
47 MessageParcel reply;
48 data.WriteBool(true);
49 std::shared_ptr<IPlugin> plugin = DisallowPowerLongPressPlugin::GetPlugin();
50 std::uint32_t funcCode =
51 POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOW_POWER_LONG_PRESS);
52 HandlePolicyData handlePolicyData{"", "", false};
53 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
54 ASSERT_TRUE(ret == ERR_OK);
55 ASSERT_TRUE(handlePolicyData.policyData == "true");
56 ASSERT_TRUE(handlePolicyData.isChanged);
57 }
58 } // namespace TEST
59 } // namespace EDM
60 } // namespace OHOS