1 /*
2 * Copyright (c) 2021 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 #define private public
17 #include "want_sender_proxy.h"
18 #undef private
19
20 #include <gtest/gtest.h>
21 #include "want_sender_stub_mock.h"
22
23 using namespace testing::ext;
24 using namespace testing;
25 using namespace OHOS::AppExecFwk;
26
27 namespace OHOS {
28 namespace AAFwk {
29 class WantSenderProxyTest : public testing::Test {
30 public:
31 static void SetUpTestCase(void);
32 static void TearDownTestCase(void);
33 void SetUp();
34 void TearDown();
35
36 std::shared_ptr<WantSenderProxy> proxy_{ nullptr };
37 sptr<WantSenderStubMock> mock_{ nullptr };
38 };
39
SetUpTestCase(void)40 void WantSenderProxyTest::SetUpTestCase(void)
41 {}
TearDownTestCase(void)42 void WantSenderProxyTest::TearDownTestCase(void)
43 {}
TearDown()44 void WantSenderProxyTest::TearDown()
45 {}
SetUp()46 void WantSenderProxyTest::SetUp()
47 {
48 mock_ = new WantSenderStubMock();
49 proxy_ = std::make_shared<WantSenderProxy>(mock_);
50 }
51
52 /*
53 * Feature: WantSendProxy
54 * Function: Send
55 * SubFunction: NA
56 * FunctionPoints: WantSendProxy Send
57 * EnvConditions: NA
58 * CaseDescription: Verify that the return value of Send is normal
59 */
60 HWTEST_F(WantSenderProxyTest, WantSenderProxyTest_001, TestSize.Level1)
61 {
62 EXPECT_CALL(*mock_, SendRequest(_, _, _, _))
63 .Times(1)
64 .WillOnce(Invoke(mock_.GetRefPtr(), &WantSenderStubMock::InvokeSendRequest));
65 SenderInfo senderInfo;
66 proxy_->Send(senderInfo);
67
68 EXPECT_EQ(IWantSender::WANT_SENDER_SEND, mock_->code_);
69 }
70 } // namespace AAFwk
71 } // namespace OHOS
72