Skip to content

Commit 8fb201d

Browse files
committedMar 15, 2023
Add Objective-C test
1 parent b62ab9e commit 8fb201d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
 

‎test/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ include(CTest)
33
add_executable(versionCheck versionCheck.c)
44
target_link_libraries(versionCheck PRIVATE macrOS)
55
add_test(NAME versionCheck COMMAND versionCheck)
6+
7+
add_executable(objcTest objcTest.c)
8+
target_link_libraries(objcTest PRIVATE macrOS)
9+
add_test(NAME objcTest COMMAND objcTest)

‎test/objcTest.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <macrOS/macrOSObjC.h>
2+
#include <stdlib.h>
3+
4+
#define CORRECT_VAL 1234
5+
6+
int returnVal(id self, SEL sel) {
7+
return CORRECT_VAL;
8+
}
9+
10+
int main(int argc, char** argv) {
11+
initObjCRuntime();
12+
/* Create an Objective-C class */
13+
Class TestClass = makeClass("TestClass", "NSObject");
14+
/* Add a method to the class */
15+
addMethod(TestClass, "returnVal:", returnVal, "i@:");
16+
/* Register the class */
17+
finaliseClass(TestClass);
18+
/* Create an instance of the class */
19+
id testClassInstance = objc_alloc_init(TestClass);
20+
/* Call a method */
21+
int returnedValue = objc_msgSend_t(int)(testClassInstance, sel("returnVal:"));
22+
/* Release the instance */
23+
objc_msgSend_id(testClassInstance, sel("release"));
24+
/* Check the return value */
25+
return (returnedValue == CORRECT_VAL) ? EXIT_SUCCESS : EXIT_FAILURE;
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.