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 #include <memory> 18 #include <string> 19 #include "int_wrapper.h" 20 #include "notification_unified_group_Info.h" 21 22 using namespace testing::ext; 23 namespace OHOS { 24 namespace Notification { 25 class NotificationUnifiedGroupInfoTest : public testing::Test { 26 public: SetUpTestCase()27 static void SetUpTestCase() {} TearDownTestCase()28 static void TearDownTestCase() {} SetUp()29 void SetUp() {} TearDown()30 void TearDown() {} 31 }; 32 33 /** 34 * @tc.name: SetUnifiedGroupInfo_00001 35 * @tc.desc: Test set all info of UnifiedGroupInfo. 36 * @tc.type: FUNC 37 * @tc.require: issue 38 */ 39 HWTEST_F(NotificationUnifiedGroupInfoTest, SetUnifiedGroupInfo_00001, Function | SmallTest | Level1) 40 { 41 NotificationUnifiedGroupInfo info; 42 info.SetKey("testKey"); 43 EXPECT_EQ(info.GetKey(), "testKey"); 44 45 info.SetTitle("testtitle"); 46 EXPECT_EQ(info.GetTitle(), "testtitle"); 47 48 info.SetContent("content"); 49 EXPECT_EQ(info.GetContent(), "content"); 50 51 info.SetSceneName("test"); 52 EXPECT_EQ(info.GetSceneName(), "test"); 53 54 std::shared_ptr<AAFwk::WantParams> extraInfo = std::make_shared<AAFwk::WantParams>(); 55 info.SetExtraInfo(extraInfo); 56 EXPECT_NE(info.GetExtraInfo(), nullptr); 57 std::string res = "NotificationUnifiedGroupInfo{ key = testKey, title = testtitle, " 58 "content = content, sceneName = test, extraInfo = {} }"; 59 EXPECT_EQ(info.Dump(), res); 60 } 61 62 /** 63 * @tc.name: Marshalling_00001 64 * @tc.desc: Test Marshalling. 65 * @tc.type: FUNC 66 * @tc.require: issue 67 */ 68 HWTEST_F(NotificationUnifiedGroupInfoTest, Marshalling_00001, Function | SmallTest | Level1) 69 { 70 NotificationUnifiedGroupInfo info; 71 info.SetKey("testKey"); 72 info.SetTitle("testtitle"); 73 info.SetContent("content"); 74 info.SetSceneName("test"); 75 76 Parcel parcel; 77 EXPECT_EQ(info.Marshalling(parcel), true); 78 auto ptr = NotificationUnifiedGroupInfo::Unmarshalling(parcel); 79 EXPECT_NE(ptr, nullptr); 80 EXPECT_EQ(ptr->GetTitle(), "testtitle"); 81 } 82 83 /** 84 * @tc.name: Marshalling_00002 85 * @tc.desc: Test Marshalling. 86 * @tc.type: FUNC 87 * @tc.require: issue 88 */ 89 HWTEST_F(NotificationUnifiedGroupInfoTest, Marshalling_00002, Function | SmallTest | Level1) 90 { 91 NotificationUnifiedGroupInfo info; 92 info.SetKey("testKey"); 93 info.SetTitle("testtitle"); 94 info.SetContent("content"); 95 info.SetSceneName("test"); 96 std::shared_ptr<AAFwk::WantParams> extraInfo = std::make_shared<AAFwk::WantParams>(); 97 sptr<AAFwk::IInterface> value = AAFwk::Integer::Box(1); 98 extraInfo->SetParam(string("testId"), value); 99 info.SetExtraInfo(extraInfo); 100 101 Parcel parcel; 102 EXPECT_EQ(info.Marshalling(parcel), true); 103 auto ptr = NotificationUnifiedGroupInfo::Unmarshalling(parcel); 104 EXPECT_NE(ptr, nullptr); 105 EXPECT_EQ(ptr->GetTitle(), "testtitle"); 106 } 107 } 108 } 109