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_mtp_server_plugin.h"
18 #include "edm_ipc_interface_code.h"
19 #include "iplugin_manager.h"
20 #include "plugin_singleton.h"
21 #include "utils.h"
22
23 using namespace testing::ext;
24 using namespace testing;
25
26 namespace OHOS {
27 namespace EDM {
28 namespace TEST {
29 class DisableMtpServerPluginTest : public testing::Test {
30 protected:
31 static void SetUpTestSuite(void);
32
33 static void TearDownTestSuite(void);
34 };
35
SetUpTestSuite(void)36 void DisableMtpServerPluginTest::SetUpTestSuite(void)
37 {
38 Utils::SetEdmInitialEnv();
39 }
40
TearDownTestSuite(void)41 void DisableMtpServerPluginTest::TearDownTestSuite(void)
42 {
43 Utils::ResetTokenTypeAndUid();
44 ASSERT_TRUE(Utils::IsOriginalUTEnv());
45 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
46 }
47
48 /**
49 * @tc.name: TestDisableMtpServerPluginTestSet
50 * @tc.desc: Test DisableMtpServerPluginTest::OnSetPolicy function.
51 * @tc.type: FUNC
52 */
53 HWTEST_F(DisableMtpServerPluginTest, TestDisableMtpServerPluginTestSet, TestSize.Level1)
54 {
55 MessageParcel data;
56 MessageParcel reply;
57 data.WriteBool(true);
58 std::shared_ptr<IPlugin> plugin = DisableMtpServerPlugin::GetPlugin();
59 HandlePolicyData handlePolicyData{"false", "", false};
60 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
61 EdmInterfaceCode::DISABLE_MTP_SERVER);
62 ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
63 ASSERT_TRUE(ret == ERR_OK);
64 ASSERT_TRUE(handlePolicyData.policyData == "true");
65 ASSERT_TRUE(handlePolicyData.isChanged);
66 }
67 } // namespace TEST
68 } // namespace EDM
69 } // namespace OHOS