• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "pasteboard_client_mock_test.h"
17 
18 #include "pasteboard_client.h"
19 #include "pasteboard_error.h"
20 #include "pasteboard_service_loader.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace MiscServices {
27 
SetUpTestCase(void)28 void PasteboardClientMockTest::SetUpTestCase(void)
29 {
30     PasteSystemAbilityManagerClient::pasteSystemAbilityManagerClient = systemAbilityManagerClientMock_;
31 }
32 
TearDownTestCase(void)33 void PasteboardClientMockTest::TearDownTestCase(void)
34 {
35     PasteSystemAbilityManagerClient::pasteSystemAbilityManagerClient = nullptr;
36     systemAbilityManagerClientMock_ = nullptr;
37 }
38 
SetUp(void)39 void PasteboardClientMockTest::SetUp(void) { }
40 
TearDown(void)41 void PasteboardClientMockTest::TearDown(void)
42 {
43     testing::Mock::VerifyAndClear(systemAbilityManagerClientMock_.get());
44 }
45 
46 /**
47  * @tc.name: GetChangeCount001
48  * @tc.desc: GetChangeCount.
49  * @tc.type: FUNC
50  * @tc.require:
51  * @tc.author:
52  */
53 HWTEST_F(PasteboardClientMockTest, GetChangeCount001, TestSize.Level0)
54 {
55     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
56     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
57     PasteboardServiceLoader::GetInstance().constructing_ = false;
58     uint32_t changeCount = 0;
59     int32_t ret = PasteboardClient::GetInstance()->GetChangeCount(changeCount);
60     ASSERT_EQ(ret, static_cast<int32_t>(PasteboardError::OBTAIN_SERVER_SA_ERROR));
61 }
62 
63 /**
64  * @tc.name: GetPasteData001
65  * @tc.desc: GetPasteData.
66  * @tc.type: FUNC
67  * @tc.require:
68  * @tc.author:
69  */
70 HWTEST_F(PasteboardClientMockTest, GetPasteData001, TestSize.Level0)
71 {
72     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
73     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
74     PasteboardServiceLoader::GetInstance().constructing_ = false;
75     PasteData pasteData;
76     int32_t status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
77     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::OBTAIN_SERVER_SA_ERROR));
78 }
79 
80 /**
81  * @tc.name: GetPasteDataFromService001
82  * @tc.desc: GetPasteDataFromService.
83  * @tc.type: FUNC
84  * @tc.require:
85  * @tc.author:
86  */
87 HWTEST_F(PasteboardClientMockTest, GetPasteDataFromService001, TestSize.Level0)
88 {
89     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
90     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
91     PasteboardServiceLoader::GetInstance().constructing_ = false;
92     PasteData pasteData;
93     PasteDataFromServiceInfo pasteDataFromServiceInfo;
94     std::string progressKey = "";
95     std::shared_ptr<GetDataParams> params = nullptr;
96     int32_t status = PasteboardClient::GetInstance()->GetPasteDataFromService(
97         pasteData, pasteDataFromServiceInfo, progressKey, params);
98     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::OBTAIN_SERVER_SA_ERROR));
99 }
100 
101 /**
102  * @tc.name: SetPasteData001
103  * @tc.desc: SetPasteData.
104  * @tc.type: FUNC
105  * @tc.require:
106  * @tc.author:
107  */
108 HWTEST_F(PasteboardClientMockTest, SetPasteData001, TestSize.Level0)
109 {
110     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
111     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
112     PasteboardServiceLoader::GetInstance().constructing_ = false;
113     PasteData pasteData;
114     int32_t status = PasteboardClient::GetInstance()->SetPasteData(pasteData);
115     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::OBTAIN_SERVER_SA_ERROR));
116 }
117 
118 /**
119  * @tc.name: SubscribeTest001
120  * @tc.desc: SubscribeTest.
121  * @tc.type: FUNC
122  * @tc.require:
123  * @tc.author:
124  */
125 HWTEST_F(PasteboardClientMockTest, SubscribeTest001, TestSize.Level0)
126 {
127     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
128     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
129     PasteboardServiceLoader::GetInstance().constructing_ = false;
130     sptr<PasteboardObserver> callback = nullptr;
131     auto ret = PasteboardClient::GetInstance()->Subscribe(PasteboardObserverType::OBSERVER_LOCAL, callback);
132     ASSERT_EQ(ret, false);
133 }
134 
135 /**
136  * @tc.name: SubscribeTest002
137  * @tc.desc: SubscribeTest.
138  * @tc.type: FUNC
139  * @tc.require:
140  * @tc.author:
141  */
142 HWTEST_F(PasteboardClientMockTest, SubscribeTest002, TestSize.Level0)
143 {
144     EXPECT_CALL(*systemAbilityManagerClientMock_, GetSystemAbilityManager()).WillRepeatedly(testing::Return(nullptr));
145     PasteboardServiceLoader::GetInstance().pasteboardServiceProxy_ = nullptr;
146     PasteboardServiceLoader::GetInstance().constructing_ = false;
147     sptr<PasteboardObserver> callback = sptr<PasteboardObserver>::MakeSptr();
148     auto ret = PasteboardClient::GetInstance()->Subscribe(PasteboardObserverType::OBSERVER_LOCAL, callback);
149     ASSERT_EQ(ret, false);
150 }
151 
152 } // namespace MiscServices
153 } // namespace OHOS