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 
22 namespace OHOS::FileManagement::CloudSync::Test {
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace std;
26 
27 class CloudStatusTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
SetUpTestCase(void)34 void CloudStatusTest::SetUpTestCase(void)
35 {
36     GTEST_LOG_(INFO) << "SetUpTestCase";
37 }
38 
TearDownTestCase(void)39 void CloudStatusTest::TearDownTestCase(void)
40 {
41     GTEST_LOG_(INFO) << "TearDownTestCase";
42 }
43 
SetUp(void)44 void CloudStatusTest::SetUp(void)
45 {
46     GTEST_LOG_(INFO) << "SetUp";
47 }
48 
TearDown(void)49 void CloudStatusTest::TearDown(void)
50 {
51     GTEST_LOG_(INFO) << "TearDown";
52 }
53 
54 /**
55  * @tc.name: GetCurrentCloudInfo001
56  * @tc.desc: Verify the CloudStatus::GetCurrentCloudInfo function
57  * @tc.type: FUNC
58  * @tc.require: SR000HRKKA
59  */
60 HWTEST_F(CloudStatusTest, GetCurrentCloudInfo001, TestSize.Level1)
61 {
62     CloudStatus cloudStatus;
63     const string bundleName = "ohos.com.test";
64     const int32_t userId = 1;
65     auto ret = cloudStatus.GetCurrentCloudInfo(bundleName, userId);
66     EXPECT_EQ(ret, E_NULLPTR);
67 }
68 
69 /**
70  * @tc.name: IsCloudStatusOkay001
71  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
72  * @tc.type: FUNC
73  * @tc.require: SR000HRKKA
74  */
75 HWTEST_F(CloudStatusTest, IsCloudStatusOkay001, TestSize.Level1)
76 {
77     CloudStatus cloudStatus;
78     const string bundleName = "ohos.com.demo";
79     const int32_t userId = -1;
80     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
81     EXPECT_EQ(ret, false);
82 }
83 
84 /**
85  * @tc.name: IsCloudStatusOkay002
86  * @tc.desc: Verify the CloudStatus::IsCloudStatusOkay function
87  * @tc.type: FUNC
88  * @tc.require: SR000HRKKA
89  */
90 HWTEST_F(CloudStatusTest, IsCloudStatusOkay002, TestSize.Level1)
91 {
92     CloudStatus cloudStatus;
93     const string bundleName = "ohos.com.demo1";
94     const int32_t userId = 1;
95     auto ret = cloudStatus.IsCloudStatusOkay(bundleName, userId);
96     EXPECT_EQ(ret, false);
97 }
98 
99 /**
100  * @tc.name: ChangeAppSwitch001
101  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
102  * @tc.type: FUNC
103  * @tc.require: SR000HRKKA
104  */
105 HWTEST_F(CloudStatusTest, ChangeAppSwitch001, TestSize.Level1)
106 {
107     CloudStatus cloudStatus;
108     const string bundleName = "ohos.com.demo2";
109     const int32_t userId = -1;
110     bool appSwitchStatus = true;
111     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
112     EXPECT_EQ(ret, E_OK);
113 }
114 
115 /**
116  * @tc.name: ChangeAppSwitch002
117  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
118  * @tc.type: FUNC
119  * @tc.require: SR000HRKKA
120  */
121 HWTEST_F(CloudStatusTest, ChangeAppSwitch002, TestSize.Level1)
122 {
123     CloudStatus cloudStatus;
124     const string bundleName = "ohos.com.demo3";
125     const int32_t userId = 1;
126     bool appSwitchStatus = true;
127     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
128     EXPECT_EQ(ret, E_OK);
129 }
130 
131 /**
132  * @tc.name: ChangeAppSwitch003
133  * @tc.desc: Verify the CloudStatus::ChangeAppSwitch function
134  * @tc.type: FUNC
135  * @tc.require: SR000HRKKA
136  */
137 HWTEST_F(CloudStatusTest, ChangeAppSwitch003, TestSize.Level1)
138 {
139     CloudStatus cloudStatus;
140     const string bundleName = "ohos.com.demo3";
141     const int32_t userId = 1;
142     bool appSwitchStatus = true;
143     cloudStatus.appSwitches_.clear();
144     auto ret = cloudStatus.ChangeAppSwitch(bundleName, userId, appSwitchStatus);
145     EXPECT_EQ(ret, E_OK);
146 }
147 
148 /**
149  * @tc.name: IsAccountIdChanged001
150  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
151  * @tc.type: FUNC
152  * @tc.require: SR000HRKKA
153  */
154 HWTEST_F(CloudStatusTest, IsAccountIdChanged001, TestSize.Level1)
155 {
156     CloudStatus cloudStatus;
157     std::string accountId = "IsAccountIdChanged";
158     cloudStatus.userInfo_.accountId = "CloudStatusTest";
159     auto ret = cloudStatus.IsAccountIdChanged(accountId);
160     EXPECT_EQ(ret, true);
161 }
162 
163 /**
164  * @tc.name: IsAccountIdChanged002
165  * @tc.desc: Verify the CloudStatus::IsAccountIdChanged function
166  * @tc.type: FUNC
167  * @tc.require: SR000HRKKA
168  */
169 HWTEST_F(CloudStatusTest, IsAccountIdChanged002, TestSize.Level1)
170 {
171     CloudStatus cloudStatus;
172     std::string accountId = "IsAccountIdChanged";
173     cloudStatus.userInfo_.accountId = "";
174     auto ret = cloudStatus.IsAccountIdChanged(accountId);
175     EXPECT_EQ(ret, false);
176 }
177 } // namespace OHOS::FileManagement::CloudSync::Test