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_progress.h" 19 20 using namespace testing::ext; 21 namespace OHOS { 22 namespace Notification { 23 class NotificationProgressTest : 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: SetMaxValue_00001 33 * @tc.desc: Test SetMaxValue. 34 * @tc.type: FUNC 35 * @tc.require: issue 36 */ 37 HWTEST_F(NotificationProgressTest, SetMaxValue_00001, Function | SmallTest | Level1) 38 { 39 NotificationProgress notificationProgress; 40 notificationProgress.SetMaxValue(0xffffffff); 41 EXPECT_EQ(0xffffffff, notificationProgress.GetMaxValue()); 42 } 43 44 /** 45 * @tc.name: SetCurrentValue_00001 46 * @tc.desc: Test SetCurrentValue. 47 * @tc.type: FUNC 48 * @tc.require: issue 49 */ 50 HWTEST_F(NotificationProgressTest, SetCurrentValue_00001, Function | SmallTest | Level1) 51 { 52 NotificationProgress notificationProgress; 53 notificationProgress.SetCurrentValue(0xffffffff); 54 EXPECT_EQ(0xffffffff, notificationProgress.GetCurrentValue()); 55 } 56 57 /** 58 * @tc.name: SetIsPercentage_00001 59 * @tc.desc: Test SetIsPercentage. 60 * @tc.type: FUNC 61 * @tc.require: issue 62 */ 63 HWTEST_F(NotificationProgressTest, SetIsPercentage_00001, Function | SmallTest | Level1) 64 { 65 NotificationProgress notificationProgress; 66 notificationProgress.SetIsPercentage(true); 67 EXPECT_EQ(true, notificationProgress.GetIsPercentage()); 68 } 69 70 /** 71 * @tc.name: Dump_00001 72 * @tc.desc: Test Dump. 73 * @tc.type: FUNC 74 * @tc.require: issue 75 */ 76 HWTEST_F(NotificationProgressTest, Dump_00001, Function | SmallTest | Level1) 77 { 78 NotificationProgress notificationProgress; 79 notificationProgress.SetIsPercentage(true); 80 notificationProgress.SetMaxValue(1); 81 notificationProgress.SetCurrentValue(1); 82 std::string dumpStr = "Progress{ maxValue = 1, currentValue = 1, isPercentage = 1 }"; 83 EXPECT_EQ(dumpStr, notificationProgress.Dump()); 84 } 85 86 /** 87 * @tc.name: FromJson_00001 88 * @tc.desc: Test FromJson and json is null. 89 * @tc.type: FUNC 90 * @tc.require: issue 91 */ 92 HWTEST_F(NotificationProgressTest, FromJson_00001, Function | SmallTest | Level1) 93 { 94 nlohmann::json jsonObject = nlohmann::json{}; 95 NotificationProgress notificationProgress; 96 97 EXPECT_EQ(nullptr, notificationProgress.FromJson(jsonObject)); 98 } 99 100 /** 101 * @tc.name: FromJson_00002 102 * @tc.desc: Test FromJson. 103 * @tc.type: FUNC 104 * @tc.require: issue 105 */ 106 HWTEST_F(NotificationProgressTest, FromJson_00002, Function | SmallTest | Level1) 107 { 108 nlohmann::json jsonObject = nlohmann::json{ 109 {"maxValue", 1}, {"currentValue", 1}, 110 {"isPercentage", 1}}; 111 NotificationProgress notificationProgress; 112 NotificationProgress *progress = notificationProgress.FromJson(jsonObject); 113 EXPECT_NE(nullptr, progress); 114 if (progress != nullptr) { 115 delete progress; 116 } 117 } 118 119 /** 120 * @tc.name: Marshalling_00001 121 * @tc.desc: Test Marshalling. 122 * @tc.type: FUNC 123 * @tc.require: issue 124 */ 125 HWTEST_F(NotificationProgressTest, Marshalling_00001, Function | SmallTest | Level1) 126 { 127 NotificationProgress notificationProgress; 128 notificationProgress.SetIsPercentage(true); 129 notificationProgress.SetMaxValue(1); 130 notificationProgress.SetCurrentValue(1); 131 132 Parcel parcel; 133 notificationProgress.Marshalling(parcel); 134 EXPECT_NE(nullptr, notificationProgress.Unmarshalling(parcel)); 135 } 136 } 137 } 138