• 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: IsCloudStatusOkay001
108  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
109  * @tc.type: FUNC
110  * @tc.require: SR000HRKKA
111  */
112 HWTEST_F(CloudStatusTest, IsCloudStatusOkay001, TestSize.Level1)
113 {
114     CloudStatus cloudStatus;
115     const string bundleName = "ohos.com.demo";
116     const int32_t userId = -1;
117     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
118     EXPECT_EQ(ret, false);
119 }
120 
121 /**
122  * @tc.name: IsCloudStatusOkay002
123  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
124  * @tc.type: FUNC
125  * @tc.require: SR000HRKKA
126  */
127 HWTEST_F(CloudStatusTest, IsCloudStatusOkay002, TestSize.Level1)
128 {
129     CloudStatus cloudStatus;
130     const string bundleName = "ohos.com.demo1";
131     const int32_t userId = 1;
132     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
133     EXPECT_EQ(ret, false);
134 }
135 
136 /**
137  * @tc.name: ChangeAppSwitch001
138  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
139  * @tc.type: FUNC
140  * @tc.require: SR000HRKKA
141  */
142 HWTEST_F(CloudStatusTest, ChangeAppSwitch001, TestSize.Level1)
143 {
144     CloudStatus cloudStatus;
145     const string bundleName = "ohos.com.demo2";
146     const int32_t userId = -1;
147     bool appSwitchStatus = true;
148     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
149     EXPECT_EQ(ret, E_OK);
150 }
151 
152 /**
153  * @tc.name: ChangeAppSwitch002
154  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
155  * @tc.type: FUNC
156  * @tc.require: SR000HRKKA
157  */
158 HWTEST_F(CloudStatusTest, ChangeAppSwitch002, TestSize.Level1)
159 {
160     CloudStatus cloudStatus;
161     const string bundleName = "ohos.com.demo3";
162     const int32_t userId = 1;
163     bool appSwitchStatus = true;
164     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
165     EXPECT_EQ(ret, E_OK);
166 }
167 
168 /**
169  * @tc.name: ChangeAppSwitch003
170  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
171  * @tc.type: FUNC
172  * @tc.require: SR000HRKKA
173  */
174 HWTEST_F(CloudStatusTest, ChangeAppSwitch003, TestSize.Level1)
175 {
176     CloudStatus cloudStatus;
177     const string bundleName = "ohos.com.demo3";
178     const int32_t userId = 1;
179     bool appSwitchStatus = true;
180     cloudStatus.appSwitches_.clear();
181     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
182     EXPECT_EQ(ret, E_OK);
183 }
184 
185 /**
186  * @tc.name: IsAccountIdChanged001
187  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
188  * @tc.type: FUNC
189  * @tc.require: SR000HRKKA
190  */
191 HWTEST_F(CloudStatusTest, IsAccountIdChanged001, TestSize.Level1)
192 {
193     CloudStatus cloudStatus;
194     std::string accountId = "IsAccountIdChanged";
195     cloudStatus.userInfo_.accountId = "CloudStatusTest";
196     auto ret = cloudStatus.IsAccountIdChanged(accountId);
197     EXPECT_EQ(ret, true);
198 }
199 
200 /**
201  * @tc.name: IsAccountIdChanged002
202  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
203  * @tc.type: FUNC
204  * @tc.require: SR000HRKKA
205  */
206 HWTEST_F(CloudStatusTest, IsAccountIdChanged002, TestSize.Level1)
207 {
208     CloudStatus cloudStatus;
209     std::string accountId = "IsAccountIdChanged";
210     cloudStatus.userInfo_.accountId = "";
211     auto ret = cloudStatus.IsAccountIdChanged(accountId);
212     EXPECT_EQ(ret, false);
213 }
214 } // namespace OHOS::FileManagement::CloudSync::Test