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 <gtest/gtest.h>
17 #include "disable_maintenance_mode_plugin.h"
18 #include "edm_ipc_interface_code.h"
19 #include "iplugin_manager.h"
20 #include "parameters.h"
21 #include "plugin_singleton.h"
22 #include "utils.h"
23
24 using namespace testing::ext;
25 using namespace testing;
26
27 namespace OHOS {
28 namespace EDM {
29 namespace TEST {
30 const std::string PERSIST_EDM_MAINTENANCE_MODE = "persist.edm.maintenance_mode";
31 class DisableMaintenanceModePluginTest : public testing::Test {
32 protected:
33 static void SetUpTestSuite(void);
34
35 static void TearDownTestSuite(void);
36 };
37
SetUpTestSuite(void)38 void DisableMaintenanceModePluginTest::SetUpTestSuite(void)
39 {
40 Utils::SetEdmServiceEnable();
41 Utils::SetEdmInitialEnv();
42 }
43
TearDownTestSuite(void)44 void DisableMaintenanceModePluginTest::TearDownTestSuite(void)
45 {
46 Utils::SetEdmServiceDisable();
47 Utils::ResetTokenTypeAndUid();
48 OHOS::system::SetParameter(PERSIST_EDM_MAINTENANCE_MODE, "false");
49 ASSERT_TRUE(Utils::IsOriginalUTEnv());
50 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
51 }
52
53 /**
54 * @tc.name: TestDisableMaintenanceModePluginTestSetTrue
55 * @tc.desc: Test DisableMaintenanceModePluginTest::OnSetPolicy function.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(DisableMaintenanceModePluginTest, TestDisableMaintenanceModePluginTestSetTrue, TestSize.Level1)
59 {
60 MessageParcel data;
61 MessageParcel reply;
62 data.WriteBool(true);
63 std::shared_ptr<IPlugin> plugin = DisableMaintenanceModePlugin::GetPlugin();
64 HandlePolicyData handlePolicyData{"false", "", false};
65 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
66 EdmInterfaceCode::DISABLE_MAINTENANCE_MODE);
67 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
68 ASSERT_TRUE(ret == ERR_OK);
69 ASSERT_TRUE(OHOS::system::GetBoolParameter(PERSIST_EDM_MAINTENANCE_MODE, false));
70 }
71
72 /**
73 * @tc.name: TestDisableMaintenanceModePluginTestSetFalse
74 * @tc.desc: Test DisableMaintenanceModePluginTest::OnSetPolicy function.
75 * @tc.type: FUNC
76 */
77 HWTEST_F(DisableMaintenanceModePluginTest, TestDisableMaintenanceModePluginTestSetFalse, TestSize.Level1)
78 {
79 MessageParcel data;
80 MessageParcel reply;
81 data.WriteBool(false);
82 std::shared_ptr<IPlugin> plugin = DisableMaintenanceModePlugin::GetPlugin();
83 HandlePolicyData handlePolicyData{"false", "", false};
84 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
85 EdmInterfaceCode::DISABLE_MAINTENANCE_MODE);
86 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
87 ASSERT_TRUE(ret == ERR_OK);
88 ASSERT_FALSE(OHOS::system::GetBoolParameter(PERSIST_EDM_MAINTENANCE_MODE, true));
89 }
90 } // namespace TEST
91 } // namespace EDM
92 } // namespace OHOS