@@ -191,39 +191,54 @@ void BluetoothDeviceTestSuite::test_deviceDetection_invalidNames_enabled()
191191 this ->test_deviceDetection (false , true );
192192}
193193
194- void BluetoothDeviceTestSuite::test_deviceDetection_exclusions () {
195- auto testData = this ->testParam ;
196-
197- auto exclusionNames = testData->Exclusions ();
198-
199- if (exclusionNames.size ()==0 )
200- GTEST_SKIP () << " No exclusions defined for this device: " << testData->Name ().toStdString ();
201-
202- // Only take the first for each type of exclusion
203- std::vector<const BluetoothDeviceTestData*> exclusions;
204- std::unordered_set<int > exclusionTypeIds;
205- for (auto exclusionName : exclusionNames)
206- {
207- auto deviceTestData = DeviceTestDataIndex::GetTestData (exclusionName);
208- if (exclusionTypeIds.count (deviceTestData->ExpectedDeviceType ()))
209- continue ;
210- exclusions.push_back (deviceTestData);
211- exclusionTypeIds.insert (deviceTestData->ExpectedDeviceType ());
212- }
213-
214- bluetooth bt (this ->defaultDiscoveryOptions );
215-
216- // Test that it doesn't detect this device if its higher priority "namesakes" are already detected.
217- for (auto exclusion : exclusions) {
218-
219- // For each name that would otherwise result in the device being detected
220- for (QString deviceName : this ->names )
221- {
222- // Get the enabling configurations
223- auto enablingConfigurations = this ->getConfigurations (testData, deviceName, true );
224-
225- for (size_t i=0 ; i<enablingConfigurations.size (); i++) {
226- DeviceDiscoveryInfo enablingDiscoveryInfo = enablingConfigurations[i];
194+ void BluetoothDeviceTestSuite::test_deviceDetection_exclusions () {
195+ auto testData = this ->testParam ;
196+
197+ auto exclusionNames = testData->Exclusions ();
198+
199+ if (exclusionNames.size ()==0 )
200+ GTEST_SKIP () << " No exclusions defined for this device: " << testData->Name ().toStdString ();
201+
202+ bluetooth bt (this ->defaultDiscoveryOptions );
203+
204+ // Test that it doesn't detect this device if its higher priority "namesakes" are already detected.
205+ for (QString deviceName : this ->names )
206+ {
207+ // Prefer exclusions that actually collide with the specific bluetooth name being tested.
208+ std::vector<const BluetoothDeviceTestData*> exclusions;
209+ std::unordered_set<int > exclusionTypeIds;
210+
211+ for (auto exclusionName : exclusionNames)
212+ {
213+ auto candidate = DeviceTestDataIndex::GetTestData (exclusionName);
214+ auto typeId = candidate->ExpectedDeviceType ();
215+
216+ if (exclusionTypeIds.count (typeId))
217+ continue ;
218+
219+ const BluetoothDeviceTestData *selected = candidate;
220+ for (auto alternativeName : exclusionNames)
221+ {
222+ auto alternative = DeviceTestDataIndex::GetTestData (alternativeName);
223+ if (alternative->ExpectedDeviceType () != typeId)
224+ continue ;
225+
226+ if (alternative->NamePatternGroup ()->DeviceNames ().contains (deviceName)) {
227+ selected = alternative;
228+ break ;
229+ }
230+ }
231+
232+ exclusions.push_back (selected);
233+ exclusionTypeIds.insert (typeId);
234+ }
235+
236+ for (auto exclusion : exclusions) {
237+ // Get the enabling configurations
238+ auto enablingConfigurations = this ->getConfigurations (testData, deviceName, true );
239+
240+ for (size_t i=0 ; i<enablingConfigurations.size (); i++) {
241+ DeviceDiscoveryInfo enablingDiscoveryInfo = enablingConfigurations[i];
227242
228243 // get an enabling configuration for the exclusion
229244 DeviceDiscoveryInfo exclusionDiscoveryInfo (true );
@@ -253,9 +268,8 @@ void BluetoothDeviceTestSuite::test_deviceDetection_exclusions() {
253268
254269 failMessage = QString (" Detected the %1 from %2 with valid config %3 in spite of exclusion by %4" )
255270 .arg (testData->Name ()).arg (deviceName).arg (i).arg (exclusion->Name ());
256- this ->testDeviceDetection (testData, bt, *enablingDiscoveryInfo.DeviceInfo (), false , true , failMessage);
257- }
258-
259- }
260- }
261- }
271+ this ->testDeviceDetection (testData, bt, *enablingDiscoveryInfo.DeviceInfo (), false , true , failMessage);
272+ }
273+ }
274+ }
275+ }
0 commit comments