• 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 <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 
19 #include "cloud_sync_constants.h"
20 #include "dfs_error.h"
21 #include "cloud_sync_callback_client.h"
22 #include "service_callback_mock.h"
23 
24 namespace OHOS {
25 namespace FileManagement::CloudSync {
26 namespace Test {
27 using namespace testing::ext;
28 using namespace std;
29 
30 class CloudSyncCallbackTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36     sptr<CloudSyncCallbackClient> callbackClient_;
37     void InitCloudSyncCallback();
38 };
39 
40 class CloudSyncCallbackDerived : public CloudSyncCallback {
41 public:
OnSyncStateChanged(CloudSyncState state,ErrorType error)42     void OnSyncStateChanged(CloudSyncState state, ErrorType error) override
43     {
44         GTEST_LOG_(INFO) << "OnSyncStateChanged SUCCESS";
45     }
46 };
47 
InitCloudSyncCallback(void)48 void CloudSyncCallbackTest::InitCloudSyncCallback(void)
49 {
50     shared_ptr<CloudSyncCallback> callback = make_shared<CloudSyncCallbackDerived>();
51     callbackClient_ = new CloudSyncCallbackClient(callback);
52 }
53 
SetUpTestCase(void)54 void CloudSyncCallbackTest::SetUpTestCase(void)
55 {
56     std::cout << "SetUpTestCase" << std::endl;
57 }
58 
TearDownTestCase(void)59 void CloudSyncCallbackTest::TearDownTestCase(void)
60 {
61     std::cout << "TearDownTestCase" << std::endl;
62 }
63 
SetUp(void)64 void CloudSyncCallbackTest::SetUp(void)
65 {
66     std::cout << "SetUp" << std::endl;
67 }
68 
TearDown(void)69 void CloudSyncCallbackTest::TearDown(void)
70 {
71     std::cout << "TearDown" << std::endl;
72 }
73 
74 /**
75  * @tc.name: OnSyncStateChangedTest
76  * @tc.desc: Verify the OnSyncStateChanged function.
77  * @tc.type: FUNC
78  * @tc.require: I6H5MH
79  */
80 HWTEST_F(CloudSyncCallbackTest, OnSyncStateChangedTest, TestSize.Level1)
81 {
82     GTEST_LOG_(INFO) << "OnSyncStateChanged start";
83     try {
84         InitCloudSyncCallback();
85         callbackClient_->OnSyncStateChanged(CloudSyncState::COMPLETED, ErrorType::NO_ERROR);
86         EXPECT_TRUE(true);
87         callbackClient_->callback_ = nullptr;
88         callbackClient_->OnSyncStateChanged(CloudSyncState::COMPLETED, ErrorType::NO_ERROR);
89         EXPECT_TRUE(true);
90     } catch (...) {
91         EXPECT_TRUE(false);
92         GTEST_LOG_(INFO) << "OnSyncStateChanged FAILED";
93     }
94     GTEST_LOG_(INFO) << "OnSyncStateChanged end";
95 }
96 
97 } // namespace Test
98 } // namespace FileManagement::CloudSync {
99 } // namespace OHOS
100