• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 
20 #include "notification_slot.h"
21 
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Notification {
25 class NotificationSlotTest : public testing::Test {
26 public:
SetUpTestCase()27     static void SetUpTestCase() {}
TearDownTestCase()28     static void TearDownTestCase() {}
SetUp()29     void SetUp() {}
TearDown()30     void TearDown() {}
31 };
32 
33 /**
34  * @tc.name: GetSlotTypeByString_00001
35  * @tc.desc: Test GetSlotTypeByString method is ok.
36  * @tc.type: FUNC
37  * @tc.require: issue
38  */
39 HWTEST_F(NotificationSlotTest, GetSlotTypeByString_00001, Function | SmallTest | Level1)
40 {
41     NotificationConstant::SlotType type;
42     EXPECT_EQ(NotificationSlot::GetSlotTypeByString(NotificationSlot::CONTENT_INFORMATION, type), true);
43     EXPECT_EQ(type, NotificationConstant::SlotType::CONTENT_INFORMATION);
44 }
45 
46 /**
47  * @tc.name: GetSlotTypeByString_00002
48  * @tc.desc: Test GetSlotTypeByString method is false.
49  * @tc.type: FUNC
50  * @tc.require: issue
51  */
52 HWTEST_F(NotificationSlotTest, GetSlotTypeByString_00002, Function | SmallTest | Level1)
53 {
54     NotificationConstant::SlotType type;
55     const std::string inputStr = "others";
56     EXPECT_EQ(NotificationSlot::GetSlotTypeByString(inputStr, type), false);
57 }
58 
59 /**
60  * @tc.name: GetSlotFlags_00001
61  * @tc.desc: Test GetSlotTypeByString method is false.
62  * @tc.type: FUNC
63  * @tc.require: issue
64  */
65 HWTEST_F(NotificationSlotTest, GetSlotFlags_00001, Function | SmallTest | Level1)
66 {
67     NotificationSlot notificationSlot;
68     notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION);
69     ASSERT_EQ(notificationSlot.GetId(), "EMERGENCY_INFORMATION");
70 
71     notificationSlot.SetSlotFlags(1);
72     ASSERT_EQ(notificationSlot.GetSlotFlags(), 1);
73 }
74 
75 /**
76  * @tc.name: Unmarshalling_00001
77  * @tc.desc: Test GetSlotTypeByString method is false.
78  * @tc.type: FUNC
79  * @tc.require: issue
80  */
81 HWTEST_F(NotificationSlotTest, Unmarshalling_00001, Function | SmallTest | Level1)
82 {
83     NotificationSlot notificationSlot;
84     notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION);
85     Parcel parcel;
86     auto res = notificationSlot.Marshalling(parcel);
87     ASSERT_TRUE(res);
88     Uri uri("123");
89     notificationSlot.SetSound(uri);
90 
91     sptr<NotificationSlot> notificationSlotSptr = notificationSlot.Unmarshalling(parcel);
92     ASSERT_NE(notificationSlotSptr, nullptr);
93     ASSERT_NE(notificationSlotSptr->GetSound().ToString(), "123");
94 }
95 
96 /**
97  * @tc.name: MergeVectorToString_00001
98  * @tc.desc: Test GetSlotTypeByString method is false.
99  * @tc.type: FUNC
100  * @tc.require: issue
101  */
102 HWTEST_F(NotificationSlotTest, MergeVectorToString_00001, Function | SmallTest | Level1)
103 {
104     NotificationSlot notificationSlot;
105     notificationSlot.SetType(NotificationConstant::SlotType::EMERGENCY_INFORMATION);
106     std::vector<int64_t> mergeVector;
107     mergeVector.push_back(100);
108 
109     auto res = notificationSlot.MergeVectorToString(mergeVector);
110     auto it = res.find("100");
111     ASSERT_NE(it, std::string::npos);
112 }
113 }
114 }