• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include <gtest/gtest.h>
16 #include <thread>
17 
18 #include "nfc_controller_death_recipient.h"
19 #include "nfc_controller_impl.h"
20 
21 namespace OHOS {
22 namespace NFC {
23 namespace TEST {
24 using namespace testing::ext;
25 using namespace OHOS::NFC;
26 class NfcControllerDeathRecipientTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void NfcControllerDeathRecipientTest::SetUpTestCase()
35 {
36     std::cout << " SetUpTestCase NfcControllerDeathRecipientTest." << std::endl;
37 }
38 
TearDownTestCase()39 void NfcControllerDeathRecipientTest::TearDownTestCase()
40 {
41     std::cout << " TearDownTestCase NfcControllerDeathRecipientTest." << std::endl;
42 }
43 
SetUp()44 void NfcControllerDeathRecipientTest::SetUp()
45 {
46     std::cout << " SetUp NfcControllerDeathRecipientTest." << std::endl;
47 }
48 
TearDown()49 void NfcControllerDeathRecipientTest::TearDown()
50 {
51     std::cout << " TearDown NfcControllerDeathRecipientTest." << std::endl;
52 }
53 
54 /**
55  * @tc.name: OnRemoteDied001
56  * @tc.desc: Test NfcControllerDeathRecipientTest OnRemoteDied.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(NfcControllerDeathRecipientTest, OnRemoteDied001, TestSize.Level1)
60 {
61     sptr<NfcControllerImpl> nfcConctrolService = nullptr;
62     Security::AccessToken::AccessTokenID callerToken = 0;
63     wptr<IRemoteObject> remote = nullptr;
64     std::shared_ptr<NfcControllerDeathRecipient> nfcControllerDeathRecipient =
65         std::make_shared<NfcControllerDeathRecipient>(nfcConctrolService, callerToken);
66     nfcControllerDeathRecipient->OnRemoteDied(remote);
67     ASSERT_TRUE(nfcControllerDeathRecipient != nullptr);
68 }
69 
70 /**
71  * @tc.name: OnRemoteDied002
72  * @tc.desc: Test NfcControllerDeathRecipientTest OnRemoteDied.
73  * @tc.type: FUNC
74  */
75 HWTEST_F(NfcControllerDeathRecipientTest, OnRemoteDied002, TestSize.Level1)
76 {
77     std::weak_ptr<NfcService> nfcService;
78     sptr<NfcControllerImpl> nfcConctrolService =
79         sptr<NfcControllerImpl>(new (std::nothrow) NfcControllerImpl(nfcService));
80     Security::AccessToken::AccessTokenID callerToken = 0;
81     wptr<IRemoteObject> remote = nullptr;
82     std::shared_ptr<NfcControllerDeathRecipient> nfcControllerDeathRecipient =
83         std::make_shared<NfcControllerDeathRecipient>(nfcConctrolService, callerToken);
84     nfcControllerDeathRecipient->OnRemoteDied(remote);
85     ASSERT_TRUE(nfcControllerDeathRecipient != nullptr);
86 }
87 }
88 }
89 }