Skip to content

Commit 4766354

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Ensure that we Platform::MemoryInit before serializing payloads on Darwin. (#26931)
1 parent b212271 commit 4766354

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/darwin/Framework/CHIP/MTRSetupPayload.mm

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#import "MTRError.h"
1919
#import "MTRError_Internal.h"
20+
#import "MTRFramework.h"
2021
#import "MTROnboardingPayloadParser.h"
2122
#import "MTRSetupPayload_Internal.h"
2223
#import "setup_payload/ManualSetupPayloadGenerator.h"
@@ -30,6 +31,13 @@ @implementation MTRSetupPayload {
3031
chip::SetupPayload _chipSetupPayload;
3132
}
3233

34+
+ (void)initialize
35+
{
36+
// Need to make sure we set up Platform memory stuff before we start
37+
// serializing payloads.
38+
MTRFrameworkInit();
39+
}
40+
3341
- (MTRDiscoveryCapabilities)convertRendezvousFlags:(const chip::Optional<chip::RendezvousInformationFlags> &)value
3442
{
3543
if (!value.HasValue()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (c) 2023 Project CHIP Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// module headers
17+
#import "MTRSetupPayload.h"
18+
19+
// additional includes
20+
#import "MTRError.h"
21+
22+
// system dependencies
23+
#import <XCTest/XCTest.h>
24+
25+
@interface MTRSetupPayloadSerializerTests : XCTestCase
26+
27+
@end
28+
29+
@implementation MTRSetupPayloadSerializerTests
30+
31+
- (void)testSetupPayloadBasicQRCodeSerialize
32+
{
33+
__auto_type * payload = [[MTRSetupPayload alloc] init];
34+
XCTAssertNotNil(payload);
35+
36+
payload.version = @(0);
37+
payload.vendorID = @(0xFFF1);
38+
payload.productID = @(1);
39+
payload.commissioningFlow = MTRCommissioningFlowStandard;
40+
payload.discoveryCapabilities = MTRDiscoveryCapabilitiesOnNetwork;
41+
payload.discriminator = @(0xabc);
42+
payload.hasShortDiscriminator = NO;
43+
payload.setupPasscode = @(12121212);
44+
45+
NSError * error;
46+
__auto_type * qrCode = [payload qrCodeString:&error];
47+
XCTAssertNil(error);
48+
XCTAssertNotNil(qrCode);
49+
XCTAssertEqualObjects(qrCode, @"MT:-24J06.H14BK9C7R900");
50+
}
51+
52+
// Make sure to not add any tests that involve parsing setup payloads to this
53+
// file. Those should go in MTRSetupPayloadParserTests.m.
54+
@end

src/darwin/Framework/Matter.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
517BF3F0282B62B800A8B7DB /* MTRCertificates.h in Headers */ = {isa = PBXBuildFile; fileRef = 517BF3EE282B62B800A8B7DB /* MTRCertificates.h */; settings = {ATTRIBUTES = (Public, ); }; };
156156
517BF3F1282B62B800A8B7DB /* MTRCertificates.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517BF3EF282B62B800A8B7DB /* MTRCertificates.mm */; };
157157
517BF3F3282B62CB00A8B7DB /* MTRCertificateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 517BF3F2282B62CB00A8B7DB /* MTRCertificateTests.m */; };
158+
519498322A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */; };
158159
51A2F1322A00402A00F03298 /* MTRDataValueParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */; };
159160
51B22C1E2740CB0A008D5055 /* MTRStructsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C1D2740CB0A008D5055 /* MTRStructsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
160161
51B22C222740CB1D008D5055 /* MTRCommandPayloadsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C212740CB1D008D5055 /* MTRCommandPayloadsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -445,6 +446,7 @@
445446
517BF3EE282B62B800A8B7DB /* MTRCertificates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRCertificates.h; sourceTree = "<group>"; };
446447
517BF3EF282B62B800A8B7DB /* MTRCertificates.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRCertificates.mm; sourceTree = "<group>"; };
447448
517BF3F2282B62CB00A8B7DB /* MTRCertificateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRCertificateTests.m; sourceTree = "<group>"; };
449+
519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRSetupPayloadSerializerTests.m; sourceTree = "<group>"; };
448450
51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRDataValueParserTests.m; sourceTree = "<group>"; };
449451
51B22C1D2740CB0A008D5055 /* MTRStructsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRStructsObjc.h; sourceTree = "<group>"; };
450452
51B22C212740CB1D008D5055 /* MTRCommandPayloadsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRCommandPayloadsObjc.h; sourceTree = "<group>"; };
@@ -1071,6 +1073,7 @@
10711073
5142E39729D377F000A206F0 /* MTROTAProviderTests.m */,
10721074
51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */,
10731075
51339B1E2A0DA64D00C798C1 /* MTRCertificateValidityTests.m */,
1076+
519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */,
10741077
B202529D2459E34F00F97062 /* Info.plist */,
10751078
);
10761079
path = CHIPTests;
@@ -1483,6 +1486,7 @@
14831486
517BF3F3282B62CB00A8B7DB /* MTRCertificateTests.m in Sources */,
14841487
5142E39829D377F000A206F0 /* MTROTAProviderTests.m in Sources */,
14851488
51E24E73274E0DAC007CCF6E /* MTRErrorTestUtils.mm in Sources */,
1489+
519498322A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m in Sources */,
14861490
51A2F1322A00402A00F03298 /* MTRDataValueParserTests.m in Sources */,
14871491
);
14881492
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)