• 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 "ndef_msg_callback_stub.h"
19 
20 namespace OHOS {
21 namespace NFC {
22 namespace TEST {
23 using namespace testing::ext;
24 using namespace OHOS::NFC;
25 class NdefMsgCallbackStubTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
33 class INdefMsgCallbackImpl : public INdefMsgCallback {
34 public:
INdefMsgCallbackImpl()35     INdefMsgCallbackImpl() {}
36 
~INdefMsgCallbackImpl()37     virtual ~INdefMsgCallbackImpl() {}
38 
39 public:
OnNdefMsgDiscovered(const std::string & tagUid,const std::string & ndef,int ndefMsgType)40     bool OnNdefMsgDiscovered(const std::string &tagUid, const std::string &ndef, int ndefMsgType) override
41     {
42         return false;
43     }
44 
AsObject()45     OHOS::sptr<OHOS::IRemoteObject> AsObject() override
46     {
47         return nullptr;
48     }
49 };
50 
SetUpTestCase()51 void NdefMsgCallbackStubTest::SetUpTestCase()
52 {
53     std::cout << " SetUpTestCase NdefMsgCallbackStubTest." << std::endl;
54 }
55 
TearDownTestCase()56 void NdefMsgCallbackStubTest::TearDownTestCase()
57 {
58     std::cout << " TearDownTestCase NdefMsgCallbackStubTest." << std::endl;
59 }
60 
SetUp()61 void NdefMsgCallbackStubTest::SetUp()
62 {
63     std::cout << " SetUp NdefMsgCallbackStubTest." << std::endl;
64 }
65 
TearDown()66 void NdefMsgCallbackStubTest::TearDown()
67 {
68     std::cout << " TearDown NdefMsgCallbackStubTest." << std::endl;
69 }
70 
71 /**
72  * @tc.name: OnRemoteRequest001
73  * @tc.desc: Test NdefMsgCallbackStubTest OnRemoteRequest.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(NdefMsgCallbackStubTest, OnRemoteRequest001, TestSize.Level1)
77 {
78     uint32_t code = 0;
79     MessageParcel data;
80     MessageParcel reply;
81     MessageOption option;
82     std::shared_ptr<NdefMsgCallbackStub> ndefMsgCallbackStub = std::make_shared<NdefMsgCallbackStub>();
83     int onRemoteRequest = ndefMsgCallbackStub->OnRemoteRequest(code, data, reply, option);
84     ASSERT_TRUE(onRemoteRequest == KITS::ERR_NFC_PARAMETERS);
85 }
86 
87 /**
88  * @tc.name: OnRemoteRequest002
89  * @tc.desc: Test NdefMsgCallbackStubTest OnRemoteRequest.
90  * @tc.type: FUNC
91  */
92 HWTEST_F(NdefMsgCallbackStubTest, OnRemoteRequest002, TestSize.Level1)
93 {
94     uint32_t code = 0;
95     MessageParcel data;
96     MessageParcel reply;
97     MessageOption option;
98     std::u16string descriptor = u"ohos.nfc.kits.INdefMsgCallback";
99     data.WriteInterfaceToken(descriptor);
100     data.WriteInt32(1);
101     std::shared_ptr<NdefMsgCallbackStub> ndefMsgCallbackStub = std::make_shared<NdefMsgCallbackStub>();
102     int onRemoteRequest = ndefMsgCallbackStub->OnRemoteRequest(code, data, reply, option);
103     ASSERT_TRUE(onRemoteRequest == 1);
104 }
105 
106 /**
107  * @tc.name: OnRemoteRequest003
108  * @tc.desc: Test NdefMsgCallbackStubTest OnRemoteRequest.
109  * @tc.type: FUNC
110  */
111 HWTEST_F(NdefMsgCallbackStubTest, OnRemoteRequest003, TestSize.Level1)
112 {
113     uint32_t code = 0;
114     MessageParcel data;
115     MessageParcel reply;
116     MessageOption option;
117     std::u16string descriptor = u"ohos.nfc.kits.INdefMsgCallback";
118     data.WriteInterfaceToken(descriptor);
119     data.WriteInt32(0);
120     std::shared_ptr<NdefMsgCallbackStub> ndefMsgCallbackStub = std::make_shared<NdefMsgCallbackStub>();
121     int onRemoteRequest = ndefMsgCallbackStub->OnRemoteRequest(code, data, reply, option);
122     ASSERT_TRUE(onRemoteRequest);
123 }
124 
125 /**
126  * @tc.name: OnRemoteRequest004
127  * @tc.desc: Test NdefMsgCallbackStubTest OnRemoteRequest.
128  * @tc.type: FUNC
129  */
130 HWTEST_F(NdefMsgCallbackStubTest, OnRemoteRequest004, TestSize.Level1)
131 {
132     uint32_t code = 113;
133     MessageParcel data;
134     MessageParcel reply;
135     MessageOption option;
136     std::u16string descriptor = u"ohos.nfc.kits.INdefMsgCallback";
137     data.WriteInterfaceToken(descriptor);
138     data.WriteInt32(0);
139     std::shared_ptr<NdefMsgCallbackStub> ndefMsgCallbackStub = std::make_shared<NdefMsgCallbackStub>();
140     int onRemoteRequest = ndefMsgCallbackStub->OnRemoteRequest(code, data, reply, option);
141     ASSERT_TRUE(!onRemoteRequest);
142 }
143 
144 /**
145  * @tc.name: RegisterCallback001
146  * @tc.desc: Test NdefMsgCallbackStubTest RegisterCallback.
147  * @tc.type: FUNC
148  */
149 HWTEST_F(NdefMsgCallbackStubTest, RegisterCallback001, TestSize.Level1)
150 {
151     sptr<INdefMsgCallback> callback = nullptr;
152     std::shared_ptr<NdefMsgCallbackStub> ndefMsgCallbackStub = std::make_shared<NdefMsgCallbackStub>();
153     KITS::ErrorCode errorCode = ndefMsgCallbackStub->RegisterCallback(callback);
154     ASSERT_TRUE(errorCode == KITS::ERR_NFC_PARAMETERS);
155 }
156 }
157 }
158 }