1 /* 2 * Copyright (c) 2022 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 #define private public 19 #define protected public 20 #include "notification_template.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationTemplateTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() {} TearDownTestCase()30 static void TearDownTestCase() {} SetUp()31 void SetUp() {} TearDown()32 void TearDown() {} 33 }; 34 35 /** 36 * @tc.name: SetTemplateName_00001 37 * @tc.desc: Test SetTemplateName parameters. 38 * @tc.type: FUNC 39 * @tc.require: issueI5WBBH 40 */ 41 HWTEST_F(NotificationTemplateTest, SetTemplateName_00001, Function | SmallTest | Level1) 42 { 43 std::string name = "Name"; 44 auto rrc = std::make_shared<NotificationTemplate>(); 45 rrc->SetTemplateName(name); 46 EXPECT_EQ(rrc->GetTemplateName(), name); 47 } 48 49 /** 50 * @tc.name: SetTemplateData_00001 51 * @tc.desc: Test SetTemplateData parameters. 52 * @tc.type: FUNC 53 * @tc.require: issueI5WBBH 54 */ 55 HWTEST_F(NotificationTemplateTest, SetTemplateData_00001, Function | SmallTest | Level1) 56 { 57 std::shared_ptr<AAFwk::WantParams> data = std::make_shared<AAFwk::WantParams>(); 58 auto rrc = std::make_shared<NotificationTemplate>(); 59 rrc->SetTemplateData(data); 60 EXPECT_EQ(rrc->GetTemplateData(), data); 61 } 62 63 /** 64 * @tc.name: Dump_00001 65 * @tc.desc: Test Dump parameters. 66 * @tc.type: FUNC 67 * @tc.require: issueI5WBBH 68 */ 69 HWTEST_F(NotificationTemplateTest, Dump_00001, Function | SmallTest | Level1) 70 { 71 auto rrc = std::make_shared<NotificationTemplate>(); 72 std::string ret = "templateName = , templateData = null"; 73 EXPECT_EQ(rrc->Dump(), ret); 74 } 75 76 /** 77 * @tc.name: Marshalling_00001 78 * @tc.desc: Test Marshalling parameters. 79 * @tc.type: FUNC 80 * @tc.require: issueI5WBBHI 81 */ 82 HWTEST_F(NotificationTemplateTest, Marshalling_00001, Function | SmallTest | Level1) 83 { 84 Parcel parcel; 85 auto rrc = std::make_shared<NotificationTemplate>(); 86 EXPECT_EQ(rrc->Marshalling(parcel), true); 87 } 88 89 /** 90 * @tc.name: Unmarshalling_00001 91 * @tc.desc: Test Unmarshalling parameters. 92 * @tc.type: FUNC 93 * @tc.require: issueI5WBBH 94 */ 95 HWTEST_F(NotificationTemplateTest, Unmarshalling_001, Function | SmallTest | Level1) 96 { 97 bool unmarshalling = true; 98 Parcel parcel; 99 std::shared_ptr<NotificationTemplate> result = 100 std::make_shared<NotificationTemplate>(); 101 102 if (nullptr != result) { 103 if (nullptr == result->Unmarshalling(parcel)) { 104 unmarshalling = false; 105 } 106 } 107 EXPECT_EQ(unmarshalling, false); 108 } 109 110 /** 111 * @tc.name: ReadFromParcel_00001 112 * @tc.desc: Test ReadFromParcel parameters. 113 * @tc.type: FUNC 114 * @tc.require: issueI5WBBH 115 */ 116 HWTEST_F(NotificationTemplateTest, ReadFromParcel_00001, Function | SmallTest | Level1) 117 { 118 Parcel parcel; 119 auto rrc = std::make_shared<NotificationTemplate>(); 120 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 121 } 122 123 /** 124 * @tc.name: Marshalling_00002 125 * @tc.desc: Test Marshalling parameters. 126 * @tc.type: FUNC 127 * @tc.require: issueI5WBBHI 128 */ 129 HWTEST_F(NotificationTemplateTest, Marshalling_00002, Function | SmallTest | Level1) 130 { 131 Parcel parcel; 132 auto rrc = std::make_shared<NotificationTemplate>(); 133 auto data = std::make_shared<AAFwk::WantParams>(); 134 rrc->SetTemplateData(data); 135 rrc->SetTemplateName("test"); 136 EXPECT_EQ(rrc->Marshalling(parcel), true); 137 138 EXPECT_EQ(rrc->ReadFromParcel(parcel), true); 139 } 140 } 141 }