1 /*
2 * Copyright (c) 2021 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 #define private public
16 #define protected public
17
18 #include "ans_notification.h"
19 #include "iservice_registry.h"
20 #include "singleton.h"
21 #include "system_ability_definition.h"
22
23 #undef private
24 #undef protected
25
26 #include <gtest/gtest.h>
27
28 using namespace testing::ext;
29
30 namespace OHOS {
31 namespace Notification {
32 class AnsDumpTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38
39 std::shared_ptr<AnsNotification> ans_;
40 };
41
SetUpTestCase()42 void AnsDumpTest::SetUpTestCase()
43 {}
44
TearDownTestCase()45 void AnsDumpTest::TearDownTestCase()
46 {}
47
SetUp()48 void AnsDumpTest::SetUp()
49 {
50 if (!ans_) {
51 ans_ = DelayedSingleton<AnsNotification>::GetInstance();
52 }
53 }
54
TearDown()55 void AnsDumpTest::TearDown()
56 {}
57
58 /*
59 * @tc.number: AnsDumpTest_GetServiceObject_0100
60 * @tc.name: Get Service Object
61 * @tc.desc:
62 */
63 HWTEST_F(AnsDumpTest, AnsDumpTest_GetServiceObject_0100, Function | MediumTest | Level0)
64 {
65 sptr<ISystemAbilityManager> systemAbilityManager =
66 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
67 EXPECT_NE(systemAbilityManager, nullptr);
68
69 sptr<IRemoteObject> remoteObject =
70 systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID);
71 EXPECT_NE(remoteObject, nullptr);
72 }
73
74 /*
75 * @tc.number: AnsDumpTest_ShellDump_0100
76 * @tc.name: Shell Dump
77 * @tc.desc:
78 */
79 HWTEST_F(AnsDumpTest, AnsDumpTest_ShellDump_0100, Function | MediumTest | Level0)
80 {
81 std::vector<std::string> infos;
82 if (ans_) {
83 auto ret = ans_->ShellDump("active", infos);
84 EXPECT_EQ(ret, 0);
85 }
86 }
87 } // namespace Notification
88 } // namespace OHOS