Skip to content

Commit

Permalink
Merge pull request #11 from google/sync
Browse files Browse the repository at this point in the history
add sync rop tests
  • Loading branch information
tburgin authored Aug 1, 2019
2 parents 7f09ac6 + d0bc2b1 commit 2c67c92
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
6 changes: 4 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ objc_library(
name = "MOLXPCConnection",
srcs = ["Source/MOLXPCConnection/MOLXPCConnection.m"],
hdrs = ["Source/MOLXPCConnection/MOLXPCConnection.h"],
copts = ["-Wunguarded-availability"],
includes = ["Source"],
sdk_frameworks = ["Security"],
deps = ["@MOLCodesignChecker//:MOLCodesignChecker"],
visibility = ["//visibility:public"],
deps = ["@MOLCodesignChecker"],
)

objc_library(
name = "MOLXPCConnectionTestsLib",
testonly = 1,
srcs = ["Tests/MOLXPCConnectionTests.m"],
copts = ["-Wunguarded-availability"],
deps = [
":MOLXPCConnection",
"@OCMock//:OCMock",
"@OCMock",
],
)

Expand Down
3 changes: 2 additions & 1 deletion MOLXPCConnection.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'MOLXPCConnection'
s.version = '2.1'
s.platform = :osx, '10.11'
s.platform = :osx, '10.9'
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
s.homepage = 'https://github.com/google/macops-molxpcconnection'
s.authors = { 'Google Macops' => '[email protected]' }
Expand All @@ -10,4 +10,5 @@ Pod::Spec.new do |s|
:tag => "v#{s.version}" }
s.source_files = 'Source/MOLXPCConnection/*.{h,m}'
s.dependency 'MOLCodesignChecker', '~> 2.2'
s.compiler_flags = '-Wunguarded-availability'
end
2 changes: 1 addition & 1 deletion Source/MOLXPCConnection/MOLXPCConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
@note If the connection to the server failed, this will be nil, so you can safely send messages
and rely on the invalidationHandler for handling the failure.
*/
@property(readonly, nonatomic, nullable) id synchronousRemoteObjectProxy;
@property(readonly, nonatomic, nullable) id synchronousRemoteObjectProxy API_AVAILABLE(macos(10.11));

/**
The privileged interface this object exports. (server)
Expand Down
39 changes: 39 additions & 0 deletions Tests/MOLXPCConnectionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,30 @@ @interface MOLXPCConnectionTest : XCTestCase
@protocol DummyXPCProtocol
@end

@protocol DeepThoughtProtocol
- (void)theAnswerToLifeTheUniverseAndEverything:(void(^)(int))reply;
@end

@interface DeepThought : NSObject<DeepThoughtProtocol>
@end

@implementation DeepThought
- (void)theAnswerToLifeTheUniverseAndEverything:(void(^)(int))reply {
reply(42);
}
@end

@implementation MOLXPCConnectionTest

- (NSXPCInterface *)deepThoughtInterface {
static NSXPCInterface *interface;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
interface = [NSXPCInterface interfaceWithProtocol:@protocol(DeepThoughtProtocol)];
});
return interface;
}

- (void)testPlainInit {
XCTAssertThrows([[MOLXPCConnection alloc] init]);
}
Expand Down Expand Up @@ -127,4 +149,21 @@ - (void)testConnectionInterruption {
[self waitForExpectationsWithTimeout:1.0 handler:NULL];
}

- (void)testSynchronous {
NSXPCListener *listener = [NSXPCListener anonymousListener];
MOLXPCConnection *sutServer = [[MOLXPCConnection alloc] initServerWithListener:listener];
sutServer.unprivilegedInterface = [self deepThoughtInterface];
sutServer.exportedObject = [[DeepThought alloc] init];
[sutServer resume];

__block int answer = 0;
MOLXPCConnection *sutClient = [[MOLXPCConnection alloc] initClientWithListener:listener.endpoint];
sutClient.remoteInterface = [self deepThoughtInterface];
[sutClient resume];
[[sutClient synchronousRemoteObjectProxy] theAnswerToLifeTheUniverseAndEverything:^(int reply) {
answer = reply;
}];
XCTAssertEqual(answer, 42);
}

@end

0 comments on commit 2c67c92

Please sign in to comment.