Skip to content

Commit

Permalink
Ensure that we Platform::MemoryInit before serializing payloads on Da…
Browse files Browse the repository at this point in the history
…rwin. (#26931)
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 1, 2023
1 parent e9107b8 commit 4af77d7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTRSetupPayload.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#import "MTRError.h"
#import "MTRError_Internal.h"
#import "MTRFramework.h"
#import "MTROnboardingPayloadParser.h"
#import "MTRSetupPayload_Internal.h"
#import "setup_payload/ManualSetupPayloadGenerator.h"
Expand All @@ -30,6 +31,13 @@ @implementation MTRSetupPayload {
chip::SetupPayload _chipSetupPayload;
}

+ (void)initialize
{
// Need to make sure we set up Platform memory stuff before we start
// serializing payloads.
MTRFrameworkInit();
}

- (MTRDiscoveryCapabilities)convertRendezvousFlags:(const chip::Optional<chip::RendezvousInformationFlags> &)value
{
if (!value.HasValue()) {
Expand Down
54 changes: 54 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRSetupPayloadSerializerTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// module headers
#import "MTRSetupPayload.h"

// additional includes
#import "MTRError.h"

// system dependencies
#import <XCTest/XCTest.h>

@interface MTRSetupPayloadSerializerTests : XCTestCase

@end

@implementation MTRSetupPayloadSerializerTests

- (void)testSetupPayloadBasicQRCodeSerialize
{
__auto_type * payload = [[MTRSetupPayload alloc] init];
XCTAssertNotNil(payload);

payload.version = @(0);
payload.vendorID = @(0xFFF1);
payload.productID = @(1);
payload.commissioningFlow = MTRCommissioningFlowStandard;
payload.discoveryCapabilities = MTRDiscoveryCapabilitiesOnNetwork;
payload.discriminator = @(0xabc);
payload.hasShortDiscriminator = NO;
payload.setupPasscode = @(12121212);

NSError * error;
__auto_type * qrCode = [payload qrCodeString:&error];
XCTAssertNil(error);
XCTAssertNotNil(qrCode);
XCTAssertEqualObjects(qrCode, @"MT:-24J06.H14BK9C7R900");
}

// Make sure to not add any tests that involve parsing setup payloads to this
// file. Those should go in MTRSetupPayloadParserTests.m.
@end
4 changes: 4 additions & 0 deletions src/darwin/Framework/Matter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
517BF3F0282B62B800A8B7DB /* MTRCertificates.h in Headers */ = {isa = PBXBuildFile; fileRef = 517BF3EE282B62B800A8B7DB /* MTRCertificates.h */; settings = {ATTRIBUTES = (Public, ); }; };
517BF3F1282B62B800A8B7DB /* MTRCertificates.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517BF3EF282B62B800A8B7DB /* MTRCertificates.mm */; };
517BF3F3282B62CB00A8B7DB /* MTRCertificateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 517BF3F2282B62CB00A8B7DB /* MTRCertificateTests.m */; };
519498322A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */; };
51A2F1322A00402A00F03298 /* MTRDataValueParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */; };
51B22C1E2740CB0A008D5055 /* MTRStructsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C1D2740CB0A008D5055 /* MTRStructsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
51B22C222740CB1D008D5055 /* MTRCommandPayloadsObjc.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B22C212740CB1D008D5055 /* MTRCommandPayloadsObjc.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -445,6 +446,7 @@
517BF3EE282B62B800A8B7DB /* MTRCertificates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRCertificates.h; sourceTree = "<group>"; };
517BF3EF282B62B800A8B7DB /* MTRCertificates.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRCertificates.mm; sourceTree = "<group>"; };
517BF3F2282B62CB00A8B7DB /* MTRCertificateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRCertificateTests.m; sourceTree = "<group>"; };
519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRSetupPayloadSerializerTests.m; sourceTree = "<group>"; };
51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTRDataValueParserTests.m; sourceTree = "<group>"; };
51B22C1D2740CB0A008D5055 /* MTRStructsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRStructsObjc.h; sourceTree = "<group>"; };
51B22C212740CB1D008D5055 /* MTRCommandPayloadsObjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRCommandPayloadsObjc.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1071,6 +1073,7 @@
5142E39729D377F000A206F0 /* MTROTAProviderTests.m */,
51A2F1312A00402A00F03298 /* MTRDataValueParserTests.m */,
51339B1E2A0DA64D00C798C1 /* MTRCertificateValidityTests.m */,
519498312A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m */,
B202529D2459E34F00F97062 /* Info.plist */,
);
path = CHIPTests;
Expand Down Expand Up @@ -1483,6 +1486,7 @@
517BF3F3282B62CB00A8B7DB /* MTRCertificateTests.m in Sources */,
5142E39829D377F000A206F0 /* MTROTAProviderTests.m in Sources */,
51E24E73274E0DAC007CCF6E /* MTRErrorTestUtils.mm in Sources */,
519498322A25581C00B3BABE /* MTRSetupPayloadSerializerTests.m in Sources */,
51A2F1322A00402A00F03298 /* MTRDataValueParserTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down

0 comments on commit 4af77d7

Please sign in to comment.