Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Darwin discovery test. #36833

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice

[_results addObject:snapshot];

XCTAssertLessThanOrEqual(_results.count, kExpectedDiscoveredDevicesCount);

__auto_type instanceName = device.instanceName;
__auto_type vendorId = device.vendorID;
__auto_type productId = device.productID;
__auto_type discriminator = device.discriminator;
__auto_type commissioningMode = device.commissioningMode;

XCTAssertEqual(instanceName.length, 16); // The instance name is random, so just ensure the len is right.
XCTAssertEqualObjects(vendorId, @(kTestVendorId));
XCTAssertTrue([kTestProductIds containsObject:productId]);
XCTAssertTrue([kTestDiscriminators containsObject:discriminator]);
XCTAssertEqual(commissioningMode, YES);

NSLog(@"Found device %@", snapshot);

if (_results.count == kExpectedDiscoveredDevicesCount) {
// Do some sanity checking on our results and removedResults to make
// sure we really only saw the relevant set of things.
Expand All @@ -123,39 +139,17 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice
[self.expectation fulfill];
}
}

XCTAssertLessThanOrEqual(_results.count, kExpectedDiscoveredDevicesCount);

__auto_type instanceName = device.instanceName;
__auto_type vendorId = device.vendorID;
__auto_type productId = device.productID;
__auto_type discriminator = device.discriminator;
__auto_type commissioningMode = device.commissioningMode;

XCTAssertEqual(instanceName.length, 16); // The instance name is random, so just ensure the len is right.
XCTAssertEqualObjects(vendorId, @(kTestVendorId));
XCTAssertTrue([kTestProductIds containsObject:productId]);
XCTAssertTrue([kTestDiscriminators containsObject:discriminator]);
XCTAssertEqual(commissioningMode, YES);

NSLog(@"Found Device (%@) with discriminator: %@ (vendor: %@, product: %@)", instanceName, discriminator, vendorId, productId);
}

- (void)controller:(MTRDeviceController *)controller didRemoveCommissionableDevice:(MTRCommissionableBrowserResult *)device
{
__auto_type instanceName = device.instanceName;
__auto_type vendorId = device.vendorID;
__auto_type productId = device.productID;
__auto_type discriminator = device.discriminator;

NSLog(
@"Removed Device (%@) with discriminator: %@ (vendor: %@, product: %@)", instanceName, discriminator, vendorId, productId);

__auto_type * snapshot = ResultSnapshot(device);
XCTAssertTrue([_results containsObject:snapshot], @"Removed device %@ is not something we found before", snapshot);
XCTAssertTrue([_results containsObject:snapshot], @"Removed device %@ is not something we found before: %@", snapshot, _results);

[_removedResults addObject:snapshot];
[_results removeObject:snapshot];

NSLog(@"Removed device %@", snapshot);
}
@end

Expand Down
Loading