• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "ohos/aafwk/base/string_wrapper.h"
19 #include "ohos/aafwk/base/bool_wrapper.h"
20 #include "ohos/aafwk/base/int_wrapper.h"
21 #include "ohos/aafwk/base/long_wrapper.h"
22 
23 #include "ohos/aafwk/content/want_params.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::AAFwk;
27 using OHOS::Parcel;
28 
29 namespace OHOS {
30 namespace AAFwk {
31 class WantParamsBaseTest : public testing::Test {
32 public:
WantParamsBaseTest()33     WantParamsBaseTest()
34     {}
~WantParamsBaseTest()35     ~WantParamsBaseTest()
36     {
37     }
38     static void SetUpTestCase(void);
39     static void TearDownTestCase(void);
40     void SetUp();
41     void TearDown();
42 
43     std::shared_ptr<WantParams> wantParamsIn_ = nullptr;
44     std::shared_ptr<WantParams> wantParamsOut_ = nullptr;
45 };
46 
SetUpTestCase(void)47 void WantParamsBaseTest::SetUpTestCase(void)
48 {}
49 
TearDownTestCase(void)50 void WantParamsBaseTest::TearDownTestCase(void)
51 {}
52 
SetUp(void)53 void WantParamsBaseTest::SetUp(void)
54 {
55     wantParamsIn_ = std::make_shared<WantParams>();
56     wantParamsOut_ = std::make_shared<WantParams>();
57 }
58 
TearDown(void)59 void WantParamsBaseTest::TearDown(void)
60 {
61 }
62 
63 /**
64  * @tc.number: AaFwk_WantParams_Parcelable_0100
65  * @tc.name: Marshalling/Unmarshalling
66  * @tc.desc: marshalling WantParams, and then check result.
67  */
68 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0100, Function | MediumTest | Level1)
69 {
70     std::string keyStr = "12345667";
71     std::string valueStr = "sdasdfdsffdgfdg";
72     wantParamsIn_->SetParam(keyStr, String::Box(valueStr));
73 
74     Parcel in;
75     if (wantParamsOut_ != nullptr) {
76         wantParamsIn_->Marshalling(in);
77         std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
78         EXPECT_EQ(valueStr, String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
79     }
80 }
81 
82 /**
83  * @tc.number: AaFwk_WantParams_Parcelable_0200
84  * @tc.name: Marshalling/Unmarshalling
85  * @tc.desc: marshalling WantParams, and then check result.
86  */
87 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0200, Function | MediumTest | Level1)
88 {
89     std::string keyStr = "12345667";
90     bool valueBool = true;
91     wantParamsIn_->SetParam(keyStr, Boolean::Box(valueBool));
92 
93     Parcel in;
94     if (wantParamsOut_ != nullptr) {
95         wantParamsIn_->Marshalling(in);
96         std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
97         EXPECT_EQ(valueBool, Boolean::Unbox(IBoolean::Query(wantParamsOut_->GetParam(keyStr))));
98     }
99 }
100 
101 /**
102  * @tc.number: AaFwk_WantParams_Parcelable_0300
103  * @tc.name: Marshalling/Unmarshalling
104  * @tc.desc: marshalling WantParams, and then check result.
105  */
106 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0300, Function | MediumTest | Level1)
107 {
108     std::string keyStr = "12345667";
109     int valueInteger = 12345;
110     wantParamsIn_->SetParam(keyStr, Integer::Box(valueInteger));
111     int right = Integer::Unbox(IInteger::Query(wantParamsIn_->GetParam(keyStr)));
112 
113     Parcel in;
114     wantParamsIn_->Marshalling(in);
115     std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
116     if (wantParamsOut_ != nullptr) {
117         right = Integer::Unbox(IInteger::Query(wantParamsOut_->GetParam(keyStr)));
118         EXPECT_EQ(valueInteger, right);
119 
120         wantParamsOut_ = nullptr;
121     }
122 }
123 
124 /**
125  * @tc.number: AaFwk_WantParams_Parcelable_0400
126  * @tc.name: Marshalling/Unmarshalling
127  * @tc.desc: marshalling WantParams, and then check result.
128  */
129 HWTEST_F(WantParamsBaseTest, AaFwk_WantParams_Parcelable_0400, Function | MediumTest | Level1)
130 {
131     std::string keyStr = "12345667";
132     long valueLong = 1234567;
133     wantParamsIn_->SetParam(keyStr, Long::Box(valueLong));
134 
135     Parcel in;
136     wantParamsIn_->Marshalling(in);
137     std::shared_ptr<WantParams> wantParamsOut_(WantParams::Unmarshalling(in));
138     std::string outString(String::Unbox(IString::Query(wantParamsOut_->GetParam(keyStr))));
139     EXPECT_STREQ(std::to_string(valueLong).c_str(), outString.c_str());
140 }
141 }
142 }
143