@@ -56,6 +56,16 @@ using ::testing::AllOf;
56
56
using ::testing::Property;
57
57
using ::testing::InSequence;
58
58
59
+ /*
60
+ * Parametric fixture used for service discovery.
61
+ *
62
+ * Parameters are modeled by a tuple where:
63
+ * - [0] std::tuple<bool, bool>: pair of boolean indicating the presence of the
64
+ * service callback and the characteristic callback.
65
+ * - [1] UUID: UUID used for service filtering.
66
+ * - [2] UUID: UUID used for characteristic filtering.
67
+ * - [3] server_description_t: Discovered service layout.
68
+ */
59
69
class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
60
70
std::tuple<std::tuple<bool , bool >, UUID, UUID, server_description_t >
61
71
> {
@@ -74,6 +84,7 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
74
84
server_stub () {
75
85
}
76
86
87
+ // setup the test environment
77
88
virtual void SetUp () {
78
89
gatt_client.onServiceDiscoveryTermination (
79
90
makeFunctionPointer (
@@ -93,6 +104,10 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
93
104
std::tie (has_service_cb, has_characteristic_cb) = cb_combination;
94
105
}
95
106
107
+ /*
108
+ * Return a closure that sends a read by group type response to a client.
109
+ * @param[in] service_transactions The services to include in the response.
110
+ */
96
111
auto reply_read_by_group_type (const std::vector<service_description_t >& service_transactions) {
97
112
return Invoke ([service_transactions, this ](connection_handle_t connection, attribute_handle_t handle) -> ble_error_t {
98
113
// Log::info() << "discover primary service (" << connection << "," << handle << ")" << std::endl;
@@ -123,6 +138,11 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
123
138
});
124
139
}
125
140
141
+ /*
142
+ * Return a closure that sends a find by type value response to the client.
143
+ * @param[in] service_transactions Services to include in the response sent
144
+ * to the client.
145
+ */
126
146
auto reply_find_by_type_value (const std::vector<service_description_t >& service_transactions) {
127
147
return Invoke ([service_transactions, this ](connection_handle_t connection, attribute_handle_t handle, const UUID& uuid) -> ble_error_t {
128
148
// Log::info() << "discover primary service by uuid(" << connection << "," << handle << "," << uuid << ")" << std::endl;
@@ -146,6 +166,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
146
166
});
147
167
}
148
168
169
+ /* *
170
+ * Convert a DiscoveredCharacteristic::Properties_t into an uint8_t
171
+ */
149
172
uint8_t properties_to_byte (DiscoveredCharacteristic::Properties_t p) {
150
173
return (
151
174
p.broadcast () << 0 |
@@ -159,6 +182,11 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
159
182
);
160
183
}
161
184
185
+ /* *
186
+ * Return a closure that sends a read by type to a client.
187
+ * @param[in] transaction Characteristics to include in the response send to
188
+ * the client.
189
+ */
162
190
auto reply_read_by_type (const std::vector<characteristic_description_t >& transaction) {
163
191
return Invoke ([transaction, this ](connection_handle_t connection, attribute_handle_range_t range) -> ble_error_t {
164
192
// Log::info() << "discover characteristic(" << connection << "," << range.begin << "," << range.end << ")" << std::endl;
@@ -188,6 +216,11 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
188
216
});
189
217
}
190
218
219
+ /*
220
+ * Return a closure that send an error response to the client.
221
+ * @param[in] opcode Opcode that caused the error.
222
+ * @param[in] error_code Error code.
223
+ */
191
224
auto reply_error (AttributeOpcode opcode, AttErrorResponse::AttributeErrorCode error_code) {
192
225
return InvokeWithoutArgs ([this , opcode, error_code]() -> ble_error_t {
193
226
// Log::info() << "reply error: opcode = " << (uint8_t) opcode << ", error_code = " << error_code << std::endl;
@@ -199,8 +232,10 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
199
232
});
200
233
}
201
234
202
- // helper
203
- // note sequence insured by caller
235
+ /*
236
+ * Set service discovery expectation when the procedure discover all services
237
+ * is used.
238
+ */
204
239
void set_discover_all_services_expectations () {
205
240
auto services_transactions = get_services_transactions ();
206
241
@@ -233,6 +268,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
233
268
}
234
269
}
235
270
271
+ /*
272
+ * Set client expectations when the discover services by UUID is used.
273
+ */
236
274
void set_discover_services_by_uuid_expectations () {
237
275
std::vector<std::vector<uint8_t >> services_response;
238
276
auto services_transactions = get_services_transactions ();
@@ -276,6 +314,10 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
276
314
}
277
315
}
278
316
317
+ /*
318
+ * Set an expectation regarding call of the service discovery callback with
319
+ * the services @p services.
320
+ */
279
321
void set_services_callback_expectations (const std::vector<service_description_t >& services) {
280
322
if (!has_service_cb) {
281
323
return ;
@@ -286,6 +328,10 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
286
328
}
287
329
}
288
330
331
+ /*
332
+ * Set an expectation regarding call of the service discovery callback with
333
+ * the service @p service.
334
+ */
289
335
void set_service_callback_expectation (const service_description_t & service) {
290
336
if (!has_service_cb) {
291
337
return ;
@@ -313,7 +359,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
313
359
}));
314
360
}
315
361
316
-
362
+ /*
363
+ * Set expectations for characteristic discovery.
364
+ */
317
365
void set_discover_characteristics_expectations () {
318
366
auto services = get_services_discovered ();
319
367
@@ -411,6 +459,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
411
459
}));
412
460
}
413
461
462
+ /*
463
+ * Compute the transactions involved during the service discovery process.
464
+ */
414
465
std::vector<std::vector<service_description_t >> get_services_transactions () {
415
466
std::vector<service_description_t > working_set = get_services_discovered ();
416
467
@@ -440,6 +491,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
440
491
return result;
441
492
}
442
493
494
+ /*
495
+ * Compute the list of services discovered during service discovery.
496
+ */
443
497
std::vector<service_description_t > get_services_discovered () {
444
498
std::vector<service_description_t > working_set;
445
499
@@ -456,6 +510,9 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
456
510
return working_set;
457
511
}
458
512
513
+ /*
514
+ * Compute the transactions present during the characteristic discovery process.
515
+ */
459
516
std::vector<std::vector<characteristic_description_t >> get_characteristics_transactions (const service_description_t & service) {
460
517
std::vector<std::vector<characteristic_description_t >> transactions;
461
518
for (const auto & characteristic : service.characteristics ) {
@@ -495,7 +552,8 @@ class LaunchDiscoveryNoServiceFilter : public ::testing::TestWithParam<
495
552
};
496
553
497
554
TEST_P (LaunchDiscoveryNoServiceFilter, regular) {
498
-
555
+ // ///////////////////////////
556
+ // Install default calls
499
557
ON_CALL (
500
558
mock_client, discover_primary_service (_, _)
501
559
).WillByDefault (Invoke ([](connection_handle_t connection, attribute_handle_t handle) -> ble_error_t {
@@ -533,6 +591,8 @@ TEST_P(LaunchDiscoveryNoServiceFilter, regular) {
533
591
}));
534
592
}
535
593
594
+ // ///////////////////////////
595
+ // Install expectations
536
596
{
537
597
InSequence seq;
538
598
if (service_filter == UUID ()) {
@@ -548,6 +608,8 @@ TEST_P(LaunchDiscoveryNoServiceFilter, regular) {
548
608
EXPECT_CALL (termination_callback, call (connection_handle));
549
609
}
550
610
611
+ // ///////////////////////////
612
+ // Launch the discovery process.
551
613
ble_error_t err = gatt_client.launchServiceDiscovery (
552
614
connection_handle,
553
615
has_service_cb ?
@@ -568,14 +630,19 @@ TEST_P(LaunchDiscoveryNoServiceFilter, regular) {
568
630
INSTANTIATE_TEST_CASE_P (
569
631
GattClient_launch_discovery_no_service_filter,
570
632
LaunchDiscoveryNoServiceFilter,
633
+ // Yield all combination of each generator
571
634
::testing::Combine (
635
+ // service cb generator
572
636
::testing::Values (
573
637
std::tuple<bool , bool >(true , false ),
574
638
std::tuple<bool, bool>(false , true ),
575
639
std::tuple<bool, bool>(true , true )
576
640
),
641
+ // service UUID filter generator
577
642
::testing::Values(UUID(), UUID(0x1452 ), UUID(" a3d1495f-dba7-4441-99f2-d0a20f663422" )),
643
+ // characteristic UUID filter generator
578
644
::testing::Values(UUID(), UUID(0xBEEF ), UUID(" 1f551ee3-aef4-4719-8c52-8b419fc4ac01" )),
645
+ // server layout generator.
579
646
::testing::Values(
580
647
server_description_t { },
581
648
server_description_t {
0 commit comments