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_conversational_message.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationConversationalMessageTest : 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: GetText_00001 37 * @tc.desc: Test GetText parameters. 38 * @tc.type: FUNC 39 * @tc.require: issueI5W15B 40 */ 41 HWTEST_F(NotificationConversationalMessageTest, GetText_00001, Function | SmallTest | Level1) 42 { 43 std::string text = "Text"; 44 int64_t timestamp = 10; 45 MessageUser sender; 46 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 47 rrc->GetSender(); 48 EXPECT_EQ(rrc->GetText(), text); 49 EXPECT_EQ(rrc->GetArrivedTime(), timestamp); 50 } 51 52 /** 53 * @tc.name: SetData_00001 54 * @tc.desc: Test SetData parameters. 55 * @tc.type: FUNC 56 * @tc.require: issueI5W15B 57 */ 58 HWTEST_F(NotificationConversationalMessageTest, SetData_00001, Function | SmallTest | Level1) 59 { 60 std::string text = "Text"; 61 int64_t timestamp = 10; 62 MessageUser sender; 63 std::string mimeType = "MimeType"; 64 std::string uri; 65 std::shared_ptr<Uri> uriPtr = std::make_shared<Uri>(uri); 66 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 67 rrc->SetData(mimeType, uriPtr); 68 EXPECT_EQ(rrc->GetMimeType(), mimeType); 69 EXPECT_EQ(rrc->GetUri(), uriPtr); 70 } 71 72 /** 73 * @tc.name: Dump_00001 74 * @tc.desc: Test Dump parameters. 75 * @tc.type: FUNC 76 * @tc.require: issueI5W15B 77 */ 78 HWTEST_F(NotificationConversationalMessageTest, Dump_00001, Function | SmallTest | Level1) 79 { 80 std::string text = "Text"; 81 int64_t timestamp = 10; 82 MessageUser sender; 83 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 84 std::string ret = 85 "NotificationConversationalMessage{ text = Text, arrivedTime = 10, mimeType = , uri = null, " 86 "sender = MessageUser{ key = , name = , pixelMap = null, uri = , isMachine = false, isUserImportant = false } }"; 87 88 EXPECT_EQ(rrc->Dump(), ret); 89 } 90 91 /** 92 * @tc.name: ToJson_00001 93 * @tc.desc: Test ToJson parameters. 94 * @tc.type: FUNC 95 * @tc.require: issueI5W15B 96 */ 97 HWTEST_F(NotificationConversationalMessageTest, ToJson_00001, Function | SmallTest | Level1) 98 { 99 std::string text = "Text"; 100 int64_t timestamp = 10; 101 MessageUser sender; 102 nlohmann::json jsonObject; 103 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 104 rrc->FromJson(jsonObject); 105 EXPECT_EQ(rrc->ToJson(jsonObject), true); 106 } 107 108 /** 109 * @tc.name: Marshalling_00001 110 * @tc.desc: Test Marshalling parameters. 111 * @tc.type: FUNC 112 * @tc.require: issueI5W15B 113 */ 114 HWTEST_F(NotificationConversationalMessageTest, Marshalling_00001, Function | SmallTest | Level1) 115 { 116 std::string text = "Text"; 117 int64_t timestamp = 10; 118 MessageUser sender; 119 Parcel parcel; 120 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 121 EXPECT_EQ(rrc->Marshalling(parcel), true); 122 } 123 124 /** 125 * @tc.name: Unmarshalling_00001 126 * @tc.desc: Test Unmarshalling parameters. 127 * @tc.type: FUNC 128 * @tc.require: issueI5W15B 129 */ 130 HWTEST_F(NotificationConversationalMessageTest, Unmarshalling_001, Function | SmallTest | Level1) 131 { 132 std::string text = "Text"; 133 int64_t timestamp = 10; 134 MessageUser sender; 135 bool unmarshalling = true; 136 Parcel parcel; 137 std::shared_ptr<NotificationConversationalMessage> result = 138 std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 139 140 if (nullptr != result) { 141 if (nullptr == result->Unmarshalling(parcel)) { 142 unmarshalling = false; 143 } 144 } 145 EXPECT_EQ(unmarshalling, false); 146 } 147 148 /** 149 * @tc.name: ReadFromParcel_00001 150 * @tc.desc: Test ReadFromParcel parameters. 151 * @tc.type: FUNC 152 * @tc.require: issueI5W15B 153 */ 154 HWTEST_F(NotificationConversationalMessageTest, ReadFromParcel_00001, Function | SmallTest | Level1) 155 { 156 std::string text = "Text"; 157 int64_t timestamp = 10; 158 MessageUser sender; 159 Parcel parcel; 160 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 161 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 162 } 163 164 /** 165 * @tc.name: FromJson_00001 166 * @tc.desc: Test FromJson parameters. 167 * @tc.type: FUNC 168 * @tc.require: issueI5W15B 169 */ 170 HWTEST_F(NotificationConversationalMessageTest, FromJson_00001, Function | SmallTest | Level1) 171 { 172 std::string text = "Text"; 173 int64_t timestamp = 10; 174 MessageUser sender; 175 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 176 177 nlohmann::json jsonObject = nlohmann::json{"processName", "process6", "arrivedTime", "arrivedTime1"}; 178 rrc->FromJson(jsonObject); 179 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 180 EXPECT_EQ(jsonObject.is_object(), false); 181 } 182 183 /** 184 * @tc.name: FromJson_00002 185 * @tc.desc: Test FromJson parameters. 186 * @tc.type: FUNC 187 * @tc.require: issueI5W15B 188 */ 189 HWTEST_F(NotificationConversationalMessageTest, FromJson_00002, Function | SmallTest | Level1) 190 { 191 std::string text = "Text"; 192 int64_t timestamp = 10; 193 MessageUser sender; 194 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 195 196 nlohmann::json jsonObject = nlohmann::json{ 197 {"processName", "process6"}, {"APL", 1}, 198 {"version", 2}, {"tokenId", 685266937}, 199 {"tokenAttr", 0}, 200 {"dcaps", {"AT_CAP", "ST_CAP"}}}; 201 rrc->FromJson(jsonObject); 202 EXPECT_EQ(jsonObject.is_object(), true); 203 } 204 205 /** 206 * @tc.name: ToJson_00002 207 * @tc.desc: Test ToJson parameters. 208 * @tc.type: FUNC 209 * @tc.require: issueI5W15B 210 */ 211 HWTEST_F(NotificationConversationalMessageTest, ToJson_00002, Function | SmallTest | Level1) 212 { 213 std::string text = "Text"; 214 int64_t timestamp = 10; 215 MessageUser sender; 216 nlohmann::json jsonObject; 217 auto rrc = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender); 218 rrc->FromJson(jsonObject); 219 EXPECT_EQ(rrc->ToJson(jsonObject), true); 220 } 221 222 /** 223 * @tc.name: FromJson_00003 224 * @tc.desc: Test FromJson parameters. 225 * @tc.type: FUNC 226 * @tc.require: issueI5WBBHI 227 */ 228 HWTEST_F(NotificationConversationalMessageTest, FromJson_00003, Function | SmallTest | Level1) 229 { 230 nlohmann::json jsonObject = nlohmann::json{ 231 {"arrivedTime", 1}, 232 {"text", "test"}, 233 {"uri", "/data/log"}, 234 {"mimeType", "test"}}; 235 auto rrc = std::make_shared<NotificationConversationalMessage>(); 236 auto res = rrc->FromJson(jsonObject); 237 EXPECT_NE(res, nullptr); 238 } 239 240 /** 241 * @tc.name: FromJson_00004 242 * @tc.desc: Test FromJson parameters. 243 * @tc.type: FUNC 244 * @tc.require: issueI5WBBHI 245 */ 246 HWTEST_F(NotificationConversationalMessageTest, FromJson_00004, Function | SmallTest | Level1) 247 { 248 nlohmann::json jsonObject = nlohmann::json{ 249 {"arrivedTime", 1}, 250 {"text", "test"}, 251 {"uri", ""}}; 252 auto rrc = std::make_shared<NotificationConversationalMessage>(); 253 auto res = rrc->FromJson(jsonObject); 254 EXPECT_NE(res, nullptr); 255 } 256 } 257 }