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 "query_app_info_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 QueryAppInfoCallbackStubTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
myTagCallback(std::vector<int>)33 std::vector<AppExecFwk::ElementName> myTagCallback(std::vector<int>)
34 {
35 return std::vector<AppExecFwk::ElementName> {};
36 }
37
myHceCallback()38 std::vector<AAFwk::Want> myHceCallback()
39 {
40 return std::vector<AAFwk::Want> {};
41 }
42
SetUpTestCase()43 void QueryAppInfoCallbackStubTest::SetUpTestCase()
44 {
45 std::cout << " SetUpTestCase QueryAppInfoCallbackStubTest." << std::endl;
46 }
47
TearDownTestCase()48 void QueryAppInfoCallbackStubTest::TearDownTestCase()
49 {
50 std::cout << " TearDownTestCase QueryAppInfoCallbackStubTest." << std::endl;
51 }
52
SetUp()53 void QueryAppInfoCallbackStubTest::SetUp()
54 {
55 std::cout << " SetUp QueryAppInfoCallbackStubTest." << std::endl;
56 }
57
TearDown()58 void QueryAppInfoCallbackStubTest::TearDown()
59 {
60 std::cout << " TearDown QueryAppInfoCallbackStubTest." << std::endl;
61 }
62
63 #ifdef VENDOR_APPLICATIONS_ENABLED
64 /**
65 * @tc.name: OnRemoteRequest001
66 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
67 * @tc.type: FUNC
68 */
69 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest001, TestSize.Level1)
70 {
71 uint32_t code = 0;
72 MessageParcel data;
73 MessageParcel reply;
74 MessageOption option;
75 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
76 int onRemoteRequest = queryAppInfoCallbackStub->OnRemoteRequest(code, data, reply, option);
77 ASSERT_TRUE(onRemoteRequest == KITS::ERR_NFC_PARAMETERS);
78 }
79
80 /**
81 * @tc.name: RegisterQueryTagAppCallback001
82 * @tc.desc: Test QueryAppInfoCallbackStubTest RegisterQueryTagAppCallback.
83 * @tc.type: FUNC
84 */
85 HWTEST_F(QueryAppInfoCallbackStubTest, RegisterQueryTagAppCallback001, TestSize.Level1)
86 {
87 QueryApplicationByVendor tagCallback = nullptr;
88 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
89 KITS::ErrorCode ret = queryAppInfoCallbackStub->RegisterQueryTagAppCallback(tagCallback);
90 ASSERT_TRUE(ret == KITS::ERR_NFC_PARAMETERS);
91 }
92
93 /**
94 * @tc.name: RegisterQueryTagAppCallback002
95 * @tc.desc: Test QueryAppInfoCallbackStubTest RegisterQueryTagAppCallback.
96 * @tc.type: FUNC
97 */
98 HWTEST_F(QueryAppInfoCallbackStubTest, RegisterQueryTagAppCallback002, TestSize.Level1)
99 {
100 QueryApplicationByVendor tagCallback = myTagCallback;
101 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
102 KITS::ErrorCode ret = queryAppInfoCallbackStub->RegisterQueryTagAppCallback(tagCallback);
103 ASSERT_TRUE(ret == KITS::ERR_NONE);
104 }
105
106 /**
107 * @tc.name: RegisterQueryTagAppCallback003
108 * @tc.desc: Test QueryAppInfoCallbackStubTest RegisterQueryTagAppCallback.
109 * @tc.type: FUNC
110 */
111 HWTEST_F(QueryAppInfoCallbackStubTest, RegisterQueryTagAppCallback003, TestSize.Level1)
112 {
113 QueryApplicationByVendor tagCallback = myTagCallback;
114 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
115 queryAppInfoCallbackStub->RegisterQueryTagAppCallback(tagCallback);
116 KITS::ErrorCode ret = queryAppInfoCallbackStub->RegisterQueryTagAppCallback(tagCallback);
117 ASSERT_TRUE(ret == KITS::ERR_NFC_PARAMETERS);
118 }
119
120 /**
121 * @tc.name: RegisterQueryHceAppCallback001
122 * @tc.desc: Test QueryAppInfoCallbackStubTest RegisterQueryHceAppCallback.
123 * @tc.type: FUNC
124 */
125 HWTEST_F(QueryAppInfoCallbackStubTest, RegisterQueryHceAppCallback001, TestSize.Level1)
126 {
127 QueryHceAppByVendor hceCallback = nullptr;
128 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
129 KITS::ErrorCode ret = queryAppInfoCallbackStub->RegisterQueryHceAppCallback(hceCallback);
130 ASSERT_TRUE(ret == KITS::ERR_NFC_PARAMETERS);
131 }
132
133 /**
134 * @tc.name: RegisterQueryHceAppCallback002
135 * @tc.desc: Test QueryAppInfoCallbackStubTest RegisterQueryHceAppCallback.
136 * @tc.type: FUNC
137 */
138 HWTEST_F(QueryAppInfoCallbackStubTest, RegisterQueryHceAppCallback002, TestSize.Level1)
139 {
140 QueryHceAppByVendor hceCallback = myHceCallback;
141 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
142 KITS::ErrorCode ret = queryAppInfoCallbackStub->RegisterQueryHceAppCallback(hceCallback);
143 ASSERT_TRUE(ret == KITS::ERR_NONE);
144 }
145
146 /**
147 * @tc.name: OnRemoteRequest0001
148 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
149 * @tc.type: FUNC
150 */
151 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest0001, TestSize.Level1)
152 {
153 MessageParcel data;
154 MessageParcel reply;
155 MessageOption option;
156 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
157 int ret = queryAppInfoCallbackStub->OnRemoteRequest(0, data, reply, option);
158 ASSERT_TRUE(ret == KITS::ERR_NFC_PARAMETERS);
159 }
160
161 /**
162 * @tc.name: OnRemoteRequest002
163 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
164 * @tc.type: FUNC
165 */
166 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest002, TestSize.Level1)
167 {
168 MessageParcel data;
169 MessageParcel reply;
170 MessageOption option;
171 std::u16string descriptor = u"ohos.nfc.IQueryAppInfoCallback";
172 data.WriteInterfaceToken(descriptor);
173 data.WriteInt32(1);
174 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
175 int ret = queryAppInfoCallbackStub->OnRemoteRequest(0, data, reply, option);
176 ASSERT_TRUE(ret == 1);
177 }
178
179 /**
180 * @tc.name: OnRemoteRequest003
181 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
182 * @tc.type: FUNC
183 */
184 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest003, TestSize.Level1)
185 {
186 MessageParcel data;
187 MessageParcel reply;
188 MessageOption option;
189 std::u16string descriptor = u"ohos.nfc.IQueryAppInfoCallback";
190 data.WriteInterfaceToken(descriptor);
191 data.WriteInt32(0);
192 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
193 int ret = queryAppInfoCallbackStub->OnRemoteRequest(0, data, reply, option);
194 ASSERT_TRUE(ret);
195 }
196
197 /**
198 * @tc.name: OnRemoteRequest004
199 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
200 * @tc.type: FUNC
201 */
202 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest004, TestSize.Level1)
203 {
204 MessageParcel data;
205 MessageParcel reply;
206 MessageOption option;
207 std::u16string descriptor = u"ohos.nfc.IQueryAppInfoCallback";
208 data.WriteInterfaceToken(descriptor);
209 data.WriteInt32(0);
210 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
211 int ret = queryAppInfoCallbackStub->OnRemoteRequest(114, data, reply, option);
212 ASSERT_TRUE(!ret);
213 }
214
215 /**
216 * @tc.name: OnRemoteRequest005
217 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
218 * @tc.type: FUNC
219 */
220 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest005, TestSize.Level1)
221 {
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option;
225 std::u16string descriptor = u"ohos.nfc.IQueryAppInfoCallback";
226 data.WriteInterfaceToken(descriptor);
227 data.WriteInt32(0);
228 data.WriteString("tag");
229 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
230 int ret = queryAppInfoCallbackStub->OnRemoteRequest(114, data, reply, option);
231 ASSERT_TRUE(!ret);
232 }
233
234 /**
235 * @tc.name: OnRemoteRequest007
236 * @tc.desc: Test QueryAppInfoCallbackStubTest OnRemoteRequest.
237 * @tc.type: FUNC
238 */
239 HWTEST_F(QueryAppInfoCallbackStubTest, OnRemoteRequest007, TestSize.Level1)
240 {
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option;
244 std::u16string descriptor = u"ohos.nfc.IQueryAppInfoCallback";
245 data.WriteInterfaceToken(descriptor);
246 data.WriteInt32(0);
247 data.WriteString("hce");
248 std::shared_ptr<QueryAppInfoCallbackStub> queryAppInfoCallbackStub = std::make_shared<QueryAppInfoCallbackStub>();
249 int ret = queryAppInfoCallbackStub->OnRemoteRequest(114, data, reply, option);
250 ASSERT_TRUE(!ret);
251 }
252 #endif
253 }
254 }
255 }