PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/OJUnit/OJTestResult.j

http://github.com/hammerdr/OJTest
Unknown | 130 lines | 107 code | 23 blank | 0 comment | 0 complexity | 4effbf891cfa217ee7922da92707b5a2 MD5 | raw file
  1@import <Foundation/Foundation.j>
  2
  3@import "OJTestFailure.j"
  4
  5@implementation OJTestResult : CPObject
  6{
  7    CPArray     _failures;
  8    CPArray     _errors;
  9    CPArray     _listeners;
 10    int         _runTests;
 11    BOOL        _stop;
 12}
 13
 14- (id)init
 15{
 16    if (self = [super init])
 17    {
 18        _failures   = [];
 19        _errors     = [];
 20        _listeners  = [];
 21        _runTests   = 0;
 22        _stop       = NO;
 23    }
 24    return self;
 25}
 26
 27- (void)addError:(CPException)error forTest:(OJTest)aTest
 28{
 29    [_failures addObject:[[OJTestFailure alloc] initWithTest:aTest exception:error]];
 30    for (var i = 0; i < _listeners.length; i++)
 31        [_listeners[i] addError:error forTest:aTest];
 32}
 33
 34- (void)addFailure:(CPException)failure forTest:(OJTest)aTest
 35{
 36    [_errors addObject:[[OJTestFailure alloc] initWithTest:aTest exception:failure]];
 37    for (var i = 0; i < _listeners.length; i++)
 38        [_listeners[i] addFailure:failure forTest:aTest];
 39}
 40
 41- (void)startTest:(OJTest)aTest
 42{
 43    _runTests += [aTest countTestCases];
 44    for (var i = 0; i < _listeners.length; i++)
 45        [_listeners[i] startTest:aTest];
 46}
 47
 48- (void)endTest:(OJTest)aTest
 49{
 50    
 51    for (var i = 0; i < _listeners.length; i++)
 52        [_listeners[i] endTest:aTest];
 53}
 54
 55- (void)run:(OJTestCase)aTest
 56{
 57    [self startTest:aTest];
 58
 59    try
 60    {
 61        [aTest runBare];
 62    }
 63    catch (e)
 64    {
 65        // if not objj object, toll-free bridge to CPException
 66        if (!e.isa) {
 67            CPLog.warn("toll-free bridging e="+e+" to CPException")
 68            e.isa = CPException;
 69        }
 70
 71        if ([e name] == AssertionFailedError)
 72            [self addFailure:e forTest:aTest];
 73        else
 74            [self addError:e forTest:aTest];
 75    }
 76
 77    [self endTest:aTest];
 78}
 79
 80- (void)addListener:(OJTestListener)listener
 81{
 82    [_listeners addObject:listener];
 83}
 84
 85- (void)removeListener:(OJTestListener)listener
 86{
 87    [_listeners removeObject:listener];
 88}
 89
 90- (int)runCount
 91{
 92    return _runTests;
 93}
 94
 95- (BOOL)shouldStop
 96{
 97    return _stop;
 98}
 99
100- (void)stop
101{
102    _stop = YES;
103}
104
105- (int)failureCount
106{
107    return [_failures count];
108}
109
110- (CPArray)failures
111{
112    return _failures;
113}
114
115- (int)errorCount
116{
117    return [_errors count];
118}
119
120- (CPArray)errors
121{
122    return _errors;
123}
124
125- (BOOL)wasSuccessful
126{
127    return [self failureCount] == 0 && [self errorCount] == 0;
128}
129
130@end