• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 }