Frameworks/OJUnit/OJTestResult.j
Go to the documentation of this file.

    00001 @import <Foundation/Foundation.j>
    00002
    00003 @import "OJTestFailure.j"
    00004 @import "OJTestListenerText.j"
    00005
    00006 @implementation OJTestResult : CPObject
    00007 {
    00008     CPArray     _failures               @accessors(readonly, property=failures);
    00009     CPArray     _errors                 @accessors(readonly, property=errors);
    00010     CPArray     _listeners;
    00011     int         _runTests;
    00012     BOOL        _stop;
    00013 }
    00014
    00018 + (OJTestResult)createResult
    00019 {
    00020     return [[OJTestResult alloc] init];
    00021 }
    00022
    00023 - (id)init
    00024 {
    00025     if (self = [super init])
    00026     {
    00027         _failures   = [];
    00028         _errors     = [];
    00029         _listeners  = [];
    00030         _runTests   = 0;
    00031         _stop       = NO;
    00032     }
    00033     return self;
    00034 }
    00035
    00036 - (void)addError:(CPException)error forTest:(OJTest)aTest
    00037 {
    00038         [self addError:[[OJTestFailure alloc] initWithTest:aTest exception:error]];
    00039 }
    00040
    00041 - (void)addError:(OJTestFailure)error
    00042 {
    00043         [_errors addObject:error];
    00044         for (var i = 0; i < _listeners.length; i++)
    00045             [_listeners[i] addError:error];
    00046 }
    00047
    00048 - (void)addFailure:(CPException)failure forTest:(OJTest)aTest
    00049 {
    00050         [self addFailure:[[OJTestFailure alloc] initWithTest:aTest exception:failure]];
    00051 }
    00052
    00053 - (void)addFailure:(OJTestFailure)failure
    00054 {
    00055     [_failures addObject:failure];
    00056     for (var i = 0; i < _listeners.length; i++)
    00057         [_listeners[i] addFailure:failure];
    00058 }
    00059
    00060 - (void)startTest:(OJTest)aTest
    00061 {
    00062     _runTests += [aTest countTestCases];
    00063     for (var i = 0; i < _listeners.length; i++)
    00064         [_listeners[i] startTest:aTest];
    00065 }
    00066
    00067 - (void)endTest:(OJTest)aTest
    00068 {
    00069
    00070     for (var i = 0; i < _listeners.length; i++)
    00071         [_listeners[i] endTest:aTest];
    00072 }
    00073
    00074 - (void)run:(OJTestCase)aTest
    00075 {
    00076     [self startTest:aTest];
    00077
    00078     try
    00079     {
    00080         [aTest runBare];
    00081     }
    00082     catch (e)
    00083     {
    00084         // if not objj object, toll-free bridge to CPException
    00085         if (!e.isa) {
    00086             CPLog.warn("toll-free bridging e="+e+" to CPException")
    00087             e.isa = CPException;
    00088         }
    00089
    00090         if ([e name] == AssertionFailedError)
    00091             [self addFailure:e forTest:aTest];
    00092         else
    00093             [self addError:e forTest:aTest];
    00094     }
    00095
    00096     [self endTest:aTest];
    00097 }
    00098
    00099 - (void)addListener:(OJTestListener)listener
    00100 {
    00101     [_listeners addObject:listener];
    00102 }
    00103
    00104 - (void)removeListener:(OJTestListener)listener
    00105 {
    00106     [_listeners removeObject:listener];
    00107 }
    00108
    00109 - (int)runCount
    00110 {
    00111     return _runTests;
    00112 }
    00113
    00114 - (BOOL)shouldStop
    00115 {
    00116     return _stop;
    00117 }
    00118
    00119 - (void)stop
    00120 {
    00121     _stop = YES;
    00122 }
    00123
    00124 - (int)numberOfFailures
    00125 {
    00126     return [_failures count];
    00127 }
    00128
    00129 - (int)failureCount
    00130 {
    00131         CPLog.warn("[OJTestResult failureCount] is deprecated. Please use [OJTestResult numberOfFailures].");
    00132         return [self numberOfFailures];
    00133 }
    00134
    00135 - (int)numberOfErrors
    00136 {
    00137     return [_errors count];
    00138 }
    00139
    00140 - (int)errorCount
    00141 {
    00142         CPLog.warn("[OJTestResult errorCount] is deprecated. Please use [OJTestResult numberOfErrors].");
    00143         return [self numberOfErrors];
    00144 }
    00145
    00146 - (BOOL)wasSuccessful
    00147 {
    00148     return [self numberOfFailures] == 0 && [self numberOfErrors] == 0;
    00149 }
    00150
    00151 @end

All Classes Files Functions Variables