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 "ans_log_wrapper.h" 19 #include "ans_dialog_host_client.h" 20 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace Notification { 25 class AnsDialogHostClientTest : 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 class TestAnsDialogCallback final : public AnsDialogCallbackNativeInterface { 34 public: 35 TestAnsDialogCallback() = default; 36 ~TestAnsDialogCallback() override = default; 37 ProcessDialogStatusChanged(const DialogStatusData & data)38 void ProcessDialogStatusChanged(const DialogStatusData& data) override 39 { 40 ANS_LOGE("ProcessDialogStatusChanged err called."); 41 } 42 }; 43 44 /** 45 * @tc.name: CreateIfNullptr_00001 46 * @tc.desc: Test CreateIfNullptr. 47 * @tc.type: FUNC 48 * @tc.require: issue 49 */ 50 HWTEST_F(AnsDialogHostClientTest, CreateIfNullptr_00001, Function | SmallTest | Level1) 51 { 52 sptr<AnsDialogHostClient> client = nullptr; 53 AnsDialogHostClient::CreateIfNullptr(client); 54 client = AnsDialogHostClient::GetInstance(); 55 EXPECT_NE(client, nullptr); 56 } 57 58 /** 59 * @tc.name: Destroy_00001 60 * @tc.desc: Test Destroy. 61 * @tc.type: FUNC 62 * @tc.require: issue 63 */ 64 HWTEST_F(AnsDialogHostClientTest, Destroy_00001, Function | SmallTest | Level1) 65 { 66 sptr<AnsDialogHostClient> client = nullptr; 67 AnsDialogHostClient::CreateIfNullptr(client); 68 client = AnsDialogHostClient::GetInstance(); 69 EXPECT_NE(client, nullptr); 70 client->Destroy(); 71 auto newClient = AnsDialogHostClient::GetInstance(); 72 EXPECT_EQ(newClient.GetRefPtr(), nullptr); 73 } 74 } 75 } 76