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