• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "snapshot_skip_plugin.h"
18 #include "edm_constants.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 const std::string TEST_BUNDLE_NAME = "testBundleName";
31 const std::string TEST_PACKAGE_NAME = "testPackageName";
32 
33 class SnapshotSkipPluginTest : public testing::Test {
34 protected:
35     static void SetUpTestSuite(void);
36 
37     static void TearDownTestSuite(void);
38 };
39 
SetUpTestSuite(void)40 void SnapshotSkipPluginTest::SetUpTestSuite(void)
41 {
42     Utils::SetEdmInitialEnv();
43 }
44 
TearDownTestSuite(void)45 void SnapshotSkipPluginTest::TearDownTestSuite(void)
46 {
47     Utils::ResetTokenTypeAndUid();
48     ASSERT_TRUE(Utils::IsOriginalUTEnv());
49     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
50 }
51 
52 /**
53  * @tc.name: SnapshotSkipPlugin
54  * @tc.desc: Test SnapshotSkipPlugin::OnSetPolicy when data is empty.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(SnapshotSkipPluginTest, TestOnSetPolicyWhenInputDataEmpty, TestSize.Level1)
58 {
59     SnapshotSkipPlugin plugin;
60     std::vector<std::string> data;
61     std::vector<std::string> currentData;
62     std::vector<std::string> mergeData;
63     ErrCode ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
64     ASSERT_TRUE(ret == ERR_OK);
65 }
66 
67 /**
68  * @tc.name: TestSnapshotSkipPlugin
69  * @tc.desc: Test SnapshotSkipPlugin::OnSetPolicy when data is over limit.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(SnapshotSkipPluginTest, TestOnSetPolicyWhenInputDataOverLimit, TestSize.Level1)
73 {
74     SnapshotSkipPlugin plugin;
75     std::vector<std::string> data(EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE + 1, TEST_BUNDLE_NAME);
76     std::vector<std::string> currentData;
77     std::vector<std::string> mergeData;
78     ErrCode ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
79     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
80 }
81 
82 /**
83  * @tc.name: TestSnapshotSkipPlugin
84  * @tc.desc: Test SnapshotSkipPlugin::OnSetPolicy when data is over limit.
85  * @tc.type: FUNC
86  */
87 HWTEST_F(SnapshotSkipPluginTest, TestOnSetPolicyWhenUnionDataOverLimit, TestSize.Level1)
88 {
89     SnapshotSkipPlugin plugin;
90     std::vector<std::string> data(EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE, TEST_PACKAGE_NAME);
91     std::vector<std::string> currentData(EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE, TEST_BUNDLE_NAME);
92     std::vector<std::string> mergeData;
93     ErrCode ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
94     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
95 }
96 
97 /**
98  * @tc.name: TestSnapshotSkipPlugin
99  * @tc.desc: Test SnapshotSkipPlugin::OnRemovePolicy when data is empty.
100  * @tc.type: FUNC
101  */
102 HWTEST_F(SnapshotSkipPluginTest, TestOnRemovePolicyWhenInputDataEmpty, TestSize.Level1)
103 {
104     SnapshotSkipPlugin plugin;
105     std::vector<std::string> data;
106     std::vector<std::string> currentData;
107     std::vector<std::string> mergeData;
108     ErrCode ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
109     ASSERT_TRUE(ret == ERR_OK);
110 }
111 
112 /**
113  * @tc.name: TestSnapshotSkipPlugin
114  * @tc.desc: Test SnapshotSkipPlugin::OnRemovePolicy when data is over limit.
115  * @tc.type: FUNC
116  */
117 HWTEST_F(SnapshotSkipPluginTest, TestOnRemovePolicyWhenInputDataOverLimit, TestSize.Level1)
118 {
119     SnapshotSkipPlugin plugin;
120     std::vector<std::string> data(EdmConstants::DISALLOW_LIST_FOR_ACCOUNT_MAX_SIZE + 1, TEST_BUNDLE_NAME);
121     std::vector<std::string> currentData;
122     std::vector<std::string> mergeData;
123     ErrCode ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
124     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
125 }
126 
127 /**
128  * @tc.name: TestSnapshotSkipPlugin
129  * @tc.desc: Test SnapshotSkipPlugin::OnGetPolicy function.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(SnapshotSkipPluginTest, TestOnGetPolicy, TestSize.Level1)
133 {
134     SnapshotSkipPlugin plugin;
135     std::string policyData;
136     MessageParcel data;
137     MessageParcel reply;
138     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
139     ASSERT_TRUE(ret == ERR_OK);
140 }
141 } // namespace TEST
142 } // namespace EDM
143 } // namespace OHOS