From 8b6793aa52d2034ae5ce1851c7e13853390fbb00 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Tue, 20 Mar 2018 15:23:40 +0000 Subject: [PATCH] Add a test for forward declared protocols. Check that a protocol accessed by forward definition in one compilation unit is the one defined in another compilation unit. --- Test/CMakeLists.txt | 1 + Test/ForwardDeclareProtocol.m | 6 ++++++ Test/ForwardDeclareProtocolAccess.m | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 Test/ForwardDeclareProtocol.m create mode 100644 Test/ForwardDeclareProtocolAccess.m diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index d938432..64e644c 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -104,6 +104,7 @@ endforeach() # Tests that are more than a single file. addtest_variants("CXXExceptions" "CXXException.m;CXXException.cc" true) +addtest_variants("ForwardDeclareProtocolAccess" "ForwardDeclareProtocolAccess.m;ForwardDeclareProtocol.m" true) if (ENABLE_OBJCXX) addtest_variants(ObjCXXEHInterop "ObjCXXEHInterop.mm;ObjCXXEHInterop.m" true) endif() diff --git a/Test/ForwardDeclareProtocol.m b/Test/ForwardDeclareProtocol.m new file mode 100644 index 0000000..89a7f6f --- /dev/null +++ b/Test/ForwardDeclareProtocol.m @@ -0,0 +1,6 @@ +@protocol P; + +Protocol *getProtocol(void) +{ + return @protocol(P); +} diff --git a/Test/ForwardDeclareProtocolAccess.m b/Test/ForwardDeclareProtocolAccess.m new file mode 100644 index 0000000..f8da5e5 --- /dev/null +++ b/Test/ForwardDeclareProtocolAccess.m @@ -0,0 +1,17 @@ +#include "Test.h" + +@protocol P +- (void)someMethod; +@end + +// Defined in another compilation unit. Returns @protocol(P). +Protocol *getProtocol(void); + +int main(void) +{ + //Protocol *p1 = @protocol(P); + Protocol *p2 = getProtocol(); + //assert(protocol_isEqual(p1, p2)); + //assert(p1 == p2); + return 0; +}