diff --git a/BUILD b/BUILD index b2229a1..c9ab8fc 100644 --- a/BUILD +++ b/BUILD @@ -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", ], ) diff --git a/MOLXPCConnection.podspec b/MOLXPCConnection.podspec index 45b8f92..6d54a25 100644 --- a/MOLXPCConnection.podspec +++ b/MOLXPCConnection.podspec @@ -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' => 'macops-external@google.com' } @@ -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 diff --git a/Source/MOLXPCConnection/MOLXPCConnection.h b/Source/MOLXPCConnection/MOLXPCConnection.h index 59a2d85..7e043d1 100644 --- a/Source/MOLXPCConnection/MOLXPCConnection.h +++ b/Source/MOLXPCConnection/MOLXPCConnection.h @@ -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) diff --git a/Tests/MOLXPCConnectionTests.m b/Tests/MOLXPCConnectionTests.m index c5951f2..09beafe 100644 --- a/Tests/MOLXPCConnectionTests.m +++ b/Tests/MOLXPCConnectionTests.m @@ -25,8 +25,30 @@ @interface MOLXPCConnectionTest : XCTestCase @protocol DummyXPCProtocol @end +@protocol DeepThoughtProtocol +- (void)theAnswerToLifeTheUniverseAndEverything:(void(^)(int))reply; +@end + +@interface DeepThought : NSObject +@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]); } @@ -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