19
19
#import < Matter/Matter.h>
20
20
21
21
#import " MTRErrorTestUtils.h"
22
+ #import " MTRTestCase.h"
22
23
#import " MTRTestKeys.h"
23
- #import " MTRTestResetCommissioneeHelper .h"
24
+ #import " MTRTestServerAppRunner .h"
24
25
#import " MTRTestStorage.h"
25
26
26
- // system dependencies
27
- #import < XCTest/XCTest.h>
28
-
29
- // Fixture: chip-all-clusters-app --KVS "$(mktemp -t chip-test-kvs)" --interface-id -1 \
30
- --dac_provider credentials/development/commissioner_dut/struct_cd_origin_pid_vid_correct/test_case_vector.json \
31
- --product-id 32768 --discriminator 3839
32
- // For manual testing, CASE retry code paths can be tested by adding --faults chip_CASEServerBusy_f1 (or similar)
33
-
34
27
static const uint16_t kPairingTimeoutInSeconds = 10 ;
35
28
static const uint16_t kTimeoutInSeconds = 3 ;
36
29
static uint64_t sDeviceId = 100000000 ;
@@ -138,14 +131,16 @@ - (void)controller:(MTRDeviceController *)controller commissioningComplete:(NSEr
138
131
139
132
@end
140
133
141
- @interface MTRPairingTests : XCTestCase
134
+ @interface MTRPairingTests : MTRTestCase
142
135
@property (nullable ) MTRPairingTestControllerDelegate * controllerDelegate;
143
136
@end
144
137
145
138
@implementation MTRPairingTests
146
139
147
140
+ (void )setUp
148
141
{
142
+ [super setUp ];
143
+
149
144
__auto_type * factory = [MTRDeviceControllerFactory sharedInstance ];
150
145
XCTAssertNotNil (factory);
151
146
@@ -170,6 +165,8 @@ + (void)tearDown
170
165
sController = nil ;
171
166
172
167
[[MTRDeviceControllerFactory sharedInstance ] stopControllerFactory ];
168
+
169
+ [super tearDown ];
173
170
}
174
171
175
172
- (void )setUp
@@ -182,11 +179,37 @@ - (void)tearDown
182
179
{
183
180
[sController setDeviceControllerDelegate: (id _Nonnull) nil queue: dispatch_get_main_queue ()]; // TODO: do we need a clearDeviceControllerDelegate API?
184
181
self.controllerDelegate = nil ;
182
+
183
+ [super tearDown ];
184
+ }
185
+
186
+ - (void )startServerApp
187
+ {
188
+ // For manual testing, CASE retry code paths can be tested by adding --faults chip_CASEServerBusy_f1 (or similar)
189
+ __auto_type * appRunner = [[MTRTestServerAppRunner alloc ] initWithAppName: @" all-clusters"
190
+ arguments: @[
191
+ @" --dac_provider" ,
192
+ [self absolutePathFor: @" credentials/development/commissioner_dut/struct_cd_origin_pid_vid_correct/test_case_vector.json" ],
193
+ @" --product-id" ,
194
+ @" 32768" ,
195
+ ]
196
+ payload: kOnboardingPayload
197
+ testcase: self ];
198
+ XCTAssertNotNil (appRunner);
185
199
}
186
200
187
201
// attestationDelegate and failSafeExtension can both be nil
188
202
- (void )doPairingTestWithAttestationDelegate : (id <MTRDeviceAttestationDelegate>)attestationDelegate failSafeExtension : (NSNumber *)failSafeExtension
189
203
{
204
+ [self doPairingTestWithAttestationDelegate: attestationDelegate failSafeExtension: failSafeExtension startServerApp: YES ];
205
+ }
206
+
207
+ - (void )doPairingTestWithAttestationDelegate : (id <MTRDeviceAttestationDelegate>)attestationDelegate failSafeExtension : (NSNumber *)failSafeExtension startServerApp : (BOOL )startServerApp
208
+ {
209
+ if (startServerApp) {
210
+ [self startServerApp ];
211
+ }
212
+
190
213
// Don't reuse node ids, because that will confuse us.
191
214
++sDeviceId ;
192
215
XCTestExpectation * expectation = [self expectationWithDescription: @" Commissioning Complete" ];
@@ -209,9 +232,6 @@ - (void)doPairingTestWithAttestationDelegate:(id<MTRDeviceAttestationDelegate>)a
209
232
210
233
[self waitForExpectations: @[ expectation ] timeout: kPairingTimeoutInSeconds ];
211
234
XCTAssertNil (controllerDelegate.commissioningCompleteError );
212
-
213
- ResetCommissionee ([MTRBaseDevice deviceWithNodeID: @(sDeviceId ) controller: sController ], dispatch_get_main_queue (), self,
214
- kTimeoutInSeconds );
215
235
}
216
236
217
237
- (void )test001_PairWithoutAttestationDelegate
@@ -297,6 +317,8 @@ - (void)doPairingAndWaitForProgress:(NSString *)trigger attestationDelegate:(nul
297
317
298
318
- (void )doPairingTestAfterCancellationAtProgress : (NSString *)trigger attestationDelegate : (nullable id <MTRDeviceAttestationDelegate>)attestationDelegate
299
319
{
320
+ [self startServerApp ];
321
+
300
322
// Run pairing up and wait for the trigger
301
323
[self doPairingAndWaitForProgress: trigger attestationDelegate: attestationDelegate];
302
324
@@ -314,7 +336,7 @@ - (void)doPairingTestAfterCancellationAtProgress:(NSString *)trigger attestation
314
336
XCTAssertEqual (error.code , MTRErrorCodeCancelled);
315
337
316
338
// Now pair again. If the previous attempt was cancelled correctly this should work fine.
317
- [self doPairingTestWithAttestationDelegate: nil failSafeExtension: nil ];
339
+ [self doPairingTestWithAttestationDelegate: nil failSafeExtension: nil startServerApp: NO ];
318
340
}
319
341
320
342
- (void )doPairingTestAfterCancellationAtProgress : (NSString *)trigger
0 commit comments