• 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 "sync_state_manager.h"
20 
21 namespace OHOS::FileManagement::CloudSync::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 
26 class SyncStateManagerTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase(void)34 void SyncStateManagerTest::SetUpTestCase(void)
35 {
36     GTEST_LOG_(INFO) << "SetUpTestCase";
37 }
38 
TearDownTestCase(void)39 void SyncStateManagerTest::TearDownTestCase(void)
40 {
41     GTEST_LOG_(INFO) << "TearDownTestCase";
42 }
43 
SetUp(void)44 void SyncStateManagerTest::SetUp(void)
45 {
46     GTEST_LOG_(INFO) << "SetUp";
47 }
48 
TearDown(void)49 void SyncStateManagerTest::TearDown(void)
50 {
51     GTEST_LOG_(INFO) << "TearDown";
52 }
53 
54 /**
55  * @tc.name: UpdateSyncState
56  * @tc.desc: Verify the UpdateSyncState function
57  * @tc.type: FUNC
58  * @tc.require: I6JPKG
59  */
60 HWTEST_F(SyncStateManagerTest, UpdateSyncState, TestSize.Level1)
61 {
62     GTEST_LOG_(INFO) << "UpdateSyncState Start";
63     SyncState newState = SyncState::SYNCING;
64     SyncStateManager syncStateMgr;
65     syncStateMgr.UpdateSyncState(newState);
66     EXPECT_EQ(syncStateMgr.state_, newState);
67     GTEST_LOG_(INFO) << "UpdateSyncState End";
68 }
69 
70 /**
71  * @tc.name: CheckAndSetPending001
72  * @tc.desc: Verify the CheckAndSetPending function
73  * @tc.type: FUNC
74  * @tc.require: I6JPKG
75  */
76 HWTEST_F(SyncStateManagerTest, CheckAndSetPending001, TestSize.Level1)
77 {
78     GTEST_LOG_(INFO) << "CheckAndSetPending001 Start";
79     SyncStateManager syncStateMgr;
80     syncStateMgr.state_ = SyncState::SYNC_FAILED;
81     auto ret = syncStateMgr.CheckAndSetPending(false, SyncTriggerType::CLOUD_TRIGGER);
82     EXPECT_EQ(ret, false);
83     GTEST_LOG_(INFO) << "CheckAndSetPending001 End";
84 }
85 
86 /**
87  * @tc.name: CheckAndSetPending002
88  * @tc.desc: Verify the CheckAndSetPending function
89  * @tc.type: FUNC
90  * @tc.require: I6JPKG
91  */
92 HWTEST_F(SyncStateManagerTest, CheckAndSetPending002, TestSize.Level1)
93 {
94     GTEST_LOG_(INFO) << "CheckAndSetPending002 Start";
95     SyncStateManager syncStateMgr;
96     syncStateMgr.state_ = SyncState::SYNCING;
97     auto ret = syncStateMgr.CheckAndSetPending(false, SyncTriggerType::CLOUD_TRIGGER);
98     EXPECT_EQ(ret, true);
99     GTEST_LOG_(INFO) << "CheckAndSetPending002 End";
100 }
101 
102 /**
103  * @tc.name: CheckAndSetPending003
104  * @tc.desc: Verify the CheckAndSetPending function
105  * @tc.type: FUNC
106  * @tc.require: I6JPKG
107  */
108 HWTEST_F(SyncStateManagerTest, CheckAndSetPending003, TestSize.Level1)
109 {
110     GTEST_LOG_(INFO) << "CheckAndSetPending003 Start";
111     SyncStateManager syncStateMgr;
112     syncStateMgr.state_ = SyncState::SYNCING;
113     auto ret = syncStateMgr.CheckAndSetPending(true, SyncTriggerType::CLOUD_TRIGGER);
114     EXPECT_EQ(ret, true);
115     GTEST_LOG_(INFO) << "CheckAndSetPending003 End";
116 }
117 
118 /**
119  * @tc.name: GetStopSyncFlag
120  * @tc.desc: Verify the GetStopSyncFlag function
121  * @tc.type: FUNC
122  * @tc.require: I6JPKG
123  */
124 HWTEST_F(SyncStateManagerTest, GetStopSyncFlag, TestSize.Level1)
125 {
126     GTEST_LOG_(INFO) << "GetStopSyncFlag Start";
127     SyncStateManager syncStateMgr;
128     auto ret = syncStateMgr.GetStopSyncFlag();
129     EXPECT_EQ(ret, false);
130     GTEST_LOG_(INFO) << "GetStopSyncFlag End";
131 }
132 
133 /**
134  * @tc.name: SetStopSyncFlag
135  * @tc.desc: Verify the SetStopSyncFlag function
136  * @tc.type: FUNC
137  * @tc.require: I6JPKG
138  */
139 HWTEST_F(SyncStateManagerTest, SetStopSyncFlag, TestSize.Level1)
140 {
141     GTEST_LOG_(INFO) << "SetStopSyncFlag Start";
142     SyncStateManager syncStateMgr;
143     syncStateMgr.SetStopSyncFlag();
144     EXPECT_EQ(syncStateMgr.stopSyncFlag_, true);
145     GTEST_LOG_(INFO) << "SetStopSyncFlag End";
146 }
147 
148 /**
149  * @tc.name: GetSyncState
150  * @tc.desc: Verify the GetSyncState function
151  * @tc.type: FUNC
152  * @tc.require: I6JPKG
153  */
154 HWTEST_F(SyncStateManagerTest, GetSyncState, TestSize.Level1)
155 {
156     GTEST_LOG_(INFO) << "GetSyncState Start";
157     SyncStateManager syncStateMgr;
158     auto ret = syncStateMgr.GetSyncState();
159     EXPECT_EQ(ret, SyncState::INIT);
160     GTEST_LOG_(INFO) << "GetSyncState End";
161 }
162 
163 /**
164  * @tc.name: GetForceFlag
165  * @tc.desc: Verify the GetForceFlag function
166  * @tc.type: FUNC
167  * @tc.require: I6JPKG
168  */
169 HWTEST_F(SyncStateManagerTest, GetForceFlag, TestSize.Level1)
170 {
171     GTEST_LOG_(INFO) << "GetForceFlag Start";
172     SyncStateManager syncStateMgr;
173     auto ret = syncStateMgr.GetForceFlag();
174     EXPECT_EQ(ret, false);
175     GTEST_LOG_(INFO) << "GetForceFlag End";
176 }
177 } // namespace OHOS::FileManagement::CloudSync::Test