Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,8 +1,8 @@ include extra.mk -SUBDIRS = src utils tests new_tests +SUBDIRS = src utils new_tests DISTCLEAN = Info.plist \ aclocal.m4 \ autom4te.cache \ buildsys.mk \ config.h \ @@ -12,14 +12,13 @@ include buildsys.mk .PHONY: check docs release -utils tests new_tests: src +utils new_tests: src -check: tests new_tests - ${MAKE} -C tests -s run +check: new_tests ${MAKE} -C new_tests -s run docs: rm -fr docs doxygen >/dev/null DELETED tests/Makefile Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,138 +0,0 @@ -include ../extra.mk - -SUBDIRS = ${OBJC_SYNC} \ - terminal - -CLEAN = EBOOT.PBP \ - boot.dol \ - ${PROG_NOINST}.arm9 \ - ${PROG_NOINST}.nds \ - ${PROG_NOINST}.nro \ - ${PROG_NOINST}.rpx -DISTCLEAN = Info.plist - -PROG_NOINST = tests${PROG_SUFFIX} -STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} -SRCS = TestsAppDelegate.m - -IOS_USER ?= mobile -IOS_TMP ?= /tmp/objfw-test - -include ../buildsys.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} - rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib - rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} - rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} - rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll - rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib - if test -f ../src/libobjfw.so; then \ - ${LN_S} ../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ - ${LN_S} ../src/libobjfw.so \ - libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ - elif test -f ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ - ${LN_S} ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ - libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ - fi - if test -f ../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ - ${LN_S} ../src/objfw${OBJFW_LIB_MAJOR}.dll \ - objfw${OBJFW_LIB_MAJOR}.dll; \ - fi - if test -f ../src/libobjfw.dylib; then \ - ${LN_S} ../src/libobjfw.dylib \ - libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ - fi - if test -f ../src/runtime/libobjfwrt.so; then \ - ${LN_S} ../src/runtime/libobjfwrt.so \ - libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ - ${LN_S} ../src/runtime/libobjfwrt.so \ - libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ - elif test -f ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ - ${LN_S} ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ - fi - if test -f ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ - ${LN_S} ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ - objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ - fi - if test -f ../src/runtime/libobjfwrt.dylib; then \ - ${LN_S} ../src/runtime/libobjfwrt.dylib \ - libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ - fi - LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ - DYLD_FRAMEWORK_PATH=../src:../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ - DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ - LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ - ASAN_OPTIONS=allocator_may_return_null=1 \ - ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ - rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ - rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ - rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ - rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ - rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ - 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-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}; \ - fi - if test -f ../src/runtime/libobjfwrt.so; then \ - 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 - 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} - mksfo "ObjFW Tests" PARAM.SFO - psp-strip ${PROG_NOINST} - pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL ${PROG_NOINST} NULL - -boot.dol: ${PROG_NOINST} - elf2dol ${PROG_NOINST} $@ - -${PROG_NOINST}: ${LIBOBJFW_DEP} ${LIBOBJFWRT_DEP} - -${PROG_NOINST}.3dsx: ${PROG_NOINST} - 3dsxtool $< $@ - -${PROG_NOINST}.arm9: ${PROG_NOINST} - arm-none-eabi-objcopy -O binary $< $@ - -${PROG_NOINST}.nds: ${PROG_NOINST}.arm9 testfile.txt - rm -fr nds-data - mkdir -p nds-data - cp testfile.txt nds-data - ndstool -c $@ -9 ${PROG_NOINST} -d nds-data - rm -fr nds-data - -${PROG_NOINST}.nro: ${PROG_NOINST} testfile.txt - rm -fr romfs - mkdir -p romfs - cp testfile.txt romfs - nacptool --create "ObjFW tests" "Jonathan Schleifer" \ - "${PACKAGE_VERSION}" tests.nacp - elf2nro ${PROG_NOINST} $@ --nacp=tests.nacp --romfsdir=romfs - rm -fr romfs tests.nacp - -${PROG_NOINST}.rpx: ${PROG_NOINST} - elf2rpl $< $@ - -CPPFLAGS += -I../src \ - -I../src/exceptions \ - -I../src/runtime \ - -I.. \ - -DSTDOUT -LIBS := ${TESTS_LIBS} ${LIBS} -LDFLAGS += ${MAP_LDFLAGS} -LD = ${OBJC} DELETED tests/TestsAppDelegate.h Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -1,60 +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 "ObjFW.h" - -#define TEST(test, ...) \ - { \ - [self outputTesting: test inModule: module]; \ - \ - if (__VA_ARGS__) \ - [self outputSuccess: test inModule: module]; \ - else { \ - [self outputFailure: test inModule: module]; \ - _fails++; \ - } \ - } -#define EXPECT_EXCEPTION(test, exception, code) \ - { \ - bool caught = false; \ - \ - [self outputTesting: test inModule: module]; \ - \ - @try { \ - code; \ - } @catch (exception *e) { \ - caught = true; \ - } \ - \ - if (caught) \ - [self outputSuccess: test inModule: module]; \ - else { \ - [self outputFailure: test inModule: module]; \ - _fails++; \ - } \ - } -#define R(...) (__VA_ARGS__, 1) - -@class OFString; - -@interface TestsAppDelegate: OFObject -{ - int _fails; -} - -- (void)outputTesting: (OFString *)test inModule: (OFString *)module; -- (void)outputSuccess: (OFString *)test inModule: (OFString *)module; -- (void)outputFailure: (OFString *)test inModule: (OFString *)module; -@end DELETED tests/TestsAppDelegate.m Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -1,424 +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" - -#include - -#import "TestsAppDelegate.h" - -#ifdef OF_IOS -# include -#endif - -#ifdef OF_PSP -# include -# include -# include -# include -PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); -#endif - -#ifdef OF_WII -# define asm __asm__ -# include -# include -# undef asm -#endif - -#ifdef OF_NINTENDO_DS -# define asm __asm__ -# include -# undef asm -#endif - -#ifdef OF_NINTENDO_3DS -/* Newer versions of libctru started using id as a parameter name. */ -# define id id_3ds -# include <3ds.h> -# undef id -#endif - -#ifdef OF_NINTENDO_SWITCH -# define id nx_id -# include -# undef id - -static OFDate *lastConsoleUpdate; - -static void -updateConsole(bool force) -{ - if (force || lastConsoleUpdate.timeIntervalSinceNow <= -1.0 / 60) { - consoleUpdate(NULL); - [lastConsoleUpdate release]; - lastConsoleUpdate = [[OFDate alloc] init]; - } -} -#endif - -extern unsigned long OFHashSeed; - -#ifdef OF_PSP -static int -exitCallback(int arg1, int arg2, void *arg) -{ - sceKernelExitGame(); - - return 0; -} - -static int -threadCallback(SceSize args, void *argp) -{ - sceKernelRegisterExitCallback( - sceKernelCreateCallback("Exit Callback", exitCallback, NULL)); - sceKernelSleepThreadCB(); - - return 0; -} -#endif - -int -main(int argc, char *argv[]) -{ -#ifdef OF_PSP - int tid; -#endif - -#if defined(OF_OBJFW_RUNTIME) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) - /* - * This does not work on Win32 if ObjFW is built as a DLL. - * - * On AmigaOS, some destructors need to be able to send messages. - * Calling objc_deinit() via atexit() would result in the runtime being - * destructed before for the destructors ran. - */ - atexit(objc_deinit); -#endif - - /* We need deterministic hashes for tests */ - OFHashSeed = 0; - -#ifdef OF_WII - GXRModeObj *rmode; - void *xfb; - - VIDEO_Init(); - WPAD_Init(); - - rmode = VIDEO_GetPreferredMode(NULL); - xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); - VIDEO_Configure(rmode); - VIDEO_SetNextFramebuffer(xfb); - VIDEO_SetBlack(FALSE); - VIDEO_Flush(); - - VIDEO_WaitVSync(); - if (rmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); - - CON_InitEx(rmode, 10, 20, rmode->fbWidth - 10, rmode->xfbHeight - 20); - VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK); -#endif - -#ifdef OF_PSP - pspDebugScreenInit(); - - sceCtrlSetSamplingCycle(0); - sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); - - if ((tid = sceKernelCreateThread("update_thread", threadCallback, - 0x11, 0xFA0, 0, 0)) >= 0) - sceKernelStartThread(tid, 0, 0); -#endif - -#ifdef OF_NINTENDO_DS - consoleDemoInit(); -#endif - -#ifdef OF_NINTENDO_3DS - gfxInitDefault(); - atexit(gfxExit); - - consoleInit(GFX_TOP, NULL); -#endif - -#ifdef OF_NINTENDO_SWITCH - consoleInit(NULL); - padConfigureInput(1, HidNpadStyleSet_NpadStandard); - updateConsole(true); - -# ifdef OF_HAVE_FILES - [[OFFileManager defaultManager] changeCurrentDirectoryPath: @"romfs:/"]; -# endif -#endif - -#if defined(OF_WII) || defined(OF_WII_U) || defined(OF_PSP) || \ - defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \ - defined(OF_NINTENDO_SWITCH) - @try { - return OFApplicationMain(&argc, &argv, - [[TestsAppDelegate alloc] init]); - } @catch (id e) { - OFString *string = [OFString stringWithFormat: - @"\nRuntime error: Unhandled exception:\n%@\n", e]; - - [OFStdOut setForegroundColor: [OFColor red]]; - [OFStdOut writeString: string]; - - if ([e stackTraceAddresses] != nil) - [OFStdOut writeString: @"\nStack trace:\n"]; - - for (OFValue *address in [e stackTraceAddresses]) - [OFStdOut writeFormat: @" %p\n", address.pointerValue]; - -# if defined(OF_WII) - [OFStdOut reset]; - [OFStdOut writeString: @"Press home button to exit!"]; - - for (;;) { - WPAD_ScanPads(); - - if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) - [OFApplication terminateWithStatus: 1]; - - VIDEO_WaitVSync(); - } -# elif defined(OF_PSP) - sceKernelSleepThreadCB(); -# elif defined(OF_NINTENDO_DS) - [OFStdOut reset]; - [OFStdOut writeString: @"Press start button to exit!"]; - - for (;;) { - swiWaitForVBlank(); - scanKeys(); - if (keysDown() & KEY_START) - [OFApplication terminateWithStatus: 1]; - } -# elif defined(OF_NINTENDO_3DS) - [OFStdOut reset]; - [OFStdOut writeString: @"Press start button to exit!"]; - - for (;;) { - hidScanInput(); - - if (hidKeysDown() & KEY_START) - [OFApplication terminateWithStatus: 1]; - - gspWaitForVBlank(); - } -# elif defined(OF_NINTENDO_SWITCH) - while (appletMainLoop()) - updateConsole(true); - - consoleExit(NULL); - abort(); -# else - abort(); -# endif - } -#else - return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); -#endif -} - -@implementation TestsAppDelegate -- (void)outputTesting: (OFString *)test inModule: (OFString *)module -{ - if (OFStdOut.hasTerminal) { - [OFStdOut setForegroundColor: [OFColor yellow]]; - [OFStdOut writeFormat: @"[%@] %@: testing...", module, test]; - } else - [OFStdOut writeFormat: @"[%@] %@: ", module, test]; - -#ifdef OF_NINTENDO_SWITCH - updateConsole(false); -#endif -} - -- (void)outputSuccess: (OFString *)test inModule: (OFString *)module -{ - if (OFStdOut.hasTerminal) { - [OFStdOut setForegroundColor: [OFColor lime]]; - [OFStdOut eraseLine]; - [OFStdOut writeFormat: @"\r[%@] %@: ok\n", module, test]; - } else - [OFStdOut writeLine: @"ok"]; - -#ifdef OF_NINTENDO_SWITCH - updateConsole(false); -#endif -} - -- (void)outputFailure: (OFString *)test inModule: (OFString *)module -{ - if (OFStdOut.hasTerminal) { - [OFStdOut setForegroundColor: [OFColor red]]; - [OFStdOut eraseLine]; - [OFStdOut writeFormat: @"\r[%@] %@: failed\n", module, test]; - } else - [OFStdOut writeLine: @"failed"]; - -#ifdef OF_WII - [OFStdOut reset]; - [OFStdOut writeLine: @"Press A to continue!"]; - - for (;;) { - WPAD_ScanPads(); - - if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) - return; - - VIDEO_WaitVSync(); - } -#endif -#ifdef OF_PSP - [OFStdOut reset]; - [OFStdOut writeLine: @"Press X to continue!"]; - - for (;;) { - SceCtrlData pad; - - sceCtrlReadBufferPositive(&pad, 1); - if (pad.Buttons & PSP_CTRL_CROSS) { - for (;;) { - sceCtrlReadBufferPositive(&pad, 1); - if (!(pad.Buttons & PSP_CTRL_CROSS)) - return; - } - } - } -#endif -#ifdef OF_NINTENDO_DS - [OFStdOut reset]; - [OFStdOut writeString: @"Press A to continue!"]; - - for (;;) { - swiWaitForVBlank(); - scanKeys(); - if (keysDown() & KEY_A) - break; - } -#endif -#ifdef OF_NINTENDO_3DS - [OFStdOut reset]; - [OFStdOut writeString: @"Press A to continue!"]; - - for (;;) { - hidScanInput(); - - if (hidKeysDown() & KEY_A) - break; - - gspWaitForVBlank(); - } -#endif -#ifdef OF_NINTENDO_SWITCH - [OFStdOut reset]; - [OFStdOut writeString: @"Press A to continue!"]; - - while (appletMainLoop()) { - PadState pad; - - padUpdate(&pad); - updateConsole(true); - - if (padGetButtonsDown(&pad) & HidNpadButton_A) - break; - } -#endif - - if (OFStdOut.hasTerminal) { - [OFStdOut writeString: @"\r"]; - [OFStdOut reset]; - [OFStdOut eraseLine]; - } -} - -- (void)applicationDidFinishLaunching: (OFNotification *)notification -{ -#if defined(OF_IOS) && defined(OF_HAVE_FILES) - CFBundleRef mainBundle = CFBundleGetMainBundle(); - CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); - UInt8 resourcesPath[PATH_MAX]; - - if (!CFURLGetFileSystemRepresentation(resourcesURL, true, resourcesPath, - PATH_MAX)) { - [OFStdErr writeString: @"Failed to locate resources!\n"]; - [OFApplication terminateWithStatus: 1]; - } - - [[OFFileManager defaultManager] changeCurrentDirectoryPath: - [OFString stringWithUTF8String: (const char *)resourcesPath]]; -#endif -#if defined(OF_WII) && defined(OF_HAVE_FILES) - [[OFFileManager defaultManager] - changeCurrentDirectoryPath: @"/apps/objfw-tests"]; -#endif - - [OFStdOut reset]; - -#if defined(OF_IOS) - [OFStdOut writeFormat: @"%d tests failed!", _fails]; - [OFApplication terminateWithStatus: _fails]; -#elif defined(OF_WII) - [OFStdOut writeString: @"Press home button to exit!"]; - - for (;;) { - WPAD_ScanPads(); - - if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) - [OFApplication terminateWithStatus: _fails]; - - VIDEO_WaitVSync(); - } -#elif defined(OF_PSP) - [OFStdOut writeFormat: @"%d tests failed!", _fails]; - - sceKernelSleepThreadCB(); -#elif defined(OF_NINTENDO_DS) - [OFStdOut writeString: @"Press start button to exit!"]; - - for (;;) { - swiWaitForVBlank(); - scanKeys(); - if (keysDown() & KEY_START) - [OFApplication terminateWithStatus: _fails]; - } -#elif defined(OF_NINTENDO_3DS) - [OFStdOut writeString: @"Press start button to exit!"]; - - for (;;) { - hidScanInput(); - - if (hidKeysDown() & KEY_START) - [OFApplication terminateWithStatus: _fails]; - - gspWaitForVBlank(); - } -#elif defined(OF_NINTENDO_SWITCH) - while (appletMainLoop()) - updateConsole(true); - - consoleExit(NULL); - - [OFApplication terminateWithStatus: _fails]; -#else - [OFApplication terminateWithStatus: _fails]; -#endif -} -@end