• 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_mobile_data_plugin_test.h"
17 
18 #include "core_service_client.h"
19 #include "disallow_mobile_data_plugin.h"
20 #include "edm_constants.h"
21 #include "edm_ipc_interface_code.h"
22 #include "iplugin_manager.h"
23 #include "parameters.h"
24 #include "plugin_singleton.h"
25 #include "telephony_types.h"
26 #include "utils.h"
27 
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace EDM {
32 namespace TEST {
SetUpTestSuite(void)33 void DisallowMobileDataTest::SetUpTestSuite(void)
34 {
35     Utils::SetEdmInitialEnv();
36 }
37 
TearDownTestSuite(void)38 void DisallowMobileDataTest::TearDownTestSuite(void)
39 {
40     Utils::ResetTokenTypeAndUid();
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: TestDisallowMobileDataSuccess_001
47  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_001, TestSize.Level1)
51 {
52     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
53     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
54     HandlePolicyData handlePolicyData{"false", "", false};
55     MessageParcel data;
56     MessageParcel reply;
57     data.WriteBool(true);
58     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
59     ASSERT_TRUE(ret == ERR_OK);
60 }
61 
62 /**
63  * @tc.name: TestDisallowMobileDataSuccess_002
64  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
65  * @tc.type: FUNC
66  */
67 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_002, TestSize.Level1)
68 {
69     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
70     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
71     HandlePolicyData handlePolicyData{"true", "", true};
72     MessageParcel data;
73     MessageParcel reply;
74     data.WriteBool(false);
75     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
76     ASSERT_TRUE(ret == ERR_OK);
77 }
78 
79 /**
80  * @tc.name: TestDisallowMobileDataSuccess_003
81  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
82  * @tc.type: FUNC
83  */
84 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_003, TestSize.Level1)
85 {
86     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
87     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
88     HandlePolicyData handlePolicyData{"false", "", false};
89     MessageParcel data;
90     MessageParcel reply;
91     data.WriteString(EdmConstants::MobileData::DISALLOW_FLAG);
92     data.WriteBool(true);
93     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
94     ASSERT_TRUE(ret == ERR_OK);
95 }
96 
97 /**
98  * @tc.name: TestDisallowMobileDataSuccess_004
99  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_004, TestSize.Level1)
103 {
104     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
105     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
106     HandlePolicyData handlePolicyData{"true", "", true};
107     MessageParcel data;
108     MessageParcel reply;
109     data.WriteString(EdmConstants::MobileData::DISALLOW_FLAG);
110     data.WriteBool(false);
111     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
112     ASSERT_TRUE(ret == ERR_OK);
113 }
114 
115 /**
116  * @tc.name: TestDisallowMobileDataSuccess_005
117  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
118  * @tc.type: FUNC
119  */
120 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_005, TestSize.Level1)
121 {
122     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
123     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
124     HandlePolicyData handlePolicyData{"", "", false};
125     MessageParcel data;
126     MessageParcel reply;
127     data.WriteString(EdmConstants::MobileData::FORCE_FLAG);
128     data.WriteInt32(EdmConstants::MobileData::FORCE_OPEN);
129     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
130     ASSERT_TRUE(ret == ERR_OK);
131 }
132 
133 /**
134  * @tc.name: TestDisallowMobileDataSuccess_006
135  * @tc.desc: Test DisallowMobileDataPlugin::OnSetPolicy function sucess.
136  * @tc.type: FUNC
137  */
138 HWTEST_F(DisallowMobileDataTest, TestDisallowMobileDataSuccess_006, TestSize.Level1)
139 {
140     std::shared_ptr<DisallowMobileDataPlugin> plugin = std::make_shared<DisallowMobileDataPlugin>();
141     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_MOBILE_DATA);
142     HandlePolicyData handlePolicyData{"", "", false};
143     MessageParcel data;
144     MessageParcel reply;
145     data.WriteString(EdmConstants::MobileData::FORCE_FLAG);
146     data.WriteInt32(EdmConstants::MobileData::FORCE_OPEN);
147     system::SetParameter("persist.edm.mobile_data_policy", "disallow");
148     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
149     ASSERT_TRUE(ret == EdmReturnErrCode::ENTERPRISE_POLICES_DENIED);
150     system::SetParameter("persist.edm.mobile_data_policy", "none");
151 }
152 } // namespace TEST
153 } // namespace EDM
154 } // namespace OHOS