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 "disallowed_tethering_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 DisallowedPolicyPluginTest
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 DisallowedPolicyPluginTest::SetUpTestSuite(void)
39 {
40 Utils::SetEdmInitialEnv();
41 }
42
TearDownTestSuite(void)43 void DisallowedPolicyPluginTest::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, DisallowedPolicyPluginTest,
51 testing::ValuesIn(std::vector<std::pair<std::shared_ptr<IPlugin>, EdmInterfaceCode>>({
52 {DisallowedTetheringPlugin::GetPlugin(), EdmInterfaceCode::DISALLOWED_TETHERING},
53 {InactiveUserFreezePlugin::GetPlugin(), EdmInterfaceCode::INACTIVE_USER_FREEZE}
54 })));
55
56 /**
57 * @tc.name: TestOnSetPolicy
58 * @tc.desc: Test DisallowedTetheringPluginTest::OnSetPolicy function.
59 * @tc.type: FUNC
60 */
61 HWTEST_P(DisallowedPolicyPluginTest, TestOnSetPolicy, TestSize.Level1)
62 {
63 auto param = GetParam();
64 MessageParcel data;
65 MessageParcel reply;
66 data.WriteBool(true);
67 std::shared_ptr<IPlugin> plugin = param.first;
68 HandlePolicyData handlePolicyData{"false", "", false};
69 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, param.second);
70 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
71 ASSERT_TRUE(ret == ERR_OK);
72 ASSERT_TRUE(handlePolicyData.policyData == "true");
73 ASSERT_TRUE(handlePolicyData.isChanged);
74 }
75 } // namespace TEST
76 } // namespace EDM
77 } // namespace OHOS