• 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "cloud_status.h"
20 #include "dfs_error.h"
21 #include "cloud_file_kit_mock.cpp"
22 
23 namespace OHOS::FileManagement::CloudSync::Test {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 
28 class CloudStatusTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34     static inline shared_ptr<CloudFileKitMock> ability = make_shared<CloudFileKitMock>();
35 };
SetUpTestCase(void)36 void CloudStatusTest::SetUpTestCase(void)
37 {
38     GTEST_LOG_(INFO) << "SetUpTestCase";
39 }
40 
TearDownTestCase(void)41 void CloudStatusTest::TearDownTestCase(void)
42 {
43     ability = nullptr;
44     GTEST_LOG_(INFO) << "TearDownTestCase";
45 }
46 
SetUp(void)47 void CloudStatusTest::SetUp(void)
48 {
49     GTEST_LOG_(INFO) << "SetUp";
50 }
51 
TearDown(void)52 void CloudStatusTest::TearDown(void)
53 {
54     GTEST_LOG_(INFO) << "TearDown";
55 }
56 
57 /**
58  * @tc.name: GetCurrentCloudInfo001
59  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
60  * @tc.type: FUNC
61  * @tc.require: SR000HRKKA
62  */
63 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo001, TestSize.Level1)
64 {
65     CloudStatus cloudStatus;
66     const string bundleName = "ohos.com.test";
67     const int32_t userId = 1;
68     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
69     EXPECT_EQ(ret, E_NULLPTR);
70 }
71 
72 /**
73  * @tc.name: GetCurrentCloudInfo002
74  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
75  * @tc.type: FUNC
76  * @tc.require: SR000HRKKA
77  */
78 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo002, TestSize.Level1)
79 {
80     CloudStatus cloudStatus;
81     const string bundleName = "ohos.com.test";
82     const int32_t userId = 1;
83     CloudFile::CloudFileKit::instance_ = ability.get();
84     EXPECT_CALL(*ability, GetCloudUserInfo(_, _)).WillOnce(Return(E_RDB)).WillRepeatedly(Return(E_OK));
85     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
86     EXPECT_EQ(ret, E_RDB);
87 }
88 
89 /**
90  * @tc.name: GetCurrentCloudInfo003
91  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
92  * @tc.type: FUNC
93  * @tc.require: SR000HRKKA
94  */
95 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo003, TestSize.Level1)
96 {
97     CloudStatus cloudStatus;
98     const string bundleName = "ohos.com.test";
99     const int32_t userId = 1;
100     CloudFile::CloudFileKit::instance_ = ability.get();
101     EXPECT_CALL(*ability, GetAppSwitchStatus(_, _, _)).WillOnce(Return(E_RDB)).WillRepeatedly(Return(E_OK));
102     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
103     EXPECT_EQ(ret, E_RDB);
104 }
105 
106 /**
107  * @tc.name: GetCurrentCloudInfo004
108  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
109  * @tc.type: FUNC
110  * @tc.require: SR000HRKKA
111  */
112 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo004, TestSize.Level1)
113 {
114     CloudStatus cloudStatus;
115     const string bundleName = "com.ohos.photos";
116     const int32_t userId = 1;
117     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
118     EXPECT_EQ(ret, E_OK);
119 }
120 
121 /**
122  * @tc.name: GetCurrentCloudInfo005
123  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
124  * @tc.type: FUNC
125  * @tc.require: SR000HRKKA
126  */
127 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo005, TestSize.Level1)
128 {
129     CloudStatus cloudStatus;
130     const string bundleName = "com.ohos.ailife";
131     const int32_t userId = 1;
132     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
133     EXPECT_EQ(ret, E_OK);
134 }
135 
136 /**
137  * @tc.name: IsCloudStatusOkay001
138  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
139  * @tc.type: FUNC
140  * @tc.require: SR000HRKKA
141  */
142 HWTEST_F(CloudStatusTest, IsCloudStatusOkay001, TestSize.Level1)
143 {
144     CloudStatus cloudStatus;
145     const string bundleName = "ohos.com.demo";
146     const int32_t userId = -1;
147     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
148     EXPECT_EQ(ret, false);
149 }
150 
151 /**
152  * @tc.name: IsCloudStatusOkay002
153  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
154  * @tc.type: FUNC
155  * @tc.require: SR000HRKKA
156  */
157 HWTEST_F(CloudStatusTest, IsCloudStatusOkay002, TestSize.Level1)
158 {
159     CloudStatus cloudStatus;
160     const string bundleName = "ohos.com.demo1";
161     const int32_t userId = 1;
162     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
163     EXPECT_EQ(ret, false);
164 }
165 
166 /**
167  * @tc.name: ChangeAppSwitch001
168  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
169  * @tc.type: FUNC
170  * @tc.require: SR000HRKKA
171  */
172 HWTEST_F(CloudStatusTest, ChangeAppSwitch001, TestSize.Level1)
173 {
174     CloudStatus cloudStatus;
175     const string bundleName = "ohos.com.demo2";
176     const int32_t userId = -1;
177     bool appSwitchStatus = true;
178     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
179     EXPECT_EQ(ret, E_OK);
180 }
181 
182 /**
183  * @tc.name: ChangeAppSwitch002
184  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
185  * @tc.type: FUNC
186  * @tc.require: SR000HRKKA
187  */
188 HWTEST_F(CloudStatusTest, ChangeAppSwitch002, TestSize.Level1)
189 {
190     CloudStatus cloudStatus;
191     const string bundleName = "ohos.com.demo3";
192     const int32_t userId = 1;
193     bool appSwitchStatus = true;
194     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
195     EXPECT_EQ(ret, E_OK);
196 }
197 
198 /**
199  * @tc.name: ChangeAppSwitch003
200  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
201  * @tc.type: FUNC
202  * @tc.require: SR000HRKKA
203  */
204 HWTEST_F(CloudStatusTest, ChangeAppSwitch003, TestSize.Level1)
205 {
206     CloudStatus cloudStatus;
207     const string bundleName = "ohos.com.demo3";
208     const int32_t userId = 1;
209     bool appSwitchStatus = true;
210     cloudStatus.appSwitches_.clear();
211     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
212     EXPECT_EQ(ret, E_OK);
213 }
214 
215 /**
216  * @tc.name: IsAccountIdChanged001
217  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
218  * @tc.type: FUNC
219  * @tc.require: SR000HRKKA
220  */
221 HWTEST_F(CloudStatusTest, IsAccountIdChanged001, TestSize.Level1)
222 {
223     CloudStatus cloudStatus;
224     std::string accountId = "IsAccountIdChanged";
225     cloudStatus.userInfo_.accountId = "CloudStatusTest";
226     auto ret = cloudStatus.IsAccountIdChanged(accountId);
227     EXPECT_EQ(ret, true);
228 }
229 
230 /**
231  * @tc.name: IsAccountIdChanged002
232  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
233  * @tc.type: FUNC
234  * @tc.require: SR000HRKKA
235  */
236 HWTEST_F(CloudStatusTest, IsAccountIdChanged002, TestSize.Level1)
237 {
238     CloudStatus cloudStatus;
239     std::string accountId = "IsAccountIdChanged";
240     cloudStatus.userInfo_.accountId = "";
241     auto ret = cloudStatus.IsAccountIdChanged(accountId);
242     EXPECT_EQ(ret, false);
243 }
244 } // namespace OHOS::FileManagement::CloudSync::Test