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