//
//  Gui.m
//  Oaxaca2Test
//
//  Created by Nicholas Matsakis on 5/13/08.
//  Copyright 2008 Nicholas Matsakis. All rights reserved.
//

#import "Gui.h"
#import "HomTests.h"
#import "OxNSString.h"

@implementation Gui

- init {
    [super init];
    self.tests = [NSArray array];
    self.label = @"";
    m_total = 0;
    m_failed = 0;
    return self;
}

@synthesize tests = a_tests;
@synthesize label = a_label;

- (void)startTestGroup:(NSString*)name {
    NSMutableDictionary *testData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     name, @"name", @"", @"status", nil];
    self.tests = [self.tests arrayByAddingObject:testData];
}

- (void)test:(NSString*)name passesIf:(BOOL)passed {
    NSAttributedString *status = 
		(passed 
		 ? [@"Pass" withColor:[NSColor blackColor]]
		 : [@"FAIL" withColor:[NSColor redColor]]);
    NSMutableDictionary *testData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                     name, @"name", status, @"status", nil];
    self.tests = [self.tests arrayByAddingObject:testData];
    m_total++;
    if (!passed) m_failed++;    
}

- (IBAction) runTests:(id)sender {
    self.tests = [NSArray array];
    self.label = @"Testing";
    m_failed = m_total = 0;
    [[[[HomTests alloc] init] autorelease] runTests:self];
    self.label = [NSString stringWithFormat:@"%d failed out of %d tests.", m_failed, m_total];
}

@end
