• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "disable_set_device_name_plugin.h"
19 #include "edm_ipc_interface_code.h"
20 #include "iplugin_manager.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 class DisableSetDeviceNamePluginTest : public testing::Test {
31 protected:
32     static void SetUpTestSuite(void);
33 
34     static void TearDownTestSuite(void);
35 };
36 
SetUpTestSuite(void)37 void DisableSetDeviceNamePluginTest::SetUpTestSuite(void)
38 {
39     Utils::SetEdmInitialEnv();
40 }
41 
TearDownTestSuite(void)42 void DisableSetDeviceNamePluginTest::TearDownTestSuite(void)
43 {
44     Utils::ResetTokenTypeAndUid();
45     ASSERT_TRUE(Utils::IsOriginalUTEnv());
46     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
47 }
48 
49 /**
50  * @tc.name: TestDisableSetDeviceNamePluginTestCloseSetTrue
51  * @tc.desc: Test DisableSetDeviceNamePluginTest::OnSetPolicy function.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(DisableSetDeviceNamePluginTest, TestDisableSetDeviceNamePluginTestCloseSetTrue,
55     TestSize.Level1)
56 {
57     MessageParcel data;
58     MessageParcel reply;
59     data.WriteBool(true);
60     std::shared_ptr<IPlugin> plugin = DisableSetDeviceNamePlugin::GetPlugin();
61     HandlePolicyData handlePolicyData{"false", "", false};
62     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
63         EdmInterfaceCode::DISABLE_SET_DEVICE_NAME);
64     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
65 
66     ASSERT_TRUE(ret == ERR_OK);
67     ASSERT_TRUE(handlePolicyData.policyData == "true");
68     ASSERT_TRUE(handlePolicyData.isChanged);
69 
70     // 恢复环境,取消禁用
71     MessageParcel dataFalse;
72     dataFalse.WriteBool(false);
73     HandlePolicyData handlePolicyDataFalse{"true", "", false};
74     ret = plugin->OnHandlePolicy(funcCode, dataFalse, reply, handlePolicyDataFalse, DEFAULT_USER_ID);
75     ASSERT_TRUE(ret == ERR_OK);
76 }
77 } // namespace TEST
78 } // namespace EDM
79 } // namespace OHOS