Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -1,12 +1,17 @@ +include ../extra.mk + +SUBDIRS = ${TESTPLUGIN} + PROG_NOINST = tests${PROG_SUFFIX} SRCS = OFNumberTests.m \ OFPBKDF2Tests.m \ - OFPropertyListTests.m + OFPropertyListTests.m \ + ${USE_SRCS_PLUGINS} +SRCS_PLUGINS = OFPluginTests.m include ../buildsys.mk -include ../extra.mk .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} ADDED new_tests/OFPluginTests.m Index: new_tests/OFPluginTests.m ================================================================== --- new_tests/OFPluginTests.m +++ new_tests/OFPluginTests.m @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +#import "plugin/TestPlugin.h" + +@interface OFPluginTests: OTTestCase +@end + +@implementation OFPluginTests +- (void)testPlugin +{ + OFString *path; + OFPlugin *plugin; + Class (*class)(void); + TestPlugin *test; + +#ifndef OF_IOS + path = [OFPlugin pathForName: @"plugin/TestPlugin"]; +#else + path = [OFPlugin pathForName: @"PlugIns/TestPlugin"]; +#endif + OTAssertNotNil(path); + + plugin = [OFPlugin pluginWithPath: path]; + OTAssertNotNil(plugin); + + class = (Class (*)(void))(uintptr_t)[plugin addressForSymbol: @"class"]; + OTAssert(class != NULL); + + @try { + test = [[class() alloc] init]; + OTAssertEqual([test test: 1234], 2468); + } @finally { + [test release]; + } +} +@end ADDED new_tests/plugin/Info.plist.in Index: new_tests/plugin/Info.plist.in ================================================================== --- new_tests/plugin/Info.plist.in +++ new_tests/plugin/Info.plist.in @@ -0,0 +1,22 @@ + + + + + CFBundleExecutable + TestPlugin + CFBundleName + TestPlugin + CFBundleIdentifier + im.nil.objfw.tests.plugin + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleVersion + @BUNDLE_VERSION@ + CFBundleShortVersionString + @BUNDLE_SHORT_VERSION@ + MinimumOSVersion + 9.0 + + ADDED new_tests/plugin/Makefile Index: new_tests/plugin/Makefile ================================================================== --- new_tests/plugin/Makefile +++ new_tests/plugin/Makefile @@ -0,0 +1,11 @@ +DISTCLEAN = Info.plist + +PLUGIN_NOINST = TestPlugin${PLUGIN_SUFFIX} +SRCS = TestPlugin.m + +include ../../buildsys.mk +include ../../extra.mk + +CPPFLAGS += -I../.. -I../../src -I../../src/runtime +LIBS := ${TESTPLUGIN_LIBS} ${LIBS} +LD = ${OBJC} ADDED new_tests/plugin/TestPlugin.h Index: new_tests/plugin/TestPlugin.h ================================================================== --- new_tests/plugin/TestPlugin.h +++ new_tests/plugin/TestPlugin.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFObject.h" + +@interface TestPlugin: OFObject +- (int)test: (int)num; +@end ADDED new_tests/plugin/TestPlugin.m Index: new_tests/plugin/TestPlugin.m ================================================================== --- new_tests/plugin/TestPlugin.m +++ new_tests/plugin/TestPlugin.m @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "TestPlugin.h" + +#ifdef OF_OBJFW_RUNTIME +# import "runtime/private.h" + +OF_DESTRUCTOR() +{ + Class class = objc_getClass("TestPlugin"); + + if (class == Nil) + /* + * musl has broken dlclose(): Instead of calling the destructor + * on dlclose(), they call it on exit(). This of course means + * that our tests might have already called objc_deinit() and + * the class is already gone. + */ + return; + + objc_unregisterClass(class); +} +#endif + +@implementation TestPlugin +- (int)test: (int)num +{ + return num * 2; +} +@end + +Class +class(void) +{ + return [TestPlugin class]; +} Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,9 +1,8 @@ include ../extra.mk -SUBDIRS = ${TESTPLUGIN} \ - ${OBJC_SYNC} \ +SUBDIRS = ${OBJC_SYNC} \ ${SUBPROCESS} \ terminal CLEAN = EBOOT.PBP \ boot.dol \ @@ -55,18 +54,16 @@ OFXMLParserTests.m \ RuntimeTests.m \ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ - ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} \ testfile_bin.m \ testfile_ini.m -SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ @@ -151,28 +148,10 @@ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT -run-on-ios: all - if [ -z "${IOS_HOST}" ]; then \ - echo "Please set IOS_HOST to the hostname of your iOS host!"; \ - exit 1; \ - fi - echo "Uploading files to iOS device ${IOS_HOST} at ${IOS_TMP}..." - ssh ${IOS_USER}@${IOS_HOST} \ - 'rm -fr ${IOS_TMP} && mkdir -p ${IOS_TMP}/plugin' - destname=libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ - scp -q ../src/libobjfw.dylib \ - ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/$$destname - scp -q tests testfile.txt ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/ - scp -q plugin/TestPlugin.bundle \ - ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/plugin/ - echo "Running tests binary on iOS device ${IOS_HOST}..." - ssh ${IOS_USER}@${IOS_HOST} \ - 'cd ${IOS_TMP} && DYLD_LIBRARY_PATH=. ${WRAPPER} ./tests' - run-on-android: all echo "Uploading files to Android device..." if test -f ../src/libobjfw.so; then \ adb push ../src/libobjfw.so \ /data/local/tmp/objfw/libobjfw.so.${OBJFW_LIB_MAJOR}; \ @@ -181,14 +160,10 @@ adb push ../src/runtime/libobjfwrt.so \ /data/local/tmp/objfw/libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ fi adb push tests /data/local/tmp/objfw/tests adb push testfile.txt /data/local/tmp/objfw/testfile.txt - if test -f plugin/TestPlugin.so; then \ - adb push plugin/TestPlugin.so \ - /data/local/tmp/objfw/plugin/TestPlugin.so; \ - fi echo "Running tests binary on Android device..." adb shell 'cd /data/local/tmp/objfw && LD_LIBRARY_PATH=. exec ${WRAPPER} ./tests' EBOOT.PBP: ${PROG_NOINST} psp-fixup-imports ${PROG_NOINST} DELETED tests/OFPluginTests.m Index: tests/OFPluginTests.m ================================================================== --- tests/OFPluginTests.m +++ tests/OFPluginTests.m @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -#import "plugin/TestPlugin.h" - -#ifndef OF_IOS -static OFString *const pluginName = @"plugin/TestPlugin"; -#else -static OFString *const pluginName = @"PlugIns/TestPlugin"; -#endif - -static OFString *const module = @"OFPlugin"; - -@implementation TestsAppDelegate (OFPluginTests) -- (void)pluginTests -{ - void *pool = objc_autoreleasePoolPush(); - OFString *path; - OFPlugin *plugin; - Class (*class)(void); - TestPlugin *test; - - TEST(@"+[pathForName:]", (path = [OFPlugin pathForName: pluginName])) - - TEST(@"+[pluginWithPath:]", (plugin = [OFPlugin pluginWithPath: path])) - - TEST(@"-[addressForSymbol:]", - (class = (Class (*)(void))(uintptr_t) - [plugin addressForSymbol: @"class"])) - - test = [[class() alloc] init]; - @try { - TEST(@"TestPlugin's -[test:]", [test test: 1234] == 2468) - } @finally { - [test release]; - } - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/plugin/Info.plist.in Index: tests/plugin/Info.plist.in ================================================================== --- tests/plugin/Info.plist.in +++ tests/plugin/Info.plist.in @@ -1,22 +0,0 @@ - - - - - CFBundleExecutable - TestPlugin - CFBundleName - TestPlugin - CFBundleIdentifier - im.nil.objfw.tests.plugin - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleVersion - @BUNDLE_VERSION@ - CFBundleShortVersionString - @BUNDLE_SHORT_VERSION@ - MinimumOSVersion - 9.0 - - DELETED tests/plugin/Makefile Index: tests/plugin/Makefile ================================================================== --- tests/plugin/Makefile +++ tests/plugin/Makefile @@ -1,11 +0,0 @@ -DISTCLEAN = Info.plist - -PLUGIN_NOINST = TestPlugin${PLUGIN_SUFFIX} -SRCS = TestPlugin.m - -include ../../buildsys.mk -include ../../extra.mk - -CPPFLAGS += -I../.. -I../../src -I../../src/runtime -LIBS := ${TESTPLUGIN_LIBS} ${LIBS} -LD = ${OBJC} DELETED tests/plugin/TestPlugin.h Index: tests/plugin/TestPlugin.h ================================================================== --- tests/plugin/TestPlugin.h +++ tests/plugin/TestPlugin.h @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFObject.h" - -@interface TestPlugin: OFObject -- (int)test: (int)num; -@end DELETED tests/plugin/TestPlugin.m Index: tests/plugin/TestPlugin.m ================================================================== --- tests/plugin/TestPlugin.m +++ tests/plugin/TestPlugin.m @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestPlugin.h" - -#ifdef OF_OBJFW_RUNTIME -# import "runtime/private.h" - -OF_DESTRUCTOR() -{ - Class class = objc_getClass("TestPlugin"); - - if (class == Nil) - /* - * musl has broken dlclose(): Instead of calling the destructor - * on dlclose(), they call it on exit(). This of course means - * that our tests might have already called objc_deinit() and - * the class is already gone. - */ - return; - - objc_unregisterClass(class); -} -#endif - -@implementation TestPlugin -- (int)test: (int)num -{ - return num * 2; -} -@end - -Class -class(void) -{ - return [TestPlugin class]; -}