See ChangeLog

Monotone-Parent: f1c001048ccc36181a09a459327f563dbc26e12f
Monotone-Revision: aab1e060a1d26a9624f7f84c30d1414ca1969560

Monotone-Author: ludovic@Sophos.ca
Monotone-Date: 2010-01-24T20:40:12
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Ludovic Marcotte committed 2010-01-24 20:40:12 +00:00
1 parent 3efde51b62
commit 00e3963a96
25 files changed
+66 -54

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
# GNUstep makefile
debug=yes
include ../config.make
include $(GNUSTEP_MAKEFILES)/common.make
include ../Version
TEST_TOOL = sogo-tests
$(TEST_TOOL)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS)
$(TEST_TOOL)_OBJC_FILES += \
sogo-tests.m \
\
SOGoTest.m \
SOGoTestRunner.m \
\
TestBSJSONAdditions.m
TOOL_NAME = $(TEST_TOOL)
ADDITIONAL_INCLUDE_DIRS += \
-D_GNU_SOURCE -I../SOPE/ -I../SoObjects/ -I../UI/
ADDITIONAL_LIB_DIRS += \
-L../SoObjects/SOGo -lSOGo
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/tool.make
-include GNUmakefile.postamble
+75
View File
@@ -0,0 +1,75 @@
/* SOGoTest.h - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef SOGOTEST_H
#define SOGOTEST_H
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
@class NSArray;
@class NSMutableArray;
@class SOGoTestRunner;
@interface SOGoTest : NSObject
{
SOGoTestRunner *testRunner;
BOOL hasFailed;
}
+ (NSArray *) allTestClasses;
- (void) setTestRunner: (SOGoTestRunner *) newTestRunner;
- (void) setUp;
- (void) tearDown;
- (void) test: (BOOL) condition
message: (NSString *) message
file: (const char *) file
line: (int) line;
- (BOOL) run;
@end
#define test(c) { \
[self test: (c) message: @"assertion failure" \
file: __FILE__ line: __LINE__]; \
}
#define testWithMessage(c,m) { \
[self test: (c) message: (m) \
file: __FILE__ line: __LINE__]; \
}
#define failIf(c) test(!c)
#define testEquals(a,b) \
testWithMessage(([a isEqual: b]), \
([NSString stringWithFormat: @"objects '%@' and '%@' differs", (a), (b)]))
#define testEqualsWithMessage(a,b,m) \
testWithMessage(([a isEqual: b]), (m))
#endif /* SOGOTEST_H */
+183
View File
@@ -0,0 +1,183 @@
/* SOGoTest.m - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import "SOGoTestRunner.h"
#import "SOGoTest.h"
static NSString *SOGoTestAssertException = @"SOGoTestAssertException";
@implementation SOGoTest
+ (NSArray *) allTestClasses
{
NSMutableArray *allTestClasses;
NSArray *allSubClasses;
NSString *class;
int count, max;
allSubClasses = GSObjCAllSubclassesOfClass (self);
max = [allSubClasses count];
allTestClasses = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
class = NSStringFromClass ([allSubClasses objectAtIndex: count]);
if ([class hasPrefix: @"Test"])
[allTestClasses addObject: class];
}
return allTestClasses;
}
- (id) init
{
if ((self = [super init]))
{
testRunner = nil;
}
return self;
}
- (void) dealloc
{
[testRunner release];
[super dealloc];
}
- (void) setTestRunner: (SOGoTestRunner *) newTestRunner
{
ASSIGN (testRunner, newTestRunner);
}
- (void) setUp
{
}
- (void) tearDown
{
}
- (void) test: (BOOL) condition
message: (NSString *) message
file: (const char *) file
line: (int) line
{
NSDictionary *fileInfo;
if (!condition)
{
if (file)
fileInfo = [NSDictionary dictionaryWithObject:
[NSString stringWithFormat: @"%s:%d", file, line]
forKey: @"fileInfo"];
else
fileInfo = nil;
[[NSException exceptionWithName: SOGoTestAssertException
reason: message
userInfo: fileInfo] raise];
}
}
- (void) performTest: (SEL) testMethod
{
SOGoTestFailureCode failureCode;
failureCode = SOGoTestFailureSuccess;
NS_DURING
{
[self setUp];
}
NS_HANDLER
{
failureCode = SOGoTestFailureError;
[testRunner reportException: localException
method: @"setUp"
withCode: failureCode];
}
NS_ENDHANDLER;
if (failureCode == SOGoTestFailureSuccess)
{
NS_DURING
{
[self performSelector: testMethod];
}
NS_HANDLER
{
if ([[localException name]
isEqualToString: SOGoTestAssertException])
failureCode = SOGoTestFailureFailure;
else
failureCode = SOGoTestFailureError;
[testRunner reportException: localException
method: NSStringFromSelector (testMethod)
withCode: failureCode];
}
NS_ENDHANDLER;
}
NS_DURING
{
[self tearDown];
}
NS_HANDLER
{
failureCode = SOGoTestFailureError;
[testRunner reportException: localException
method: @"tearDown"
withCode: failureCode];
}
NS_ENDHANDLER;
[testRunner incrementTestCounter: failureCode];
}
- (BOOL) run
{
NSArray *methods;
NSString *method;
int count, max;
SEL testMethod;
methods = GSObjCMethodNames (self);
max = [methods count];
for (count = 0; count < max; count++)
{
method = [methods objectAtIndex: count];
if ([method hasPrefix: @"test"]
&& [method rangeOfString: @":"].location == NSNotFound)
{
testMethod = NSSelectorFromString (method);
[self performTest: testMethod];
}
}
return YES;
}
@end
+60
View File
@@ -0,0 +1,60 @@
/* SOGoTestRunner.h - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef SOGOTESTRUNNER_H
#define SOGOTESTRUNNER_H
#import <Foundation/NSObject.h>
@class NSException;
@class NSMutableArray;
@class NSString;
typedef enum {
SOGoTestFailureSuccess = 0,
SOGoTestFailureFailure = 1,
SOGoTestFailureError = 2,
} SOGoTestFailureCode;
@interface SOGoTestRunner : NSObject
{
NSMutableArray *messages;
int testCount;
int failuresCount;
int errorsCount;
BOOL hasFailed;
}
+ (SOGoTestRunner *) testRunner;
- (int) run;
- (void) incrementTestCounter: (SOGoTestFailureCode) failureCode;
- (void) reportException: (NSException *) exception
method: (NSString *) methodName
withCode: (SOGoTestFailureCode) failureCode;
- (void) displayReport;
@end
#endif /* SOGOTESTRUNNER_H */
+162
View File
@@ -0,0 +1,162 @@
/* SOGoTestRunner.m - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import "SOGoTest.h"
#import "SOGoTestRunner.h"
@implementation SOGoTestRunner
+ (SOGoTestRunner *) testRunner
{
SOGoTestRunner *testRunner;
testRunner = [self new];
[testRunner autorelease];
return testRunner;
}
- (id) init
{
if ((self = [super init]))
{
testCount = 0;
failuresCount = 0;
errorsCount = 0;
hasFailed = NO;
messages = nil;
}
return self;
}
- (void) dealloc
{
[messages release];
[super dealloc];
}
- (int) run
{
NSEnumerator *allTestClasses;
NSString *class;
SOGoTest *test;
NSAutoreleasePool *pool;
int rc;
rc = 0;
pool = [NSAutoreleasePool currentPool];
[self retain];
allTestClasses = [[SOGoTest allTestClasses] objectEnumerator];
[allTestClasses retain];
while ((class = [allTestClasses nextObject]))
{
test = [NSClassFromString (class) new];
[test setTestRunner: self];
if (![test run])
rc |= -1;
[test autorelease];
[pool emptyPool];
}
[self displayReport];
[allTestClasses autorelease];
[self autorelease];
return rc;
}
- (void) incrementTestCounter: (SOGoTestFailureCode) failureCode
{
static char failureChars[] = { '.', 'F', 'E' };
testCount++;
fprintf (stderr, "%c", failureChars[failureCode]);
}
- (void) reportException: (NSException *) exception
method: (NSString *) methodName
withCode: (SOGoTestFailureCode) failureCode
{
static NSString *failurePrefixs[] = { @"", @"FAIL", @"ERROR" };
NSMutableString *message;
NSString *fileInfo;
hasFailed = YES;
message = [NSMutableString stringWithFormat: @"%@: %@",
failurePrefixs[failureCode], methodName];
fileInfo = [[exception userInfo] objectForKey: @"fileInfo"];
if (fileInfo)
[message appendFormat: @" (%@)\n", fileInfo];
else
[message appendString: @"\n"];
[message appendString: @"----------------------------------------------------------------------\n"];
if (failureCode == SOGoTestFailureFailure)
{
[message appendString: [exception reason]];
failuresCount++;
}
else if (failureCode == SOGoTestFailureError)
{
[message appendFormat: @"an exception occured: %@\n"
@" reason: %@",
[exception name], [exception reason]];
errorsCount++;
}
[message appendString: @"\n"];
[messages addObject: message];
}
- (void) displayReport
{
static NSString *separator = @"\n======================================================================\n";
NSString *reportMessage;
if ([messages count])
{
fprintf (stderr, "%s", [separator UTF8String]);
reportMessage = [messages componentsJoinedByString: separator];
fprintf (stderr, "%s", [reportMessage UTF8String]);
}
fprintf (stderr,
"\n----------------------------------------------------------------------\n"
"Ran %d tests\n\n", testCount);
if (hasFailed)
fprintf (stderr, "FAILED (%d failures, %d errors)\n",
failuresCount, errorsCount);
else
fprintf (stderr, "OK\n");
}
@end
+93
View File
@@ -0,0 +1,93 @@
/* BSJSONAdditions.m - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import "SOGo/NSScanner+BSJSONAdditions.h"
#import "SOGo/NSDictionary+BSJSONAdditions.h"
#import "SOGoTest.h"
@interface TestNSScannerBSJSONAdditions : SOGoTest
@end
@implementation TestNSScannerBSJSONAdditions
- (void) test_scanJSONString
{
NSScanner *testScanner;
NSString *currentString, *expected, *error;
NSMutableString *resultString;
int count;
NSString *testStrings[] = { @"\"\\\\\"", @"\\",
@"\"\\u0041\"", @"A",
@"\"\\u000A\"", @"\n",
@"\"\\u000a\"", @"\n",
nil };
count = 0;
while ((currentString = testStrings[count * 2]))
{
resultString = [NSMutableString string];
testScanner = [NSScanner scannerWithString: currentString];
[testScanner scanJSONString: &resultString];
expected = testStrings[count * 2 + 1];
error = [NSString stringWithFormat:
@"objects '%@' and '%@' differs (count: %d)",
expected, resultString, count];
testEqualsWithMessage(expected, resultString, error);
count++;
}
}
@end
@interface TestNSDictionaryBSJSONAdditions : SOGoTest
@end
@implementation TestNSDictionaryBSJSONAdditions
- (void) test_jsonStringForString
{
NSDictionary *testDictionary;
NSString *currentString, *resultString, *expected, *error;
int count;
NSString *testStrings[] = { @"\n", @"\"\\n\"",
@"\\", @"\"\\\\\"",
nil };
testDictionary = [NSDictionary dictionary];
count = 0;
while ((currentString = testStrings[count * 2]))
{
resultString = [testDictionary jsonStringForString: currentString];
expected = testStrings[count * 2 + 1];
error = [NSString stringWithFormat:
@"objects '%@' and '%@' differs (count: %d)",
expected, resultString, count];
testEqualsWithMessage(expected, resultString, error);
count++;
}
}
@end
+37
View File
@@ -0,0 +1,37 @@
/* sogo-tests.m - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/Foundation.h>
#import "SOGoTestRunner.h"
int main()
{
NSAutoreleasePool *pool;
int rc;
pool = [NSAutoreleasePool new];
rc = [[SOGoTestRunner testRunner] run];
[pool release];
return rc;
}