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_user_input.h" 21 #undef private 22 #undef protected 23 24 using namespace testing::ext; 25 namespace OHOS { 26 namespace Notification { 27 class NotificationUserInputTest : 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: NotificationUserInput_00001 37 * @tc.desc: Test NotificationUserInput parameters. 38 * @tc.type: FUNC 39 * @tc.require: issue 40 */ 41 HWTEST_F(NotificationUserInputTest, Dump_00001, Function | SmallTest | Level1) 42 { 43 std::string inputKey = "InputKey"; 44 std::string tag = "Tag"; 45 std::vector<std::string> options; 46 bool permitFreeFormInput = true; 47 std::set<std::string> permitMimeTypes; 48 std::shared_ptr<AAFwk::WantParams> additional = nullptr; 49 Notification::NotificationConstant::InputEditType editType = 50 Notification::NotificationConstant::InputEditType(1); 51 auto rrc = std::make_shared<NotificationUserInput>(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, 52 additional, editType); 53 std::string ret = rrc->GetInputKey(); 54 EXPECT_EQ(ret, inputKey); 55 } 56 57 /** 58 * @tc.name: ToJson_00001 59 * @tc.desc: Test ToJson parameters. 60 * @tc.type: FUNC 61 * @tc.require: issue 62 */ 63 HWTEST_F(NotificationUserInputTest, ToJson_00001, Function | SmallTest | Level1) 64 { 65 nlohmann::json jsonObject; 66 auto rrc = std::make_shared<NotificationUserInput>(); 67 rrc->FromJson(jsonObject); 68 EXPECT_EQ(rrc->ToJson(jsonObject), true); 69 } 70 71 /** 72 * @tc.name: FromJson_00001 73 * @tc.desc: Test FromJson parameters. 74 * @tc.type: FUNC 75 * @tc.require: issue 76 */ 77 HWTEST_F(NotificationUserInputTest, FromJson_00001, Function | SmallTest | Level1) 78 { 79 nlohmann::json jsonObject; 80 auto rrc = std::make_shared<NotificationUserInput>(); 81 std::shared_ptr<NotificationUserInput> userInput = nullptr; 82 rrc->FromJson(jsonObject); 83 EXPECT_EQ(rrc->FromJson(jsonObject), nullptr); 84 } 85 86 /** 87 * @tc.name: Marshalling_00001 88 * @tc.desc: Test Marshalling parameters. 89 * @tc.type: FUNC 90 * @tc.require: issue 91 */ 92 HWTEST_F(NotificationUserInputTest, Marshalling_00001, Function | SmallTest | Level1) 93 { 94 Parcel parcel; 95 auto rrc = std::make_shared<NotificationUserInput>(); 96 EXPECT_EQ(rrc->Marshalling(parcel), true); 97 } 98 99 /** 100 * @tc.name: Unmarshalling_00001 101 * @tc.desc: Test Unmarshalling parameters. 102 * @tc.type: FUNC 103 * @tc.require: issue 104 */ 105 HWTEST_F(NotificationUserInputTest, Unmarshalling_001, Function | SmallTest | Level1) 106 { 107 bool unmarshalling = true; 108 Parcel parcel; 109 std::shared_ptr<NotificationUserInput> result = 110 std::make_shared<NotificationUserInput>(); 111 112 if (nullptr != result) { 113 if (nullptr == result->Unmarshalling(parcel)) { 114 unmarshalling = false; 115 } 116 } 117 EXPECT_EQ(unmarshalling, false); 118 } 119 120 /** 121 * @tc.name: ReadFromParcel_00001 122 * @tc.desc: Test ReadFromParcel parameters. 123 * @tc.type: FUNC 124 * @tc.require: issue 125 */ 126 HWTEST_F(NotificationUserInputTest, ReadFromParcel_00001, Function | SmallTest | Level1) 127 { 128 Parcel parcel; 129 auto rrc = std::make_shared<NotificationUserInput>(); 130 EXPECT_EQ(rrc->ReadFromParcel(parcel), false); 131 } 132 } 133 }