ObjFW  Diff

Differences From Artifact [8cfd87b118]:

To Artifact [ab72b7da5d]:


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
17
18
19
20
21
22
23






24
25
26
27
28
29
30







-
-
-
-
-
-








#include "config.h"

#include <stdlib.h>

#import "TestsAppDelegate.h"

#if defined(STDOUT) && (defined(OF_WINDOWS) || defined(OF_MSDOS) || \
    defined(OF_IOS))
# undef STDOUT
# define STDOUT_SIMPLE
#endif

#ifdef OF_IOS
# include <CoreFoundation/CoreFoundation.h>
#endif

#ifdef OF_PSP
# include <pspmoduleinfo.h>
# include <pspkernel.h>
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

158

159
160
161


162

163
164


165
166
167
168
169
170
171
172
173
174
175

176
177


178
179
180
181
182
183
184

185
186


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267



268
269
270

271
272

273
274
275
276
277
278
279
280
281
282
283
284





285
286
287
288


289
290
291
292
293
294
295
296
297
298





299
300
301
302
303
304
305
306
307






308
309
310


311
312
313
314
315
316
317
318
319









320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345



























346
347
348


349
350
351
352
353
354









355
356
357
358
359
360
361
362
363
137
138
139
140
141
142
143


144
145
146
147
148
149
150

151



152
153
154
155


156
157
158
159
160
161
162
163
164
165
166
167
168
169


170
171
172
173
174
175
176
177
178
179


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
























































201
202
203



204
205
206



207


208



209
210
211
212
213




214
215
216
217
218




219
220


221
222
223
224
225



226
227
228
229
230



231





232
233
234
235
236
237
238


239
240
241








242
243
244
245
246
247
248
249
250
251

























252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279


280
281
282





283
284
285
286
287
288
289
290
291


292
293
294
295
296
297
298







-
-






+
-
+
-
-
-
+
+

+
-
-
+
+











+
-
-
+
+







+
-
-
+
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
-
-
+
+
+
-
-
-
+
-
-
+
-
-
-





-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-





-
-
-
+
+
+
+
+
-
-
-

-
-
-
-
-
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-








#if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \
	defined(OF_NINTENDO_3DS)
	@try {
		return of_application_main(&argc, &argv,
		    [[TestsAppDelegate alloc] init]);
	} @catch (id e) {
		TestsAppDelegate *delegate =
		    [OFApplication sharedApplication].delegate;
		OFString *string = [OFString stringWithFormat:
		    @"\nRuntime error: Unhandled exception:\n%@\n", e];
		OFString *backtrace = [OFString stringWithFormat:
		    @"\nBacktrace:\n  %@\n\n",
		    [[e backtrace] componentsJoinedByString: @"\n  "]];

		of_stdout.foregroundColor = [OFColor red];
		[delegate outputString: string
		[of_stdout writeString: string];
			       inColor: RED];
		[delegate outputString: backtrace
			       inColor: RED];
		[of_stdout writeString: backtrace];

# if defined(OF_WII)
		[of_stdout reset];
		[delegate outputString: @"Press home button to exit!\n"
			       inColor: NO_COLOR];
		[of_stdout 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)
		[of_stdout reset];
		[delegate outputString: @"Press start button to exit!"
			       inColor: NO_COLOR];
		[of_stdout writeString: @"Press start button to exit!"];

		for (;;) {
			swiWaitForVBlank();
			scanKeys();
			if (keysDown() & KEY_START)
				[OFApplication terminateWithStatus: 1];
		}
# elif defined(OF_NINTENDO_3DS)
		[of_stdout reset];
		[delegate outputString: @"Press start button to exit!"
			       inColor: NO_COLOR];
		[of_stdout writeString: @"Press start button to exit!"];

		for (;;) {
			hidScanInput();

			if (hidKeysDown() & KEY_START)
				[OFApplication terminateWithStatus: 1];

			gspWaitForVBlank();
		}
# else
		abort();
# endif
	}
#else
	return of_application_main(&argc, &argv,
	    [[TestsAppDelegate alloc] init]);
#endif
}

@implementation TestsAppDelegate
- (void)outputString: (OFString *)str
	     inColor: (int)color
{
#if defined(OF_PSP)
	char space = ' ';
	int y = pspDebugScreenGetY();

	pspDebugScreenSetXY(0, y);
	for (uint8_t i = 0; i < 68; i++)
		pspDebugScreenPrintData(&space, 1);

	switch (color) {
	case NO_COLOR:
		pspDebugScreenSetTextColor(0xFFFFFF);
		break;
	case RED:
		pspDebugScreenSetTextColor(0x0000FF);
		break;
	case GREEN:
		pspDebugScreenSetTextColor(0x00FF00);
		break;
	case YELLOW:
		pspDebugScreenSetTextColor(0x00FFFF);
		break;
	}

	pspDebugScreenSetXY(0, y);
	pspDebugScreenPrintData(str.UTF8String, str.UTF8StringLength);
#elif defined(STDOUT)
	switch (color) {
	case NO_COLOR:
		[of_stdout writeString: @"\r\033[K"];
# if defined(OF_WII) || defined(OF_NINTENDO_DS)
		[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"];
#elif defined(STDOUT_SIMPLE)
	[of_stdout writeString: str];
#else
# error No output method!
#endif
}

- (void)outputTesting: (OFString *)test
	     inModule: (OFString *)module
{
	void *pool = objc_autoreleasePoolPush();
#ifndef STDOUT_SIMPLE
	[self outputString: [OFString stringWithFormat: @"[%@] %@: testing...",
	if (of_stdout.hasTerminal) {
		of_stdout.foregroundColor = [OFColor yellow];
		[of_stdout writeFormat: @"[%@] %@: testing...", module, test];
							module, test]
		   inColor: YELLOW];
#else
	} else
	[self outputString: [OFString stringWithFormat: @"[%@] %@: ",
							module, test]
		[of_stdout writeFormat: @"[%@] %@: ", module, test];
		   inColor: YELLOW];
#endif
	objc_autoreleasePoolPop(pool);
}

- (void)outputSuccess: (OFString *)test
	     inModule: (OFString *)module
{
#ifndef STDOUT_SIMPLE
	void *pool = objc_autoreleasePoolPush();
	[self outputString: [OFString stringWithFormat: @"[%@] %@: ok\n",
							module, test]
	if (of_stdout.hasTerminal) {
		of_stdout.cursorColumn = 0;
		of_stdout.foregroundColor = [OFColor lime];
		[of_stdout eraseLine];
		[of_stdout writeFormat: @"[%@] %@: ok\n", module, test];
		   inColor: GREEN];
	objc_autoreleasePoolPop(pool);
#else
	[self outputString: @"ok\n"
	} else
		[of_stdout writeLine: @"ok"];
		   inColor: GREEN];
#endif
}

- (void)outputFailure: (OFString *)test
	     inModule: (OFString *)module
{
#ifndef STDOUT_SIMPLE
	void *pool = objc_autoreleasePoolPush();
	[self outputString: [OFString stringWithFormat: @"[%@] %@: failed\n",
	if (of_stdout.hasTerminal) {
		of_stdout.cursorColumn = 0;
		of_stdout.foregroundColor = [OFColor red];
		[of_stdout eraseLine];
		[of_stdout writeFormat: @"[%@] %@: failed\n", module, test];
							module, test]
		   inColor: RED];
	objc_autoreleasePoolPop(pool);

# ifdef OF_WII
	[self outputString: @"Press A to continue!\n"
		   inColor: NO_COLOR];
	for (;;) {
		WPAD_ScanPads();
#ifdef OF_WII
		[of_stdout reset];
		[of_stdout writeLine: @"Press A to continue!"];

		for (;;) {
			WPAD_ScanPads();

		if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
			return;
			if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
				return;

		VIDEO_WaitVSync();
	}
# endif
# ifdef OF_PSP
	[self outputString: @"Press X to continue!\n"
		   inColor: NO_COLOR];
	for (;;) {
		SceCtrlData pad;
			VIDEO_WaitVSync();
		}
#endif
#ifdef OF_PSP
		[of_stdout reset];
		[of_stdout 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
	[self outputString: @"Press A to continue!"
		   inColor: NO_COLOR];
	for (;;) {
		swiWaitForVBlank();
		scanKeys();
		if (keysDown() & KEY_A)
			break;
	}
# endif
# ifdef OF_NINTENDO_3DS
	[self outputString: @"Press A to continue!"
		   inColor: NO_COLOR];
	for (;;) {
		hidScanInput();
			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
		[of_stdout reset];
		[of_stdout writeString: @"Press A to continue!"];

		for (;;) {
			swiWaitForVBlank();
			scanKeys();
			if (keysDown() & KEY_A)
				break;
		}
#endif
#ifdef OF_NINTENDO_3DS
		[of_stdout reset];
		[of_stdout writeString: @"Press A to continue!"];

		for (;;) {
			hidScanInput();

		if (hidKeysDown() & KEY_A)
			break;
			if (hidKeysDown() & KEY_A)
				break;

		gspWaitForVBlank();
	}
# endif
#else
	[self outputString: @"failed\n"
			gspWaitForVBlank();
		}
#endif

		of_stdout.cursorColumn = 0;
		[of_stdout reset];
		[of_stdout eraseLine];
	} else
		[of_stdout writeLine: @"failed"];
		   inColor: RED];
#endif
}

- (void)applicationDidFinishLaunching
{
#if defined(OF_IOS) && defined(OF_HAVE_FILES)
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
411
412
413
414
415
416
417








418
419
420
421
422
423
424
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367







+
+
+
+
+
+
+
+







#if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437)
	[self INIFileTests];
#endif
#ifdef OF_HAVE_SOCKETS
	[self socketTests];
	[self TCPSocketTests];
	[self UDPSocketTests];
# ifdef OF_HAVE_SCTP
	[self SCTPSocketTests];
# endif
# ifdef OF_HAVE_IPX
	[self IPXSocketTests];
	[self SPXSocketTests];
	[self SPXStreamSocketTests];
# endif
	[self kernelEventObserverTests];
#endif
#ifdef OF_HAVE_THREADS
	[self threadTests];
#endif
	[self URLTests];
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
445
446
447
448
449
450
451


452
453

454
455
456
457
458
459


460
461
462
463
464
465
466
467
468
469
470


471
472
473
474
475


476
477
478
479
480
481
482
483
484


485
486
487
488
489
490
491
492
493
494
495
496
497
388
389
390
391
392
393
394
395
396
397

398


399
400


401
402
403
404
405
406
407
408
409
410
411


412
413

414
415


416
417
418
419
420
421
422
423
424


425
426
427
428
429
430
431
432
433
434
435
436
437
438
439







+
+

-
+
-
-


-
-
+
+









-
-
+
+
-


-
-
+
+







-
-
+
+














#ifdef OF_HAVE_SOCKETS
	[self DNSResolverTests];
#endif
	[self systemInfoTests];
	[self localeTests];

	[of_stdout reset];

#if defined(OF_IOS)
	[self outputString: [OFString stringWithFormat: @"%d tests failed!",
	[of_stdout writeFormat: @"%d tests failed!", _fails];
							_fails]
		   inColor: NO_COLOR];
	[OFApplication terminateWithStatus: _fails];
#elif defined(OF_WII)
	[self outputString: @"Press home button to exit!\n"
		   inColor: NO_COLOR];
	[of_stdout 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)
	[self outputString: [OFString stringWithFormat: @"%d tests failed!",
							_fails]
	[of_stdout writeFormat: @"%d tests failed!", _fails];

		   inColor: NO_COLOR];
	sceKernelSleepThreadCB();
#elif defined(OF_NINTENDO_DS)
	[self outputString: @"Press start button to exit!"
		   inColor: NO_COLOR];
	[of_stdout writeString: @"Press start button to exit!"];

	for (;;) {
		swiWaitForVBlank();
		scanKeys();
		if (keysDown() & KEY_START)
			[OFApplication terminateWithStatus: _fails];
	}
#elif defined(OF_NINTENDO_3DS)
	[self outputString: @"Press start button to exit!"
		   inColor: NO_COLOR];
	[of_stdout writeString: @"Press start button to exit!"];

	for (;;) {
		hidScanInput();

		if (hidKeysDown() & KEY_START)
			[OFApplication terminateWithStatus: _fails];

		gspWaitForVBlank();
	}
#else
	[OFApplication terminateWithStatus: _fails];
#endif
}
@end