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 18 #include "notification_check_info.h" 19 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace Notification { 23 class NotificationCheckInfoTest : public testing::Test { 24 public: SetUpTestCase()25 static void SetUpTestCase() {} TearDownTestCase()26 static void TearDownTestCase() {} SetUp()27 void SetUp() {} TearDown()28 void TearDown() {} 29 }; 30 31 /** 32 * @tc.name: SetPkgName_00001 33 * @tc.desc: Test SetPkgName. 34 * @tc.type: FUNC 35 * @tc.require: issue 36 */ 37 HWTEST_F(NotificationCheckInfoTest, SetPkgName_00001, Function | SmallTest | Level1) 38 { 39 NotificationCheckInfo checkInfo; 40 checkInfo.SetPkgName("test"); 41 EXPECT_EQ("test", checkInfo.GetPkgName()); 42 } 43 44 /** 45 * @tc.name: SetNotifyId_00001 46 * @tc.desc: Test GetNotifyId. 47 * @tc.type: FUNC 48 * @tc.require: issue 49 */ 50 HWTEST_F(NotificationCheckInfoTest, GetNotifyId_00001, Function | SmallTest | Level1) 51 { 52 NotificationCheckInfo checkInfo; 53 checkInfo.SetNotifyId(1); 54 EXPECT_EQ(1, checkInfo.GetNotifyId()); 55 } 56 57 /** 58 * @tc.name: SetContentType_00001 59 * @tc.desc: Test SetContentType. 60 * @tc.type: FUNC 61 * @tc.require: issue 62 */ 63 HWTEST_F(NotificationCheckInfoTest, SetContentType_00001, Function | SmallTest | Level1) 64 { 65 NotificationCheckInfo checkInfo; 66 checkInfo.SetContentType(1); 67 EXPECT_EQ(1, checkInfo.GetContentType()); 68 } 69 70 /** 71 * @tc.name: SetCreatorUserId_00001 72 * @tc.desc: Test SetCreatorUserId. 73 * @tc.type: FUNC 74 * @tc.require: issue 75 */ 76 HWTEST_F(NotificationCheckInfoTest, SetCreatorUserId_00001, Function | SmallTest | Level1) 77 { 78 NotificationCheckInfo checkInfo; 79 checkInfo.SetCreatorUserId(1); 80 EXPECT_EQ(1, checkInfo.GetCreatorUserId()); 81 } 82 83 /** 84 * @tc.name: SetSlotType_00001 85 * @tc.desc: Test SetSlotType. 86 * @tc.type: FUNC 87 * @tc.require: issue 88 */ 89 HWTEST_F(NotificationCheckInfoTest, SetSlotType_00001, Function | SmallTest | Level1) 90 { 91 NotificationCheckInfo checkInfo; 92 checkInfo.SetSlotType(1); 93 EXPECT_EQ(1, checkInfo.GetSlotType()); 94 } 95 96 /** 97 * @tc.name: SetLabel_00001 98 * @tc.desc: Test SetLabel. 99 * @tc.type: FUNC 100 * @tc.require: issue 101 */ 102 HWTEST_F(NotificationCheckInfoTest, SetLabel_00001, Function | SmallTest | Level1) 103 { 104 NotificationCheckInfo checkInfo; 105 checkInfo.SetLabel("testTag"); 106 EXPECT_EQ("testTag", checkInfo.GetLabel()); 107 } 108 109 /** 110 * @tc.name: SetExtraInfo_00001 111 * @tc.desc: Test SetExtraInfo. 112 * @tc.type: FUNC 113 * @tc.require: issue 114 */ 115 HWTEST_F(NotificationCheckInfoTest, SetExtraInfo_00001, Function | SmallTest | Level1) 116 { 117 NotificationCheckInfo checkInfo; 118 std::shared_ptr<AAFwk::WantParams> wantParams = std::make_shared<AAFwk::WantParams>(); 119 checkInfo.SetExtraInfo(wantParams); 120 EXPECT_NE(nullptr, checkInfo.GetExtraInfo()); 121 } 122 123 /** 124 * @tc.name: ConvertJsonStringToValue_00001 125 * @tc.desc: Test ConvertJsonStringToValue. 126 * @tc.type: FUNC 127 * @tc.require: issue 128 */ 129 HWTEST_F(NotificationCheckInfoTest, ConvertJsonStringToValue_00001, Function | SmallTest | Level1) 130 { 131 NotificationCheckInfo checkInfo; 132 std::string obj = "{\"pkgName\":\"test\", \"notifyId\":1, \"contentType\":1," 133 "\"creatorUserId\":1, \"slotType\":1, \"label\":\"testTag\", \"extraInfo\":\"{}\"}"; 134 checkInfo.ConvertJsonStringToValue(obj); 135 136 EXPECT_EQ("testTag", checkInfo.GetLabel()); 137 } 138 139 /** 140 * @tc.name: ConvertJsonStringToValue_00002 141 * @tc.desc: Test ConvertJsonStringToValue and json is null. 142 * @tc.type: FUNC 143 * @tc.require: issue 144 */ 145 HWTEST_F(NotificationCheckInfoTest, ConvertJsonStringToValue_00002, Function | SmallTest | Level1) 146 { 147 NotificationCheckInfo checkInfo; 148 std::string obj = "{}"; 149 checkInfo.ConvertJsonStringToValue(obj); 150 151 EXPECT_EQ("", checkInfo.GetLabel()); 152 } 153 } 154 } 155