• 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 <gtest/gtest.h>
17 #include "disable_user_mtp_client_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 DisableUserMtpClientPluginTest : public testing::Test {
31 protected:
32     static void SetUpTestSuite(void);
33 
34     static void TearDownTestSuite(void);
35 };
36 
SetUpTestSuite(void)37 void DisableUserMtpClientPluginTest::SetUpTestSuite(void)
38 {
39     Utils::SetEdmInitialEnv();
40 }
41 
TearDownTestSuite(void)42 void DisableUserMtpClientPluginTest::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: TestDisableUserMtpClientPluginTestSet
51  * @tc.desc: Test DisableUserMtpClientPluginTest::OnSetPolicy function.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(DisableUserMtpClientPluginTest, TestDisableUserMtpClientPluginTestSet, TestSize.Level1)
55 {
56     MessageParcel data;
57     MessageParcel reply;
58     data.WriteBool(true);
59     std::shared_ptr<IPlugin> plugin = DisableUserMtpClientPlugin::GetPlugin();
60     HandlePolicyData handlePolicyData{"false", "", false};
61     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
62         EdmInterfaceCode::DISABLE_USER_MTP_CLIENT);
63     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
64     ASSERT_TRUE(ret == ERR_OK);
65     ASSERT_TRUE(handlePolicyData.policyData == "true");
66     ASSERT_TRUE(handlePolicyData.isChanged);
67 
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 }
75 } // namespace TEST
76 } // namespace EDM
77 } // namespace OHOS