Skip to content

Commit

Permalink
Address review comments and fix tests to work in the new setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Apr 16, 2024
1 parent 5ed6ad0 commit 4d0e686
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,9 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)

// Send read request to device if any of the following are true:
// 1. Subscription not in a state we can expect reports
// 2. The attribute has (or is assumed to have) the Changes Omitted quality, so we won't get reports for it.
// 2. The attribute has the Changes Omitted quality, so we won't get reports for it.
// 3. The attribute is not in the spec, and the read params asks to assume
// an unknown attribute has the Changes Omitted quality.
if (![self _subscriptionAbleToReport] || hasChangesOmittedQuality) {
// Read requests container will be a mutable array of items, each being an array containing:
// [attribute request path, params]
Expand Down
7 changes: 6 additions & 1 deletion src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,10 @@ - (void)test017_TestMTRDeviceBasics
[self waitForExpectations:@[ onTimeWriteSuccess, onTimePreviousValue ] timeout:10];

// Test if errors are properly received
// TODO: We might stop reporting these altogether from MTRDevice, and then
// this test will need updating.
__auto_type * readThroughForUnknownAttributesParams = [[MTRReadParams alloc] init];
readThroughForUnknownAttributesParams.assumeUnknownAttributesReportable = NO;
XCTestExpectation * attributeReportErrorExpectation = [self expectationWithDescription:@"Attribute read error"];
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * data) {
for (NSDictionary<NSString *, id> * attributeReponseValue in data) {
Expand All @@ -1526,8 +1530,9 @@ - (void)test017_TestMTRDeviceBasics
}
}
};

// use the nonexistent attribute and expect read error
[device readAttributeWithEndpointID:testEndpointID clusterID:testClusterID attributeID:testAttributeID params:nil];
[device readAttributeWithEndpointID:testEndpointID clusterID:testClusterID attributeID:testAttributeID params:readThroughForUnknownAttributesParams];
[self waitForExpectations:@[ attributeReportErrorExpectation ] timeout:10];

// Resubscription test setup
Expand Down
6 changes: 5 additions & 1 deletion src/darwin/Framework/CHIPTests/MTRSwiftDeviceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ class MTRSwiftDeviceTests : XCTestCase {
wait(for: [ expectedValueReportedExpectation, expectedValueRemovedExpectation ], timeout: 5, enforceOrder: true)

// Test if errors are properly received
// TODO: We might stop reporting these altogether from MTRDevice, and then
// this test will need updating.
let readThroughForUnknownAttributesParams = MTRReadParams()
readThroughForUnknownAttributesParams.shouldAssumeUnknownAttributesReportable = false;
let attributeReportErrorExpectation = expectation(description: "Attribute read error")
delegate.onAttributeDataReceived = { (data: [[ String: Any ]]) -> Void in
for attributeReponseValue in data {
Expand All @@ -296,7 +300,7 @@ class MTRSwiftDeviceTests : XCTestCase {
}
}
// use the nonexistent attribute and expect read error
device.readAttribute(withEndpointID: testEndpointID, clusterID: testClusterID, attributeID: testAttributeID, params: nil)
device.readAttribute(withEndpointID: testEndpointID, clusterID: testClusterID, attributeID: testAttributeID, params: readThroughForUnknownAttributesParams)
wait(for: [ attributeReportErrorExpectation ], timeout: 10)

// Resubscription test setup
Expand Down

0 comments on commit 4d0e686

Please sign in to comment.