From d12314662eebdb8966b50ffd626ae8544979a5b2 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Wed, 26 Jan 2022 23:53:01 +0100 Subject: [PATCH] [YAML - Darwin] Generate saveAs code not only when the 'value' keyword is used (#14322) --- .../CHIP/templates/partials/test_cluster.zapt | 21 ++--- .../Framework/CHIPTests/CHIPClustersTests.m | 78 ++++++++++++++++++- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt index 7ff7f15f85700d..ba7d54df9131d0 100644 --- a/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt +++ b/src/darwin/Framework/CHIP/templates/partials/test_cluster.zapt @@ -102,15 +102,6 @@ ResponseHandler {{> subscribeDataCallback}} = nil; { {{> actualValue}} {{>check_test_value actual="actualValue" expected=expectedValue cluster=../cluster}} - {{#if saveAs}} - {{#if (isOctetString type)}} - {{saveAs}} = [NSMutableData dataWithData:actualValue]; - {{else if (isCharString type)}} - {{saveAs}} = [NSMutableString stringWithString:actualValue]; - {{else}} - {{saveAs}} = [actualValue {{asObjectiveCNumberType "" type true}}Value]; - {{/if}} - {{/if}} } {{/if}} {{#if hasExpectedConstraints}} @@ -193,6 +184,18 @@ ResponseHandler {{> subscribeDataCallback}} = nil; } {{/if}} {{/if}} + {{#if saveAs}} + { + {{> actualValue}} + {{#if (isOctetString type)}} + {{saveAs}} = [NSMutableData dataWithData:actualValue]; + {{else if (isCharString type)}} + {{saveAs}} = [NSMutableString stringWithString:actualValue]; + {{else}} + {{saveAs}} = [actualValue {{asObjectiveCNumberType "" type true}}Value]; + {{/if}} + } + {{/if}} {{/chip_tests_item_response_parameters}} {{#unless async}} diff --git a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m index 0a427ba2b96d9d..ebcbfc3ad6b65d 100644 --- a/src/darwin/Framework/CHIPTests/CHIPClustersTests.m +++ b/src/darwin/Framework/CHIPTests/CHIPClustersTests.m @@ -13577,6 +13577,11 @@ - (void)testSendClusterTest_TC_MC_8_1_000001_ReadAttribute XCTAssertEqual([CHIPErrorTestUtils errorToZCLErrorCode:err], 0); + { + id actualValue = value; + currentTarget = [actualValue unsignedCharValue]; + } + [expectation fulfill]; }]; @@ -37123,6 +37128,9 @@ - (void)testSendClusterTestSaveAs_000001_TestAddArguments { id actualValue = values.returnValue; XCTAssertEqual([actualValue unsignedCharValue], 20); + } + { + id actualValue = values.returnValue; TestAddArgumentDefaultValue = [actualValue unsignedCharValue]; } @@ -37209,6 +37217,9 @@ - (void)testSendClusterTestSaveAs_000004_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue boolValue], 0); + } + { + id actualValue = value; readAttributeBooleanDefaultValue = [actualValue boolValue]; } @@ -37329,6 +37340,9 @@ - (void)testSendClusterTestSaveAs_000009_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedCharValue], 0); + } + { + id actualValue = value; readAttributeBitmap8DefaultValue = [actualValue unsignedCharValue]; } @@ -37449,6 +37463,9 @@ - (void)testSendClusterTestSaveAs_000014_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedShortValue], 0U); + } + { + id actualValue = value; readAttributeBitmap16DefaultValue = [actualValue unsignedShortValue]; } @@ -37569,6 +37586,9 @@ - (void)testSendClusterTestSaveAs_000019_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedIntValue], 0UL); + } + { + id actualValue = value; readAttributeBitmap32DefaultValue = [actualValue unsignedIntValue]; } @@ -37689,6 +37709,9 @@ - (void)testSendClusterTestSaveAs_000024_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedLongLongValue], 0ULL); + } + { + id actualValue = value; readAttributeBitmap64DefaultValue = [actualValue unsignedLongLongValue]; } @@ -37809,6 +37832,9 @@ - (void)testSendClusterTestSaveAs_000029_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedCharValue], 0); + } + { + id actualValue = value; readAttributeInt8uDefaultValue = [actualValue unsignedCharValue]; } @@ -37929,6 +37955,9 @@ - (void)testSendClusterTestSaveAs_000034_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedShortValue], 0U); + } + { + id actualValue = value; readAttributeInt16uDefaultValue = [actualValue unsignedShortValue]; } @@ -38049,6 +38078,9 @@ - (void)testSendClusterTestSaveAs_000039_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedIntValue], 0UL); + } + { + id actualValue = value; readAttributeInt32uDefaultValue = [actualValue unsignedIntValue]; } @@ -38169,6 +38201,9 @@ - (void)testSendClusterTestSaveAs_000044_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedLongLongValue], 0ULL); + } + { + id actualValue = value; readAttributeInt64uDefaultValue = [actualValue unsignedLongLongValue]; } @@ -38289,6 +38324,9 @@ - (void)testSendClusterTestSaveAs_000049_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue charValue], 0); + } + { + id actualValue = value; readAttributeInt8sDefaultValue = [actualValue charValue]; } @@ -38409,6 +38447,9 @@ - (void)testSendClusterTestSaveAs_000054_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue shortValue], 0); + } + { + id actualValue = value; readAttributeInt16sDefaultValue = [actualValue shortValue]; } @@ -38529,6 +38570,9 @@ - (void)testSendClusterTestSaveAs_000059_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue intValue], 0L); + } + { + id actualValue = value; readAttributeInt32sDefaultValue = [actualValue intValue]; } @@ -38649,6 +38693,9 @@ - (void)testSendClusterTestSaveAs_000064_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue longLongValue], 0LL); + } + { + id actualValue = value; readAttributeInt64sDefaultValue = [actualValue longLongValue]; } @@ -38769,6 +38816,9 @@ - (void)testSendClusterTestSaveAs_000069_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedCharValue], 0); + } + { + id actualValue = value; readAttributeEnum8DefaultValue = [actualValue unsignedCharValue]; } @@ -38889,6 +38939,9 @@ - (void)testSendClusterTestSaveAs_000074_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedShortValue], 0U); + } + { + id actualValue = value; readAttributeEnum16DefaultValue = [actualValue unsignedShortValue]; } @@ -39009,6 +39062,9 @@ - (void)testSendClusterTestSaveAs_000079_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedLongLongValue], 0ULL); + } + { + id actualValue = value; readAttributeEpochUSDefaultValue = [actualValue unsignedLongLongValue]; } @@ -39129,6 +39185,9 @@ - (void)testSendClusterTestSaveAs_000084_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedIntValue], 0UL); + } + { + id actualValue = value; readAttributeEpochSDefaultValue = [actualValue unsignedIntValue]; } @@ -39249,6 +39308,9 @@ - (void)testSendClusterTestSaveAs_000089_ReadAttribute { id actualValue = value; XCTAssertEqual([actualValue unsignedShortValue], 0U); + } + { + id actualValue = value; readAttributeVendorIdDefaultValue = [actualValue unsignedShortValue]; } @@ -39369,6 +39431,9 @@ - (void)testSendClusterTestSaveAs_000094_ReadAttribute { id actualValue = value; XCTAssertTrue([actualValue isEqualToString:@""]); + } + { + id actualValue = value; readAttributeCharStringDefaultValue = [NSMutableString stringWithString:actualValue]; } @@ -39442,7 +39507,6 @@ - (void)testSendClusterTestSaveAs_000097_ReadAttribute { id actualValue = value; XCTAssertTrue([actualValue isEqualToString:@"NotDefault"]); - readAttributeCharStringNotDefaultValue = [NSMutableString stringWithString:actualValue]; } { id actualValue = value; @@ -39450,6 +39514,10 @@ - (void)testSendClusterTestSaveAs_000097_ReadAttribute XCTAssertNotEqualObjects(actualValue, readAttributeCharStringDefaultValue); } } + { + id actualValue = value; + readAttributeCharStringNotDefaultValue = [NSMutableString stringWithString:actualValue]; + } [expectation fulfill]; }]; @@ -39575,6 +39643,9 @@ - (void)testSendClusterTestSaveAs_000102_ReadAttribute { id actualValue = value; XCTAssertTrue([actualValue isEqualToData:[[NSData alloc] initWithBytes:"" length:0]]); + } + { + id actualValue = value; readAttributeOctetStringDefaultValue = [NSMutableData dataWithData:actualValue]; } @@ -39648,7 +39719,6 @@ - (void)testSendClusterTestSaveAs_000105_ReadAttribute { id actualValue = value; XCTAssertTrue([actualValue isEqualToData:[[NSData alloc] initWithBytes:"NotDefault" length:10]]); - readAttributeOctetStringNotDefaultValue = [NSMutableData dataWithData:actualValue]; } { id actualValue = value; @@ -39656,6 +39726,10 @@ - (void)testSendClusterTestSaveAs_000105_ReadAttribute XCTAssertNotEqualObjects(actualValue, readAttributeOctetStringDefaultValue); } } + { + id actualValue = value; + readAttributeOctetStringNotDefaultValue = [NSMutableData dataWithData:actualValue]; + } [expectation fulfill]; }];