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 "message_user.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class MessageUserTest : 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: FromJson_00001 37 * @tc.desc: Test FromJson parameters. 38 * @tc.type: FUNC 39 * @tc.require: issue 40 */ 41 HWTEST_F(MessageUserTest, FromJson_00001, Function | SmallTest | Level1) 42 { 43 sptr<MessageUser> messageUser = nullptr; 44 nlohmann::json jsonObject; 45 EXPECT_EQ(messageUser ->FromJson(jsonObject), nullptr); 46 } 47 48 /** 49 * @tc.name: FromJson_00002 50 * @tc.desc: Test FromJson parameters. 51 * @tc.type: FUNC 52 * @tc.require: issue 53 */ 54 HWTEST_F(MessageUserTest, FromJson_00002, Function | SmallTest | Level1) 55 { 56 MessageUser messageUser; 57 nlohmann::json jsonObject = nlohmann::json{"processName", "process6", "name", "arrivedTime1"}; 58 messageUser.FromJson(jsonObject); 59 EXPECT_EQ(jsonObject.is_object(), false); 60 EXPECT_EQ(messageUser.FromJson(jsonObject), nullptr); 61 } 62 63 /** 64 * @tc.name: FromJson_00003 65 * @tc.desc: Test FromJson parameters. 66 * @tc.type: FUNC 67 * @tc.require: issue 68 */ 69 HWTEST_F(MessageUserTest, FromJson_00003, Function | SmallTest | Level1) 70 { 71 MessageUser messageUser; 72 nlohmann::json jsonObject = nlohmann::json{ 73 {"processName", "process6"}, {"APL", 1}, 74 {"version", 2}, {"tokenId", 685266937}, 75 {"tokenAttr", 0}, 76 {"dcaps", {"AT_CAP", "ST_CAP"}}}; 77 messageUser.FromJson(jsonObject); 78 EXPECT_EQ(jsonObject.is_object(), true); 79 } 80 81 /** 82 * @tc.name: Unmarshalling_00001 83 * @tc.desc: Test Unmarshalling parameters. 84 * @tc.type: FUNC 85 * @tc.require: issue 86 */ 87 HWTEST_F(MessageUserTest, Unmarshalling_001, Function | SmallTest | Level1) 88 { 89 bool unmarshalling = true; 90 Parcel parcel; 91 std::shared_ptr<MessageUser> result = std::make_shared<MessageUser>(); 92 93 if (nullptr != result) { 94 if (nullptr == result->Unmarshalling(parcel)) { 95 unmarshalling = false; 96 } 97 } 98 EXPECT_EQ(unmarshalling, false); 99 } 100 101 /** 102 * @tc.name: ReadFromParcel_00001 103 * @tc.desc: Test ReadFromParcel parameters. 104 * @tc.type: FUNC 105 * @tc.require: issue 106 */ 107 HWTEST_F(MessageUserTest, ReadFromParcel_00001, Function | SmallTest | Level1) 108 { 109 MessageUser messageUser; 110 Parcel parcel; 111 112 EXPECT_EQ(messageUser.ReadFromParcel(parcel), false); 113 } 114 115 /** 116 * @tc.name: ReadFromParcel_00002 117 * @tc.desc: Test ReadFromParcel parameters. 118 * @tc.type: FUNC 119 * @tc.require: issue 120 */ 121 HWTEST_F(MessageUserTest, ReadFromParcel_00002, Function | SmallTest | Level1) 122 { 123 MessageUser messageUser; 124 Parcel parcel; 125 int32_t empty = 10; 126 127 parcel.WriteInt32(empty); 128 EXPECT_EQ(messageUser.ReadFromParcel(parcel), false); 129 } 130 131 /** 132 * @tc.name: FromJson_00004 133 * @tc.desc: Test FromJson parameters. 134 * @tc.type: FUNC 135 * @tc.require: issue 136 */ 137 HWTEST_F(MessageUserTest, FromJson_00004, Function | SmallTest | Level1) 138 { 139 MessageUser messageUser; 140 nlohmann::json jsonObject = nlohmann::json{ 141 {"key", "key"}, 142 {"name", "test"}, 143 {"uri", "/data/log/"}, 144 {"isMachine", true}, 145 {"isUserImportant", true}}; 146 auto res = messageUser.FromJson(jsonObject); 147 EXPECT_NE(res, nullptr); 148 } 149 150 /** 151 * @tc.name: Marshalling_00001 152 * @tc.desc: Test Marshalling. 153 * @tc.type: FUNC 154 * @tc.require: issue 155 */ 156 HWTEST_F(MessageUserTest, Marshalling_00001, Function | SmallTest | Level1) 157 { 158 MessageUser messageUser; 159 Parcel parcel; 160 auto res = messageUser.Marshalling(parcel); 161 EXPECT_NE(res, false); 162 } 163 } 164 }