1 /*
2 * Copyright (c) 2024 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 <vector>
18
19 #include "disallow_modify_apn_plugin.h"
20 #include "edm_ipc_interface_code.h"
21 #include "inactive_user_freeze_plugin.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 DisallowModifyAPNPluginTest
31 : public testing::TestWithParam<std::pair<std::shared_ptr<IPlugin>, EdmInterfaceCode>> {
32 protected:
33 static void SetUpTestSuite(void);
34
35 static void TearDownTestSuite(void);
36 };
37
SetUpTestSuite(void)38 void DisallowModifyAPNPluginTest::SetUpTestSuite(void)
39 {
40 Utils::SetEdmInitialEnv();
41 }
42
TearDownTestSuite(void)43 void DisallowModifyAPNPluginTest::TearDownTestSuite(void)
44 {
45 Utils::ResetTokenTypeAndUid();
46 ASSERT_TRUE(Utils::IsOriginalUTEnv());
47 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
48 }
49
50 INSTANTIATE_TEST_SUITE_P(TestOnSetPolicy, DisallowModifyAPNPluginTest,
51 testing::ValuesIn(std::vector<std::pair<std::shared_ptr<IPlugin>, EdmInterfaceCode>>({
52 {DisallowModifyAPNPlugin::GetPlugin(), EdmInterfaceCode::DISALLOW_MODIFY_APN}
53 })));
54
55 /**
56 * @tc.name: TestOnSetPolicy
57 * @tc.desc: Test DisallowedTetheringPluginTest::OnSetPolicy function.
58 * @tc.type: FUNC
59 */
60 HWTEST_P(DisallowModifyAPNPluginTest, TestOnSetPolicy, TestSize.Level1)
61 {
62 auto param = GetParam();
63 MessageParcel data;
64 MessageParcel reply;
65 data.WriteBool(true);
66 std::shared_ptr<IPlugin> plugin = param.first;
67 HandlePolicyData handlePolicyData{"false", "", false};
68 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, param.second);
69 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
70 ASSERT_TRUE(ret == ERR_OK);
71 ASSERT_TRUE(handlePolicyData.policyData == "true");
72 ASSERT_TRUE(handlePolicyData.isChanged);
73 }
74 } // namespace TEST
75 } // namespace EDM
76 } // namespace OHOS