Skip to content

Commit e57e270

Browse files
Fix data type check in MTRDevice's invokeCommandWithEndpointID.
We were checking two NSStrings for pointer-equality, when we should be testing for logical equality.
1 parent 241cec1 commit e57e270

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
10591059
}
10601060

10611061
MTRDeviceDataValueDictionary fieldsDataValue = commandFields;
1062-
if (fieldsDataValue[MTRTypeKey] != MTRStructureValueType) {
1062+
if (![MTRStructureValueType isEqual:fieldsDataValue[MTRTypeKey]]) {
10631063
MTR_LOG_ERROR("%@ invokeCommandWithEndpointID passed a commandFields (%@) that is not a structure-typed data-value object",
10641064
self, commandFields);
10651065
completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]);

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+45
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,51 @@ - (void)test019_MTRDeviceMultipleCommands
19261926
}];
19271927

19281928
[self waitForExpectations:@[ readFabricLabelExpectation ] timeout:kTimeoutInSeconds];
1929+
1930+
// Now test doing the UpdateFabricLabel command but directly via the
1931+
// MTRDevice API.
1932+
XCTestExpectation * updateLabelExpectation2 = [self expectationWithDescription:@"Fabric label updated a second time"];
1933+
// IMPORTANT: commandFields here uses hardcoded strings, not MTR* constants
1934+
// for the strings, to check for places that are doing string equality wrong.
1935+
__auto_type * commandFields = @{
1936+
@"type" : @"Structure",
1937+
@"value" : @[
1938+
@{
1939+
@"contextTag" : @0,
1940+
@"data" : @ {
1941+
@"type" : @"UTF8String",
1942+
@"value" : @"Test2",
1943+
},
1944+
},
1945+
],
1946+
};
1947+
1948+
[device invokeCommandWithEndpointID:@(0)
1949+
clusterID:@(MTRClusterIDTypeOperationalCredentialsID)
1950+
commandID:@(MTRCommandIDTypeClusterOperationalCredentialsCommandUpdateFabricLabelID)
1951+
commandFields:commandFields
1952+
expectedValues:nil
1953+
expectedValueInterval:nil
1954+
queue:queue
1955+
completion:^(NSArray<NSDictionary<NSString *, id> *> * _Nullable values, NSError * _Nullable error) {
1956+
XCTAssertNil(error);
1957+
[updateLabelExpectation2 fulfill];
1958+
}];
1959+
1960+
[self waitForExpectations:@[ updateLabelExpectation2 ] timeout:kTimeoutInSeconds];
1961+
1962+
// And again, make sure our fabric label got updated.
1963+
readFabricLabelExpectation = [self expectationWithDescription:@"Read fabric label third time"];
1964+
[baseOpCredsCluster readAttributeFabricsWithParams:nil completion:^(NSArray * _Nullable value, NSError * _Nullable error) {
1965+
XCTAssertNil(error);
1966+
XCTAssertNotNil(value);
1967+
XCTAssertEqual(value.count, 1);
1968+
MTROperationalCredentialsClusterFabricDescriptorStruct * entry = value[0];
1969+
XCTAssertEqualObjects(entry.label, @"Test2");
1970+
[readFabricLabelExpectation fulfill];
1971+
}];
1972+
1973+
[self waitForExpectations:@[ readFabricLabelExpectation ] timeout:kTimeoutInSeconds];
19291974
}
19301975

19311976
- (void)test020_ReadMultipleAttributes

0 commit comments

Comments
 (0)