@@ -1327,6 +1327,88 @@ void test_ble_scan_on_ble_evt_adv_report_device_uuid_connect(void)
13271327 TEST_ASSERT_EQUAL (BLE_SCAN_EVT_FILTER_MATCH , scan_event .evt_type );
13281328}
13291329
1330+ void test_ble_scan_on_ble_evt_adv_report_device_manufacturer_data_not_found (void )
1331+ {
1332+ /* Advertising packet does not contain manufacturer-specific data matching the configured
1333+ * filter. The mocked find helper returns false, so the scan event handler must receive
1334+ * BLE_SCAN_EVT_NOT_FOUND.
1335+ */
1336+ uint8_t manuf_data_exp [2 ];
1337+ uint8_t dummy_data [] = "hello" ;
1338+ ble_evt_t ble_evt = {
1339+ .header .evt_id = BLE_GAP_EVT_ADV_REPORT ,
1340+ .evt .gap_evt = {
1341+ .conn_handle = CONN_HANDLE ,
1342+ .params .adv_report = {
1343+ .data = {
1344+ .p_data = dummy_data ,
1345+ .len = sizeof (dummy_data ),
1346+ },
1347+ },
1348+ },
1349+ };
1350+
1351+ /* Encode the company identifier in little-endian as required by the BLE spec. */
1352+ sys_put_le16 (BLE_COMPANY_ID_NORDIC , manuf_data_exp );
1353+
1354+ test_ble_scan_filter_add_manufacturer_data ();
1355+
1356+ __cmock_ble_adv_data_manufacturer_data_find_ExpectWithArrayAndReturn (
1357+ ble_evt .evt .gap_evt .params .adv_report .data .p_data , 1 ,
1358+ ble_evt .evt .gap_evt .params .adv_report .data .len ,
1359+ manuf_data_exp , sizeof (manuf_data_exp ), sizeof (manuf_data_exp ),
1360+ false); /* Mock "no manufacturer data match" -> expect BLE_SCAN_EVT_NOT_FOUND */
1361+ __cmock_sd_ble_gap_scan_start_ExpectAndReturn (NULL , & ble_scan .scan_buffer , NRF_SUCCESS );
1362+
1363+ ble_evt_send (& ble_evt );
1364+ TEST_ASSERT_EQUAL (BLE_SCAN_EVT_NOT_FOUND , scan_event .evt_type );
1365+ }
1366+
1367+ void test_ble_scan_on_ble_evt_adv_report_device_manufacturer_data (void )
1368+ {
1369+ /* Advertising packet contains manufacturer-specific data matching the configured filter.
1370+ * The mocked find helper returns true, so the scan event handler must receive
1371+ * BLE_SCAN_EVT_FILTER_MATCH with only manufacturer_data_filter_match set.
1372+ */
1373+ uint8_t manuf_data_exp [2 ];
1374+ uint8_t dummy_data [] = "hello" ;
1375+ ble_evt_t ble_evt = {
1376+ .header .evt_id = BLE_GAP_EVT_ADV_REPORT ,
1377+ .evt .gap_evt = {
1378+ .conn_handle = CONN_HANDLE ,
1379+ .params .adv_report = {
1380+ .data = {
1381+ .p_data = dummy_data ,
1382+ .len = sizeof (dummy_data ),
1383+ },
1384+ },
1385+ },
1386+ };
1387+
1388+ /* Encode the company identifier in little-endian as required by the BLE spec. */
1389+ sys_put_le16 (BLE_COMPANY_ID_NORDIC , manuf_data_exp );
1390+
1391+ test_ble_scan_filter_add_manufacturer_data ();
1392+
1393+ __cmock_ble_adv_data_manufacturer_data_find_ExpectWithArrayAndReturn (
1394+ ble_evt .evt .gap_evt .params .adv_report .data .p_data , 1 ,
1395+ ble_evt .evt .gap_evt .params .adv_report .data .len ,
1396+ manuf_data_exp , sizeof (manuf_data_exp ), sizeof (manuf_data_exp ),
1397+ true); /* Mock "manufacturer data match" -> expect BLE_SCAN_EVT_FILTER_MATCH */
1398+ __cmock_sd_ble_gap_scan_start_ExpectAndReturn (NULL , & ble_scan .scan_buffer , NRF_SUCCESS );
1399+
1400+ ble_evt_send (& ble_evt );
1401+ TEST_ASSERT_EQUAL (BLE_SCAN_EVT_FILTER_MATCH , scan_event .evt_type );
1402+ TEST_ASSERT_EQUAL (0 , scan_event .filter_match .filter_match .address_filter_match );
1403+ TEST_ASSERT_EQUAL (0 , scan_event .filter_match .filter_match .name_filter_match );
1404+ TEST_ASSERT_EQUAL (0 , scan_event .filter_match .filter_match .short_name_filter_match );
1405+ TEST_ASSERT_EQUAL (0 , scan_event .filter_match .filter_match .appearance_filter_match );
1406+ TEST_ASSERT_EQUAL (0 , scan_event .filter_match .filter_match .uuid_filter_match );
1407+ TEST_ASSERT_EQUAL (1 , scan_event .filter_match .filter_match .manufacturer_data_filter_match );
1408+ TEST_ASSERT_EQUAL_PTR (& ble_evt .evt .gap_evt .params .adv_report ,
1409+ scan_event .filter_match .adv_report );
1410+ }
1411+
13301412void test_ble_scan_on_ble_evt_timeout (void )
13311413{
13321414 ble_evt_t ble_evt = {
0 commit comments