@@ -116,6 +116,8 @@ @interface MTRXPCProtocolTests<NSXPCListenerDelegate, CHIPRemoteDeviceProtocol>
116
116
@property (readwrite, strong) void (^handleReadClusterStateCache)
117
117
(id controller, NSNumber * nodeId, NSNumber * _Nullable endpointId, NSNumber * _Nullable clusterId,
118
118
NSNumber * _Nullable attributeId, void (^completion)(id _Nullable values, NSError * _Nullable error));
119
+ @property (readwrite, strong) void (^handleDownloadLog)(id controller, NSNumber * nodeId, MTRDiagnosticLogType type, NSTimeInterval timeout,
120
+ void (^completion)(NSString * _Nullable url, NSError * _Nullable error));
119
121
120
122
@end
121
123
@@ -274,6 +276,18 @@ - (void)readAttributeCacheWithController:(id _Nullable)controller
274
276
});
275
277
}
276
278
279
+ - (void)downloadLogWithController:(id)controller
280
+ nodeId:(NSNumber *)nodeId
281
+ type:(MTRDiagnosticLogType)type
282
+ timeout:(NSTimeInterval)timeout
283
+ completion:(void (^)(NSString * _Nullable url, NSError * _Nullable error))completion
284
+ {
285
+ dispatch_async(dispatch_get_main_queue(), ^{
286
+ XCTAssertNotNil(self.handleDownloadLog);
287
+ self.handleDownloadLog(controller, nodeId, type, timeout, completion);
288
+ });
289
+ }
290
+
277
291
- (void)setUp
278
292
{
279
293
[self setContinueAfterFailure:NO];
@@ -300,6 +314,44 @@ - (void)tearDown
300
314
_xpcDisconnectExpectation = nil;
301
315
}
302
316
317
+ - (void)testDownloadLogSuccess
318
+ {
319
+ uint64_t myNodeId = 9876543210;
320
+ NSString * myBdxURL = @"bdx://foo";
321
+ NSTimeInterval myTimeout = 10;
322
+
323
+ XCTestExpectation * callExpectation = [self expectationWithDescription:@"XPC call received"];
324
+ XCTestExpectation * responseExpectation = [self expectationWithDescription:@"XPC response received"];
325
+
326
+ __auto_type uuid = self.controllerUUID;
327
+ _handleDownloadLog = ^(id controller, NSNumber * nodeId, MTRDiagnosticLogType type, NSTimeInterval timeout,
328
+ void (^completion)(NSString * _Nullable url, NSError * _Nullable error)) {
329
+ XCTAssertTrue([controller isEqualToString:uuid]);
330
+ XCTAssertEqual([nodeId unsignedLongLongValue], myNodeId);
331
+ [callExpectation fulfill];
332
+ completion(myBdxURL, nil);
333
+ };
334
+
335
+ __auto_type * device = [MTRBaseDevice deviceWithNodeID:@(myNodeId) controller:_remoteDeviceController];
336
+ NSLog(@"Device acquired. Downloading...");
337
+ [device downloadLogOfType:MTRDiagnosticLogTypeEndUserSupport
338
+ timeout:myTimeout
339
+ queue:dispatch_get_main_queue()
340
+ completion:^(NSURL * _Nullable url, NSError * _Nullable error) {
341
+ NSLog(@"Read url: %@", url);
342
+ XCTAssertNotNil(url);
343
+ XCTAssertNil(error);
344
+ [responseExpectation fulfill];
345
+ self.xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"];
346
+ }];
347
+
348
+ [self waitForExpectations:[NSArray arrayWithObjects:callExpectation, responseExpectation, nil] timeout:kTimeoutInSeconds];
349
+
350
+ // When download is done, connection should have been released
351
+ [self waitForExpectations:[NSArray arrayWithObject:_xpcDisconnectExpectation] timeout:kTimeoutInSeconds];
352
+ XCTAssertNil(_xpcConnection);
353
+ }
354
+
303
355
- (void)testReadAttributeSuccess
304
356
{
305
357
uint64_t myNodeId = 9876543210;
0 commit comments