From d1336543d8271fc5ca00c83c81833e9a28c241ca Mon Sep 17 00:00:00 2001 From: theraven Date: Wed, 9 Jan 2013 19:00:17 +0000 Subject: [PATCH] Build with exceptions (fixes the issue with crashes where +initialize throws) Start adding the tests to CMake. --- CMakeLists.txt | 5 +++-- Test/BlockImpTest.m | 5 +++++ Test/CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++ Test/PropertyIntrospectionTest.m | 5 +++++ Test/objc_msgSend.m | 13 ++++++++----- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 Test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 917bfdd..217f84f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}") set(libobjc_VERSION 4.6) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions") # Build configuration add_definitions( -DGNUSTEP -D__OBJC_RUNTIME_INTERNAL__=1) # Probably not needed anymore? @@ -291,6 +292,6 @@ configure_file( add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -#enable_testing() -#add_subdirectory(Test) +enable_testing() +add_subdirectory(Test) diff --git a/Test/BlockImpTest.m b/Test/BlockImpTest.m index f43a040..832236d 100644 --- a/Test/BlockImpTest.m +++ b/Test/BlockImpTest.m @@ -9,6 +9,11 @@ struct big int a, b, c, d, e; }; +#ifdef __has_attribute +#if __has_attribute(objc_root_class) +__attribute__((objc_root_class)) +#endif +#endif @interface Foo @end @implementation Foo @end @interface Foo (Dynamic) diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt new file mode 100644 index 0000000..4525eaa --- /dev/null +++ b/Test/CMakeLists.txt @@ -0,0 +1,32 @@ + +# Clear the LD_LIBRARY_PATH if GNUstep set it so that we don't accidentally use +# the installed version + + +set(TESTS + objc_msgSend.m + BlockImpTest.m + PropertyIntrospectionTest.m + ProtocolCreation.m +) + +#ExceptionTest.m +#PropertyAttributeTest.m +#RuntimeTest.m +foreach(TEST_SOURCE ${TESTS}) + get_filename_component(TEST ${TEST_SOURCE} NAME_WE) + add_executable(${TEST} ${TEST_SOURCE}) + add_test(${TEST} ${TEST}) + set_target_properties(${TEST} PROPERTIES + INCLUDE_DIRECTORIES ".." + COMPILE_FLAGS "-fobjc-runtime=gnustep-1.6 -fblocks" + LANGUAGE C + LINKER_LANGUAGE C + ) + set_property(TEST ${TEST} PROPERTY + ENVIRONMENT "LD_LIBRARY_PATH=" + ) + target_link_libraries(${TEST} objc) +endforeach() + + diff --git a/Test/PropertyIntrospectionTest.m b/Test/PropertyIntrospectionTest.m index bcf82b7..2a244f4 100644 --- a/Test/PropertyIntrospectionTest.m +++ b/Test/PropertyIntrospectionTest.m @@ -3,6 +3,11 @@ #include #include +#ifdef __has_attribute +#if __has_attribute(objc_root_class) +__attribute__((objc_root_class)) +#endif +#endif @interface Foo @property (getter=bar, setter=setBar:, nonatomic, copy) id foo; @end diff --git a/Test/objc_msgSend.m b/Test/objc_msgSend.m index ff179cd..3ef5d9c 100644 --- a/Test/objc_msgSend.m +++ b/Test/objc_msgSend.m @@ -1,17 +1,15 @@ #include #include -#include #include #include -#include #include +#include "objc/runtime.h" //#define assert(x) if (!(x)) { printf("Failed %d\n", __LINE__); } id objc_msgSend(id, SEL, ...); typedef struct { int a,b,c,d,e; } s; -s objc_msgSend_stret(id, SEL, ...); @interface Fake - (int)izero; - (float)fzero; @@ -20,6 +18,11 @@ s objc_msgSend_stret(id, SEL, ...); @end Class TestCls; +#ifdef __has_attribute +#if __has_attribute(objc_root_class) +__attribute__((objc_root_class)) +#endif +#endif @interface Test { id isa; }@end @implementation Test - foo @@ -90,7 +93,7 @@ int main(void) assert(objc_registerSmallObjectClass_np(objc_getClass("Test"), 1)); a = objc_msgSend((id)01, @selector(foo)); assert((id)0x42 == a); - s ret = objc_msgSend_stret(TestCls, @selector(sret)); + s ret = ((s(*)(id, SEL))objc_msgSend_stret)(TestCls, @selector(sret)); assert(ret.a == 1); assert(ret.b == 2); assert(ret.c == 3); @@ -99,7 +102,7 @@ int main(void) if (sizeof(id) == 8) { assert(objc_registerSmallObjectClass_np(objc_getClass("Test"), 3)); - ret = objc_msgSend_stret((id)3, @selector(sret)); + ret = ((s(*)(id, SEL))objc_msgSend_stret)((id)3, @selector(sret)); assert(ret.a == 1); assert(ret.b == 2); assert(ret.c == 3);