* Minor fixes to glitches detected by the clang static analyzer.
* Added MYAnimatingSplitView class.
5 // Created by Jens Alfke on 1/5/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
10 #import "ExceptionUtils.h"
15 BOOL gRunningTestCase;
17 struct TestCaseLink *gAllTestCases;
18 static int sPassed, sFailed;
19 static int sCurTestCaseExceptions;
22 static void TestCaseExceptionReporter( NSException *x ) {
23 sCurTestCaseExceptions++;
24 Log(@"XXX FAILED test case -- backtrace:\n%@\n\n", x.my_callStack);
27 static BOOL RunTestCase( struct TestCaseLink *test )
29 BOOL oldLogging = EnableLog(YES);
30 gRunningTestCase = YES;
32 NSAutoreleasePool *pool = [NSAutoreleasePool new];
33 Log(@"=== Testing %s ...",test->name);
35 sCurTestCaseExceptions = 0;
36 MYSetExceptionReporter(&TestCaseExceptionReporter);
38 test->testptr(); //SHAZAM!
40 if( sCurTestCaseExceptions == 0 ) {
41 Log(@"√√√ %s passed\n\n",test->name);
45 Log(@"XXX FAILED test case '%s' due to %i exception(s) already reported above",
46 test->name,sCurTestCaseExceptions);
49 }@catch( NSException *x ) {
50 if( [x.name isEqualToString: @"TestCaseSkipped"] )
51 Log(@"... skipping test %s since %@\n\n", test->name, x.reason);
53 Log(@"XXX FAILED test case '%s' due to:\nException: %@\n%@\n\n",
54 test->name,x,x.my_callStack);
59 test->testptr = NULL; // prevents test from being run again
62 gRunningTestCase = NO;
63 EnableLog(oldLogging);
68 static BOOL RunTestCaseNamed( const char *name )
70 for( struct TestCaseLink *test = gAllTestCases; test; test=test->next )
71 if( strcmp(name,test->name)==0 ) {
72 return RunTestCase(test);
74 Log(@"... WARNING: Could not find test case named '%s'\n\n",name);
79 void _RequireTestCase( const char *name )
81 if( ! RunTestCaseNamed(name) ) {
82 [NSException raise: @"TestCaseSkipped"
83 format: @"prerequisite %s failed", name];
88 void RunTestCases( int argc, const char **argv )
90 sPassed = sFailed = 0;
91 BOOL stopAfterTests = NO;
92 for( int i=1; i<argc; i++ ) {
93 const char *arg = argv[i];
94 if( strncmp(arg,"Test_",5)==0 ) {
96 if( strcmp(arg,"Only")==0 )
98 else if( strcmp(arg,"All") == 0 ) {
99 for( struct TestCaseLink *link = gAllTestCases; link; link=link->next )
102 RunTestCaseNamed(arg);
106 if( sPassed>0 || sFailed>0 || stopAfterTests ) {
108 Log(@"√√√√√√ ALL %i TESTS PASSED √√√√√√", sPassed);
110 Log(@"****** %i TESTS FAILED, %i PASSED ******", sFailed,sPassed);
113 if( stopAfterTests ) {
114 Log(@"Stopping after tests ('Test_Only' arg detected)");
125 #pragma mark ASSERTION FAILURE HANDLER:
128 void _AssertFailed( id rcvr, const void *selOrFn, const char *sourceFile, int sourceLine,
129 const char *condString, NSString *message, ... )
133 va_start(args,message);
134 message = [[[NSString alloc] initWithFormat: message arguments: args] autorelease];
135 message = [@"Assertion failed: " stringByAppendingString: message];
138 message = [NSString stringWithUTF8String: condString];
141 [[NSAssertionHandler currentHandler] handleFailureInMethod: (SEL)selOrFn
143 file: [NSString stringWithUTF8String: sourceFile]
144 lineNumber: sourceLine
145 description: @"%@", message];
147 [[NSAssertionHandler currentHandler] handleFailureInFunction: [NSString stringWithUTF8String:selOrFn]
148 file: [NSString stringWithUTF8String: sourceFile]
149 lineNumber: sourceLine
150 description: @"%@", message];
151 abort(); // unreachable, but appeases compiler
156 Copyright (c) 2008, Jens Alfke <jens@mooseyard.com>. All rights reserved.
158 Redistribution and use in source and binary forms, with or without modification, are permitted
159 provided that the following conditions are met:
161 * Redistributions of source code must retain the above copyright notice, this list of conditions
162 and the following disclaimer.
163 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
164 and the following disclaimer in the documentation and/or other materials provided with the
167 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
168 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
169 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
170 BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
171 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
172 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
173 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
174 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.