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 #include "disable_print_plugin.h"
18 #include "edm_errors.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 DisablePrintPluginTest : public testing::Test {
31 protected:
32 static void SetUpTestSuite(void);
33
34 static void TearDownTestSuite(void);
35 };
36
SetUpTestSuite(void)37 void DisablePrintPluginTest::SetUpTestSuite(void)
38 {
39 Utils::SetEdmInitialEnv();
40 }
41
TearDownTestSuite(void)42 void DisablePrintPluginTest::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: TestDisablePrintPluginTestSet
51 * @tc.desc: Test DisablePrintPluginTest::OnSetPolicy function.
52 * @tc.type: FUNC
53 */
54 HWTEST_F(DisablePrintPluginTest, TestDisablePrintPluginTestSet, TestSize.Level1)
55 {
56 MessageParcel data;
57 MessageParcel reply;
58 data.WriteBool(true);
59 std::shared_ptr<IPlugin> plugin = DisablePrintPlugin::GetPlugin();
60 HandlePolicyData handlePolicyData{"false", "", false};
61 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
62 EdmInterfaceCode::DISABLED_PRINT);
63 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
64
65 ASSERT_TRUE(ret == ERR_OK);
66 ASSERT_TRUE(handlePolicyData.policyData == "true");
67 ASSERT_TRUE(handlePolicyData.isChanged);
68
69 MessageParcel dataFalse;
70 dataFalse.WriteBool(false);
71 HandlePolicyData handlePolicyDataFalse{"true", "", false};
72 ret = plugin->OnHandlePolicy(funcCode, dataFalse, reply, handlePolicyDataFalse, DEFAULT_USER_ID);
73 ASSERT_TRUE(ret == ERR_OK);
74 ASSERT_TRUE(handlePolicyDataFalse.policyData == "false");
75 ASSERT_FALSE(handlePolicyDataFalse.isChanged);
76 }
77 } // namespace TEST
78 } // namespace EDM
79 } // namespace OHOS