Skip to content

Commit

Permalink
Add support for octet-string-typed config variables in YAML. (#21699)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored Aug 9, 2022
1 parent 5d5b69e commit aec3d1d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{{else if (isCharString type)}}
chip::Span<const char>("{{chip_tests_config_get_default_value definedValue}}", {{utf8StringLength (chip_tests_config_get_default_value definedValue)}});
{{else if (isOctetString type)}}
{{!-- TODO Extract the length of the default value for ByteSpan--}}
{{> octetStringValue value=(chip_tests_config_get_default_value definedValue)}};
{{else}}
{{#if_is_strongly_typed_bitmap type}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{asTypedLiteral (chip_tests_config_get_default_value definedValue) type}});
Expand All @@ -60,11 +60,7 @@
{{else if (isCharString type)}}
chip::Span<const char>("{{definedValue}}garbage: not in length on purpose", {{utf8StringLength definedValue}});
{{else if (isOctetString type)}}
{{~#if (isHexString definedValue)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringFromHexString definedValue}}garbage: not in length on purpose"), {{octetStringLengthFromHexString definedValue}});
{{else}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringEscapedForCLiteral definedValue}}garbage: not in length on purpose"), {{definedValue.length}});
{{/if}}
{{> octetStringValue value=definedValue extraGarbage="garbage: not in length on purpose"}};
{{else}}
{{#if_is_strongly_typed_bitmap type}}
static_cast<{{zapTypeToEncodableClusterObjectType type ns=ns}}>({{asTypedLiteral definedValue type}});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if (isHexString value)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringFromHexString value}}{{extraGarbage}}"), {{octetStringLengthFromHexString value}})
{{else}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringEscapedForCLiteral value}}{{extraGarbage}}"), {{value.length}})
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@
{{~#if (chip_tests_variables_has expected)}}{{expected}}
{{else if keepAsExpected}}{{expected}}
{{else if (isOctetString type)}}
{{~#if (isHexString expected)}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringFromHexString expected}}"), {{octetStringLengthFromHexString expected}})
{{else}}
chip::ByteSpan(chip::Uint8::from_const_char("{{octetStringEscapedForCLiteral expected}}"), {{expected.length}})
{{/if}}
{{> octetStringValue value=expected}}
{{else if (isCharString type)}}chip::CharSpan("{{expected}}", {{utf8StringLength expected}})
{{else if (chip_tests_config_has expected)}}m{{asUpperCamelCase expected}}.HasValue() ? m{{asUpperCamelCase expected}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value expected) (chip_tests_config_get_type expected)}}
{{else}}{{asTypedExpression expected type}}
Expand Down
4 changes: 4 additions & 0 deletions examples/chip-tool/templates/tests/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
{
"name": "valueEquals",
"path": "partials/value_equals.zapt"
},
{
"name": "octetStringValue",
"path": "partials/octet_string_value.zapt"
}
],
"templates": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
VerifyOrReturn(CheckValue{{#if (isString type)}}AsString{{/if}}("{{label}}", {{actual}},
{{~#if (chip_tests_variables_has expected)}}{{expected}}
{{~else if (isOctetString type)}}
{{~#if (isHexString expected)}}
[[NSData alloc] initWithBytes:"{{octetStringFromHexString expected}}" length:{{octetStringLengthFromHexString expected}}]
{{else}}
[[NSData alloc] initWithBytes:"{{octetStringEscapedForCLiteral expected}}" length:{{expected.length}}]
{{/if}}
{{> octetStringValue value=expected}}
{{~else if (isCharString type)}}@"{{expected}}"
{{else if (chip_tests_config_has expected)}}m{{asUpperCamelCase expected}}.HasValue() ? m{{asUpperCamelCase expected}}.Value() : {{asTypedLiteral (chip_tests_config_get_default_value expected) (chip_tests_config_get_type expected)}}
{{~else}}{{asTypedExpressionFromObjectiveC expected type}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{~#if (isHexString value)}}
[[NSData alloc] initWithBytes:"{{octetStringFromHexString value}}" length:{{octetStringLengthFromHexString value}}]
{{else}}
[[NSData alloc] initWithBytes:"{{octetStringEscapedForCLiteral value}}" length:{{value.length}}]
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{#if (isCharString type)}}
m{{asUpperCamelCase definedValue}}.Value() : @"{{chip_tests_config_get_default_value definedValue}}";
{{else if (isOctetString type)}}
{{!-- TODO Extract the length of the default value for ByteSpan--}}
{{> octetStringValue value=(chip_tests_config_get_default_value definedValue)}};
{{else}}
[NSNumber numberWith{{asObjectiveCNumberType definedValue type false}}:m{{asUpperCamelCase definedValue}}.Value()] :
[NSNumber numberWith{{asObjectiveCNumberType definedValue type false}}:{{asTypedExpressionFromObjectiveC (chip_tests_config_get_default_value definedValue) type}}];
Expand All @@ -46,11 +46,7 @@
{{#if (isCharString type)}}
@"{{definedValue}}";
{{else if (isOctetString type)}}
{{~#if (isHexString definedValue)}}
[[NSData alloc] initWithBytes:"{{octetStringFromHexString definedValue}}" length:{{octetStringLengthFromHexString definedValue}}];
{{else}}
[[NSData alloc] initWithBytes:"{{octetStringEscapedForCLiteral definedValue}}" length:{{definedValue.length}}];
{{/if}}
{{> octetStringValue value=definedValue}};
{{else}}
[NSNumber numberWith{{asObjectiveCNumberType definedValue type false}}:{{asTypedExpressionFromObjectiveC definedValue type}}];
{{/if}}
Expand Down
4 changes: 4 additions & 0 deletions examples/darwin-framework-tool/templates/tests/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"name": "check_test_value",
"path": "partials/check_test_value.zapt"
},
{
"name": "octetStringValue",
"path": "partials/octet_string_value.zapt"
},
{
"name": "maybeCheckExpectedConstraints",
"path": "partials/checks/maybeCheckExpectedConstraints.zapt"
Expand Down

0 comments on commit aec3d1d

Please sign in to comment.