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