• 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 #include <vector>
18 
19 #include "disallowed_sim_plugin.h"
20 #include "edm_ipc_interface_code.h"
21 #include "inactive_user_freeze_plugin.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 DisallowedSimPluginTest : public testing::Test {
31 protected:
32     static void SetUpTestSuite(void);
33 
34     static void TearDownTestSuite(void);
35 };
36 
SetUpTestSuite(void)37 void DisallowedSimPluginTest::SetUpTestSuite(void)
38 {
39     Utils::SetEdmInitialEnv();
40 }
41 
TearDownTestSuite(void)42 void DisallowedSimPluginTest::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: TestDisallowedSim0Success
51  * @tc.desc: Test DisallowedSimPlugin::OnSetPolicy function sucess.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(DisallowedSimPluginTest, TestDisallowedSim0Success, TestSize.Level1)
55 {
56     DisallowedSimPlugin plugin;
57     uint32_t policies = 0;
58     uint32_t currentData = 0;
59     uint32_t mergeData = 0;
60     ErrCode ret = plugin.OnSetPolicy(policies, currentData, mergeData, DEFAULT_USER_ID);
61     ASSERT_TRUE(ret == ERR_OK);
62 }
63 
64 /**
65  * @tc.name: TestDisallowedSim1Success
66  * @tc.desc: Test DisallowedSimPlugin::OnSetPolicy function sucess.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(DisallowedSimPluginTest, TestDisallowedSim1Success, TestSize.Level1)
70 {
71     DisallowedSimPlugin plugin;
72     uint32_t policies = 1;
73     uint32_t currentData = 0;
74     uint32_t mergeData = 0;
75     ErrCode ret = plugin.OnSetPolicy(policies, currentData, mergeData, DEFAULT_USER_ID);
76     ASSERT_TRUE(ret == ERR_OK);
77 }
78 
79 /**
80  * @tc.name: TestEnableSim0Success
81  * @tc.desc: Test DisallowedSimPlugin::OnRemovePolicy function sucess.
82  * @tc.type: FUNC
83  */
84 HWTEST_F(DisallowedSimPluginTest, TestEnableSim0Success, TestSize.Level1)
85 {
86     DisallowedSimPlugin plugin;
87     uint32_t policies = 0;
88     uint32_t currentData = 0;
89     uint32_t mergeData = 0;
90     ErrCode ret = plugin.OnRemovePolicy(policies, currentData, mergeData, DEFAULT_USER_ID);
91     ASSERT_TRUE(ret == ERR_OK);
92 }
93 
94 /**
95  * @tc.name: TestEnableSim1Success
96  * @tc.desc: Test DisallowedSimPlugin::OnRemovePolicy function sucess.
97  * @tc.type: FUNC
98  */
99 HWTEST_F(DisallowedSimPluginTest, TestEnableSim1Success, TestSize.Level1)
100 {
101     DisallowedSimPlugin plugin;
102     uint32_t policies = 1;
103     uint32_t currentData = 0;
104     uint32_t mergeData = 0;
105     ErrCode ret = plugin.OnRemovePolicy(policies, currentData, mergeData, DEFAULT_USER_ID);
106     ASSERT_TRUE(ret == ERR_OK);
107 }
108 
109 /**
110  * @tc.name: TestIsDisallowedSim0Success
111  * @tc.desc: Test DisallowedSimPlugin::OnGetPolicy function sucess.
112  * @tc.type: FUNC
113  */
114 HWTEST_F(DisallowedSimPluginTest, TestIsDisallowedSim0Success, TestSize.Level1)
115 {
116     MessageParcel data;
117     data.WriteInt32(0);
118     MessageParcel reply;
119     std::shared_ptr<IPlugin> plugin = DisallowedSimPlugin::GetPlugin();
120     std::string policyData{""};
121     ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
122     ASSERT_TRUE(ret == ERR_OK);
123     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
124     ASSERT_FALSE(reply.ReadBool());
125 }
126 
127 /**
128  * @tc.name: TestIsDisallowedSim1Success
129  * @tc.desc: Test DisallowedSimPlugin::OnGetPolicy function sucess.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(DisallowedSimPluginTest, TestIsDisallowedSim1Success, TestSize.Level1)
133 {
134     MessageParcel data;
135     data.WriteInt32(1);
136     MessageParcel reply;
137     std::shared_ptr<IPlugin> plugin = DisallowedSimPlugin::GetPlugin();
138     std::string policyData{""};
139     ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
140     ASSERT_TRUE(ret == ERR_OK);
141     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
142     ASSERT_FALSE(reply.ReadBool());
143 }
144 
145 } // namespace TEST
146 } // namespace EDM
147 } // namespace OHOS