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 "clear_up_application_data_plugin_test.h"
17
18 #include "clear_up_application_data_param.h"
19 #include "clear_up_application_data_plugin.h"
20 #include "edm_ipc_interface_code.h"
21 #include "plugin_singleton.h"
22 #include "utils.h"
23
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace EDM {
28 namespace TEST {
SetUpTestSuite(void)29 void ClearUpApplicationDataPluginTest::SetUpTestSuite(void)
30 {
31 Utils::SetEdmInitialEnv();
32 }
33
TearDownTestSuite(void)34 void ClearUpApplicationDataPluginTest::TearDownTestSuite(void)
35 {
36 Utils::ResetTokenTypeAndUid();
37 ASSERT_TRUE(Utils::IsOriginalUTEnv());
38 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
39 }
40
41 /**
42 * @tc.name: TestClearUpApplicationData
43 * @tc.desc: Test ClearUpApplicationDataPluginTest::OnSetPolicy function fail.
44 * @tc.type: FUNC
45 */
46 HWTEST_F(ClearUpApplicationDataPluginTest, TestClearUpApplicationData, TestSize.Level1)
47 {
48 uint64_t selfTokenId = GetSelfTokenID();
49 SetSelfTokenID(0);
50 std::shared_ptr<IPlugin> plugin = ClearUpApplicationDataPlugin::GetPlugin();
51 uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::CLEAR_UP_APPLICATION_DATA);
52 HandlePolicyData handlePolicyData { "", "", false };
53 MessageParcel data;
54 MessageParcel reply;
55 ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
56 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
57 SetSelfTokenID(selfTokenId);
58 }
59 } // namespace TEST
60 } // namespace EDM
61 } // namespace OHOS
62