@@ -18,10 +18,11 @@ #include #import "OFString.h" #import "OFStdIOStream.h" +#import "OFFile.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" #ifdef _PSP @@ -28,10 +29,24 @@ # include # include # include PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); #endif + +#ifdef __wii__ +# define BOOL OGC_BOOL +# include +# include +# undef BOOL +#endif + +enum { + NO_COLOR, + RED, + GREEN, + YELLOW +}; int main(int argc, char *argv[]) { #ifdef OF_OBJFW_RUNTIME @@ -39,11 +54,56 @@ #endif /* We need deterministic hashes for tests */ of_hash_seed = 0; +#ifdef __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); + + @try { + return of_application_main(&argc, &argv, + [TestsAppDelegate class]); + } @catch (id e) { + TestsAppDelegate *delegate = + [[OFApplication sharedApplication] delegate]; + OFString *string = [OFString stringWithFormat: + @"\nRuntime error: Unhandled exception:\n%@\n", e]; + + [delegate outputString: string + withColor: RED]; + [delegate outputString: @"Press home button to exit!\n" + withColor: NO_COLOR]; + for (;;) { + WPAD_ScanPads(); + + if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) + [OFApplication terminateWithStatus: 1]; + + VIDEO_WaitVSync(); + } + } +#else return of_application_main(&argc, &argv, [TestsAppDelegate class]); +#endif } @implementation TestsAppDelegate - (void)outputString: (OFString*)str withColor: (int)color @@ -70,18 +130,24 @@ pspDebugScreenSetXY(0, y); pspDebugScreenPrintData([str UTF8String], [str UTF8StringLength]); #elif defined(STDOUT) switch (color) { - case 0: - [of_stdout writeString: @"\r\033[K\033[1;33m"]; - break; - case 1: - [of_stdout writeString: @"\r\033[K\033[1;32m"]; - break; - case 2: - [of_stdout writeString: @"\r\033[K\033[1;31m"]; + case NO_COLOR: + [of_stdout writeString: @"\r\033[K"]; +# ifdef __wii__ + [of_stdout writeString: @"\033[37m"]; +# endif + break; + case RED: + [of_stdout writeString: @"\r\033[K\033[31;1m"]; + break; + case GREEN: + [of_stdout writeString: @"\r\033[K\033[32;1m"]; + break; + case YELLOW: + [of_stdout writeString: @"\r\033[K\033[33;1m"]; break; } [of_stdout writeString: str]; [of_stdout writeString: @"\033[m"]; @@ -94,39 +160,55 @@ inModule: (OFString*)module { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; [self outputString: [OFString stringWithFormat: @"[%@] %@: testing...", module, test] - withColor: 0]; + withColor: YELLOW]; [pool release]; } - (void)outputSuccess: (OFString*)test inModule: (OFString*)module { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; [self outputString: [OFString stringWithFormat: @"[%@] %@: ok\n", module, test] - withColor: 1]; + withColor: GREEN]; [pool release]; } - (void)outputFailure: (OFString*)test inModule: (OFString*)module { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; [self outputString: [OFString stringWithFormat: @"[%@] %@: failed\n", module, test] - withColor: 2]; + withColor: RED]; [pool release]; + +#ifdef __wii__ + [self outputString: @"Press A to continue!\n" + withColor: NO_COLOR]; + for (;;) { + WPAD_ScanPads(); + + if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) + return; + + VIDEO_WaitVSync(); + } +#endif } - (void)applicationDidFinishLaunching { #ifdef _PSP pspDebugScreenInit(); #endif +#ifdef __wii__ + [OFFile changeToDirectoryAtPath: @"/objfw-tests"]; +#endif [self objectTests]; #ifdef OF_HAVE_BLOCKS [self blockTests]; #endif @@ -162,8 +244,21 @@ [self forwardingTests]; #ifdef OF_HAVE_PROPERTIES [self propertiesTests]; #endif +#ifdef __wii__ + [self outputString: @"Press home button to exit!\n" + withColor: NO_COLOR]; + for (;;) { + WPAD_ScanPads(); + + if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) + [OFApplication terminateWithStatus: _fails]; + + VIDEO_WaitVSync(); + } +#else [OFApplication terminateWithStatus: _fails]; +#endif } @end