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 #include <gtest/gtest.h>
17 #include "parcel.h"
18 #include "sender_info.h"
19 #define private public
20 #define protected public
21 #include "wants_info.h"
22 #undef private
23 #undef protected
24 #include "want_receiver_stub.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::AppExecFwk;
29 using OHOS::AppExecFwk::ElementName;
30 
31 namespace OHOS {
32 namespace AAFwk {
33 #define SLEEP(milli) std::this_thread::sleep_for(std::chrono::seconds(milli))
34 namespace {}  // namespace
35 class WantsInfoTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41     static constexpr int TEST_WAIT_TIME = 100000;
42     class CancelReceiver : public AAFwk::WantReceiverStub {
43     public:
44         int performReceiveCount = 0;
45         void Send(const int32_t resultCode) override;
46         void PerformReceive(const AAFwk::Want& want, int resultCode, const std::string& data,
47             const AAFwk::WantParams& extras, bool serialized, bool sticky, int sendingUser) override;
48     };
49 
50 public:
51 };
52 
Send(const int32_t resultCode)53 void WantsInfoTest::CancelReceiver::Send(const int32_t resultCode)
54 {}
PerformReceive(const AAFwk::Want & want,int resultCode,const std::string & data,const AAFwk::WantParams & extras,bool serialized,bool sticky,int sendingUser)55 void WantsInfoTest::CancelReceiver::PerformReceive(const AAFwk::Want& want, int resultCode, const std::string& data,
56     const AAFwk::WantParams& extras, bool serialized, bool sticky, int sendingUser)
57 {}
58 
SetUpTestCase()59 void WantsInfoTest::SetUpTestCase()
60 {}
61 
TearDownTestCase()62 void WantsInfoTest::TearDownTestCase()
63 {}
64 
SetUp()65 void WantsInfoTest::SetUp()
66 {}
67 
TearDown()68 void WantsInfoTest::TearDown()
69 {}
70 
71 /*
72  * @tc.number    : WantsInfoTest_0100
73  * @tc.name      : Marshalling/UnMarshalling
74  * @tc.desc      : 1.Marshalling/UnMarshalling
75  */
76 HWTEST_F(WantsInfoTest, WantsInfoTest_0100, TestSize.Level1)
77 {
78     WantsInfo info;
79     Want want;
80     ElementName element("device", "com.ix.hiMusic", "MusicSAbility");
81     want.SetElement(element);
82     info.want = want;
83     info.resolvedTypes = "nihao";
84     Parcel parcel;
85     info.Marshalling(parcel);
86     auto unInfo = WantsInfo::Unmarshalling(parcel);
87     EXPECT_EQ(unInfo->want.GetElement().GetBundleName(), "com.ix.hiMusic");
88     EXPECT_EQ(unInfo->want.GetElement().GetAbilityName(), "MusicSAbility");
89     EXPECT_EQ(unInfo->resolvedTypes, "nihao");
90     delete unInfo;
91 }
92 }  // namespace AAFwk
93 }  // namespace OHOS
94