• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #define private public
18 #include "pending_want_common_event.h"
19 #undef private
20 #include "want.h"
21 #include "wants_info.h"
22 #include "hilog_tag_wrapper.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::AppExecFwk;
26 namespace OHOS {
27 namespace AAFwk {
28 class PendingWantCommonEventTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void PendingWantCommonEventTest::SetUpTestCase(void)
37 {}
TearDownTestCase(void)38 void PendingWantCommonEventTest::TearDownTestCase(void)
39 {}
SetUp(void)40 void PendingWantCommonEventTest::SetUp(void)
41 {}
TearDown(void)42 void PendingWantCommonEventTest::TearDown(void)
43 {}
44 class TestWantReceiver : public IWantReceiver {
Send(const int32_t resultCode)45     virtual void Send(const int32_t resultCode) {}
PerformReceive(const Want & want,int resultCode,const std::string & data,const WantParams & extras,bool serialized,bool sticky,int sendingUser)46     virtual void PerformReceive(const Want &want, int resultCode, const std::string &data, const WantParams &extras,
47         bool serialized, bool sticky, int sendingUser) {}
AsObject()48     virtual sptr<IRemoteObject> AsObject()
49     {
50         return nullptr;
51     }
52 };
53 /*
54  * @tc.number: OnReceiveEvent_0100
55  * @tc.name: set type
56  * @tc.desc: Set RequestWant, use GetRequestWant to verify whether the RequestWant  is set successfully
57  */
58 HWTEST_F(PendingWantCommonEventTest, OnReceiveEvent_0100, TestSize.Level1)
59 {
60     TAG_LOGI(AAFwkTag::TEST, "PendingWantCommonEventTest OnReceiveEvent_0100 start");
61     PendingWantCommonEvent PendingWant;
62     EventFwk::CommonEventData data;
63     PendingWant.OnReceiveEvent(data);
64     EXPECT_EQ(PendingWant.finishedReceiver_, nullptr);
65     TAG_LOGI(AAFwkTag::TEST, "PendingWantCommonEventTest OnReceiveEvent_0100 end");
66 }
67 
68 /*
69  * @tc.number: OnReceiveEvent_0200
70  * @tc.name: set type
71  * @tc.desc: Set RequestWant, use GetRequestWant to verify whether the RequestWant  is set successfully
72  */
73 HWTEST_F(PendingWantCommonEventTest, OnReceiveEvent_0200, TestSize.Level1)
74 {
75     TAG_LOGI(AAFwkTag::TEST, "PendingWantCommonEventTest OnReceiveEvent_0200 start");
76     PendingWantCommonEvent PendingWant;
77     EventFwk::CommonEventData data;
78     PendingWant.finishedReceiver_ = new TestWantReceiver();
79     PendingWant.OnReceiveEvent(data);
80     EXPECT_NE(PendingWant.finishedReceiver_, nullptr);
81     TAG_LOGI(AAFwkTag::TEST, "PendingWantCommonEventTest OnReceiveEvent_0200 end");
82 }
83 }  // namespace AAFwk
84 }  // namespace OHOS
85