mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-05 20:10:33 +00:00
Applied changes coming from v2/PR#184.
This commit is contained in:
@@ -21,19 +21,24 @@ $(TEST_TOOL)_OBJC_FILES += \
|
||||
\
|
||||
TestSBJsonParser.m \
|
||||
\
|
||||
TestNGMimeAddressHeaderFieldGenerator.m \
|
||||
TestNGMimeHeaderFieldGenerator.m \
|
||||
TestNGMimeMessageGenerator.m \
|
||||
\
|
||||
TestNSData+Crypto.m \
|
||||
TestNSString+Crypto.m \
|
||||
TestNSString+URLEscaping.m \
|
||||
TestNSString+Utilities.m \
|
||||
TestNGMailAddressParser.m
|
||||
TestNGMailAddressParser.m \
|
||||
\
|
||||
TestRTFHandler.m \
|
||||
../../OpenChange/RTFHandler.m
|
||||
# I don't know how to link against -l:SOGoBackend \
|
||||
undefined reference to `__objc_class_name_SOGoMailFolder'
|
||||
|
||||
TEST_TOOL_NAME = $(TEST_TOOL)
|
||||
|
||||
$(TEST_TOOL)_CPPFLAGS += \
|
||||
-Wall -D_GNU_SOURCE -I../../SOPE/ -I../../SoObjects/ -I../../UI/
|
||||
-Wall -D_GNU_SOURCE -I../../SOPE/ -I../../SoObjects/ -I../../UI/ -I../../OpenChange
|
||||
|
||||
ADDITIONAL_LIB_DIRS += \
|
||||
-L../../SoObjects/SOGo/SOGo.framework/Versions/Current/sogo -L../../SOPE/NGCards/obj -L../../SOPE/GDLContentStore/obj -lSOGo -lNGMime -lNGCards -lGDLContentStore -lNGExtensions -lSBJson -lobjc \
|
||||
@@ -47,3 +52,4 @@ include $(GNUSTEP_MAKEFILES)/test-tool.make
|
||||
|
||||
check :: $(TEST_TOOL)
|
||||
./obj/sogo-tests
|
||||
|
||||
|
||||
@@ -154,7 +154,8 @@ static NSString *SOGoTestAssertException = @"SOGoTestAssertException";
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
|
||||
[testRunner incrementTestCounter: failureCode];
|
||||
[testRunner incrementTestCounter: failureCode
|
||||
afterMethod: NSStringFromSelector (testMethod)];
|
||||
}
|
||||
|
||||
- (BOOL) run
|
||||
|
||||
@@ -35,20 +35,31 @@ typedef enum {
|
||||
SOGoTestFailureError = 2,
|
||||
} SOGoTestFailureCode;
|
||||
|
||||
typedef enum {
|
||||
SOGoTestTextOutputFormat = 0,
|
||||
SOGoTestJUnitOutputFormat
|
||||
} SOGoTestOutputFormat;
|
||||
|
||||
@interface SOGoTestRunner : NSObject
|
||||
{
|
||||
NSMutableArray *messages;
|
||||
/* An array of arrays whose components are the method name and the
|
||||
failure message if any */
|
||||
NSMutableArray *performedTests;
|
||||
int testCount;
|
||||
int failuresCount;
|
||||
int errorsCount;
|
||||
BOOL hasFailed;
|
||||
SOGoTestOutputFormat reportFormat;
|
||||
}
|
||||
|
||||
+ (SOGoTestRunner *) testRunner;
|
||||
+ (SOGoTestRunner *) testRunnerWithFormat: (SOGoTestOutputFormat) reportFormat;
|
||||
|
||||
- (void) setReportFormat: (SOGoTestOutputFormat) format;
|
||||
|
||||
- (int) run;
|
||||
|
||||
- (void) incrementTestCounter: (SOGoTestFailureCode) failureCode;
|
||||
- (void) incrementTestCounter: (SOGoTestFailureCode) failureCode
|
||||
afterMethod: (NSString *) methodName;
|
||||
- (void) reportException: (NSException *) exception
|
||||
method: (NSString *) methodName
|
||||
withCode: (SOGoTestFailureCode) failureCode;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSDate.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSEnumerator.h>
|
||||
#import <Foundation/NSException.h>
|
||||
@@ -31,15 +32,16 @@
|
||||
|
||||
#import "SOGoTestRunner.h"
|
||||
|
||||
#define EXPECTED_FAILURES 3
|
||||
#define EXPECTED_FAILURES 0
|
||||
|
||||
@implementation SOGoTestRunner
|
||||
|
||||
+ (SOGoTestRunner *) testRunner
|
||||
+ (SOGoTestRunner *) testRunnerWithFormat: (SOGoTestOutputFormat) reportFormat
|
||||
{
|
||||
SOGoTestRunner *testRunner;
|
||||
|
||||
testRunner = [self new];
|
||||
[testRunner setReportFormat: reportFormat];
|
||||
[testRunner autorelease];
|
||||
|
||||
return testRunner;
|
||||
@@ -53,7 +55,8 @@
|
||||
failuresCount = 0;
|
||||
errorsCount = 0;
|
||||
hasFailed = NO;
|
||||
messages = [NSMutableArray new];
|
||||
performedTests = [NSMutableArray new];
|
||||
reportFormat = SOGoTestTextOutputFormat;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -61,10 +64,15 @@
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[messages release];
|
||||
[performedTests release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) setReportFormat: (SOGoTestOutputFormat) format
|
||||
{
|
||||
reportFormat = format;
|
||||
}
|
||||
|
||||
- (int) run
|
||||
{
|
||||
NSEnumerator *allTestClasses;
|
||||
@@ -95,11 +103,16 @@
|
||||
}
|
||||
|
||||
- (void) incrementTestCounter: (SOGoTestFailureCode) failureCode
|
||||
afterMethod: (NSString *) methodName
|
||||
{
|
||||
static char failureChars[] = { '.', 'F', 'E' };
|
||||
|
||||
testCount++;
|
||||
fprintf (stderr, "%c", failureChars[failureCode]);
|
||||
if (reportFormat == SOGoTestTextOutputFormat)
|
||||
fprintf (stderr, "%c", failureChars[failureCode]);
|
||||
if (failureCode == SOGoTestFailureSuccess)
|
||||
[performedTests addObject: [NSArray arrayWithObjects: methodName, @"", nil]];
|
||||
/* else has been added by reportException method */
|
||||
}
|
||||
|
||||
- (void) reportException: (NSException *) exception
|
||||
@@ -134,13 +147,27 @@
|
||||
errorsCount++;
|
||||
}
|
||||
[message appendString: @"\n"];
|
||||
[messages addObject: message];
|
||||
|
||||
[performedTests addObject:
|
||||
[NSArray arrayWithObjects: methodName, message, [NSNumber numberWithInt: failureCode], nil]];
|
||||
}
|
||||
|
||||
- (void) displayReport
|
||||
- (void) displayTextReport
|
||||
{
|
||||
static NSString *separator = @"\n======================================================================\n";
|
||||
NSArray *performedTest;
|
||||
NSMutableArray *messages;
|
||||
NSString *reportMessage;
|
||||
NSUInteger i, max;
|
||||
|
||||
messages = [NSMutableArray new];
|
||||
max = [performedTests count];
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
performedTest = [performedTests objectAtIndex: i];
|
||||
if ([[performedTest objectAtIndex: 1] length] > 0)
|
||||
[messages addObject: [performedTest objectAtIndex: 1]];
|
||||
}
|
||||
|
||||
if ([messages count])
|
||||
{
|
||||
@@ -148,6 +175,9 @@
|
||||
reportMessage = [messages componentsJoinedByString: separator];
|
||||
fprintf (stderr, "%s", [reportMessage UTF8String]);
|
||||
}
|
||||
|
||||
[messages release];
|
||||
|
||||
fprintf (stderr,
|
||||
"\n----------------------------------------------------------------------\n"
|
||||
"Ran %d tests\n\n", testCount);
|
||||
@@ -158,4 +188,58 @@
|
||||
fprintf (stderr, "OK\n");
|
||||
}
|
||||
|
||||
- (void) displayJUnitReport
|
||||
{
|
||||
/* Follow JUnit.xsd defined by Apache-Ant project */
|
||||
NSArray *performedTest;
|
||||
NSMutableString *reportMessage;
|
||||
NSUInteger i, max;
|
||||
|
||||
/* Header */
|
||||
reportMessage = [NSMutableString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
@"<testsuite "
|
||||
@"name=\"%@\" id=\"0\" tests=\"%d\" errors=\"%d\" failures=\"%d\" "
|
||||
@"timestamp=\"%@\">\n"
|
||||
@"<desc>%@</desc>\n",
|
||||
@"SOGoUnitTests", testCount, errorsCount, failuresCount,
|
||||
[NSDate date],
|
||||
@"SOGo and SOPE Unit tests"];
|
||||
|
||||
/* Test cases */
|
||||
max = [performedTests count];
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
performedTest = [performedTests objectAtIndex: i];
|
||||
[reportMessage appendFormat: @"<testcase name=\"%@\">\n", [performedTest objectAtIndex: 0]];
|
||||
if ([[performedTest objectAtIndex: 1] length] > 0)
|
||||
{
|
||||
if ([performedTest count] > 2 && [[performedTest objectAtIndex: 2] intValue] == SOGoTestFailureFailure)
|
||||
[reportMessage appendFormat: @"<failure>%@</failure>\n", [performedTest objectAtIndex: 1]];
|
||||
else
|
||||
[reportMessage appendFormat: @"<error>%@</error>\n", [performedTest objectAtIndex: 1]];
|
||||
}
|
||||
[reportMessage appendString: @"</testcase>\n"];
|
||||
}
|
||||
|
||||
/* End */
|
||||
[reportMessage appendString: @"</testsuite>"];
|
||||
|
||||
fprintf (stdout, "%s", [reportMessage UTF8String]);
|
||||
}
|
||||
|
||||
- (void) displayReport
|
||||
{
|
||||
switch (reportFormat)
|
||||
{
|
||||
case SOGoTestTextOutputFormat:
|
||||
[self displayTextReport];
|
||||
break;
|
||||
;;
|
||||
case SOGoTestJUnitOutputFormat:
|
||||
[self displayJUnitReport];
|
||||
break;
|
||||
;;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
@"johndown@test.com", // email alone
|
||||
@"<johndown@test.com>", // email between brackets
|
||||
@"\"<johndown@test.com>\" <johndown@test.com>", // doubled
|
||||
// @"\"johndown@inverse.ca\" <johndown@test.com>", // with and without br.
|
||||
@"\"johndown@inverse.ca\" <johndown@test.com>", // with and without br.
|
||||
@"=?utf-8?q?=C3=80=C3=B1in=C3=A9oblabla?= <johndown@test.com>", // accented full name
|
||||
@"=?utf-8?q?=C3=80=C3=B1in=C3=A9oblabla_Bla_Bl=C3=A9?= <johndown@test.com>", // accented and multiword
|
||||
@"John Down \"Bla Bla\" <johndown@test.com>", // partly quoted
|
||||
@@ -45,14 +45,13 @@
|
||||
@"john", // name only, no domain
|
||||
nil ];
|
||||
NSArray *expectedAddresses = [NSArray arrayWithObjects:
|
||||
@"johndown@test.com", // email alone
|
||||
@"johndown@test.com", // email between brackets
|
||||
@"johndown@test.com", // email alone
|
||||
@"johndown@test.com", // email between brackets
|
||||
@"johndown@test.com", // doubled
|
||||
// @"\"johndown@inverse.ca\" <johndown@test.com>", // with and without br.
|
||||
@"johndown@test.com", // with and without br.
|
||||
@"johndown@test.com", // accented full name
|
||||
@"johndown@test.com", // accented
|
||||
// and multiword
|
||||
|
||||
/* NOTE: the following are wrong but tolerated for now */
|
||||
@"johndown@test.com", // partly quoted
|
||||
@"johndown@test.com", // full name + email
|
||||
@@ -72,8 +71,8 @@
|
||||
parsedRecipient = [parser parse];
|
||||
result = [parsedRecipient address];
|
||||
error = [NSString
|
||||
stringWithFormat: @"received '%@' instead of '%@' for '%@'",
|
||||
result, currentExp, rawAddress];
|
||||
stringWithFormat: @"[%d] received '%@' instead of '%@' for '%@'",
|
||||
count, result, currentExp, rawAddress];
|
||||
testWithMessage([result isEqualToString: currentExp], error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,113 +19,97 @@
|
||||
#import "SOGoTest.h"
|
||||
#import <NGMail/NGMimeMessageGenerator.h>
|
||||
|
||||
|
||||
@interface TestNGMimeMessageGenerator : SOGoTest
|
||||
@end
|
||||
|
||||
@implementation TestNGMimeMessageGenerator
|
||||
|
||||
/*
|
||||
This test is actually for SOPE library, not SOGo
|
||||
*/
|
||||
- (void) test_generateDataForHeaderField_value
|
||||
{
|
||||
NGMimeMessageGenerator *generator;
|
||||
NSArray *cases = [NSArray arrayWithObjects:
|
||||
[NSArray arrayWithObjects: @"Message-ID", @"<CADCKkzo+9X1SniJFY3yc7YGafNrmAts419RmcqNkMzd-PBqNbA@mail.gmail.com>", @"<CADCKkzo+9X1SniJFY3yc7YGafNrmAts419RmcqNkMzd-PBqNbA@mail.gmail.com>", nil],
|
||||
[NSArray arrayWithObjects: @"Content-Type",
|
||||
@"text/plain; charset=utf-8; format=flowed",
|
||||
@"text/plain; charset=utf-8; format=flowed",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-FullHeaderOneHebrewOneLatin",
|
||||
@"עs",
|
||||
@"=?utf-8?q?=D7=A2s?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-FullHeaderOneLatineOneHebrew",
|
||||
@"sע",
|
||||
@"=?utf-8?q?s=D7=A2?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-FullHeaderOneCharacterHebrew",
|
||||
@"ע",
|
||||
@"=?utf-8?q?=D7=A2?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-FullHeaderOneCharacterRussian",
|
||||
@"Б",
|
||||
@"=?utf-8?q?=D0=91?=",
|
||||
nil],
|
||||
|
||||
[NSArray arrayWithObjects: @"X-FullHeaderParameter",
|
||||
@"parameter=ע",
|
||||
@"parameter==?utf-8?q?=D7=A2?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-MixedHeaderParameters",
|
||||
@"plain; parameter=ע; parameter-plain; parameter2=ea",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=;\n parameter-plain; parameter2=ea",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-MixedHeaderAndNoParameter",
|
||||
@"plain; parameter=ע; parameter-plain; ע",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=; parameter-plain;\n =?utf-8?q?=D7=A2?=",
|
||||
nil],
|
||||
|
||||
[NSArray arrayWithObjects: @"X-MixedHeaderAndTwoParameter",
|
||||
@"plain; parameter=ע; parameter-plain; z=ע",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=; parameter-plain;\n z==?utf-8?q?=D7=A2?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-MixedHeaderExtrablanks",
|
||||
@"plain; parameter=ע; parameter 2spaces; parameter2=ea",
|
||||
@"plain;\n \\ parameter==?utf-8?q?=D7=A2?=;\n parameter 2spaces; parameter2=ea",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"X-Encoded-Unbalanced-Paramter-Quote",
|
||||
@"text/plain; name=\"ע",
|
||||
@"text/plain;\n name==?utf-8?q?=22=D7=A2?=",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"content-type",
|
||||
@"text/plain; name=\"АБВГДЕЁЖЗИЙ, КЛМНОПРСТУФ y ЦЧШЩЪЫЬЭЮЯ.txt\"",
|
||||
@"text/plain;\n name=\"=?utf-8?q?=D0=90=D0=91=D0=92=D0=93=D0=94=D0=95=D0=81=D0=96=D0=97=D0=98=D0=99=2C_=D0=9A=D0=9B=D0=9C=D0=9D=D0=9E=D0=9F=D0=A0=D0=A1=D0=A2=D0=A3=D0=A4_y_=D0=A6=D0=A7=D0=A8=D0=A9=D0=AA=D0=AB=D0=AC=D0=AD=D0=AE=D0=AF=2Etxt?=\"",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"content-disposition",
|
||||
@"attachment; filename=\"АБВГДЕЁЖЗИЙ, КЛМНОПРСТУФ y ЦЧШЩЪЫЬЭЮЯ.txt\"",
|
||||
@"attachment;\n filename=\"=?utf-8?q?=D0=90=D0=91=D0=92=D0=93=D0=94=D0=95=D0=81=D0=96=D0=97=D0=98=D0=99=2C_=D0=9A=D0=9B=D0=9C=D0=9D=D0=9E=D0=9F=D0=A0=D0=A1=D0=A2=D0=A3=D0=A4_y_=D0=A6=D0=A7=D0=A8=D0=A9=D0=AA=D0=AB=D0=AC=D0=AD=D0=AE=D0=AF=2Etxt?=\"",
|
||||
nil],
|
||||
[NSArray arrayWithObjects: @"content-length", @"2912", @"2912", nil],
|
||||
[NSArray arrayWithObjects: @"content-transfer-encoding", @"quoted-printable", @"quoted-printable", nil],
|
||||
nil
|
||||
];
|
||||
NSEnumerator *enumerator;
|
||||
NSArray *testCase;
|
||||
[NSArray arrayWithObjects:@"Message-ID",
|
||||
@"<CADCKkzo+9X1SniJFY3yc7YGafNrmAts419RmcqNkMzd-PBqNbA@mail.gmail.com>",
|
||||
@"<CADCKkzo+9X1SniJFY3yc7YGafNrmAts419RmcqNkMzd-PBqNbA@mail.gmail.com>", nil],
|
||||
[NSArray arrayWithObjects:@"Content-Type",
|
||||
@"text/plain; charset=utf-8; format=flowed",
|
||||
@"text/plain; charset=utf-8; format=flowed", nil],
|
||||
[NSArray arrayWithObjects:@"X-FullHeaderOneHebrewOneLatin",
|
||||
@"עs",
|
||||
@"=?utf-8?q?=D7=A2s?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-FullHeaderOneLatineOneHebrew",
|
||||
@"sע",
|
||||
@"=?utf-8?q?s=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-FullHeaderOneCharacterHebrew",
|
||||
@"ע",
|
||||
@"=?utf-8?q?=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-FullHeaderOneCharacterRussian",
|
||||
@"Б",
|
||||
@"=?utf-8?q?=D0=91?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-FullHeaderParameter",
|
||||
@"parameter=ע",
|
||||
@"parameter==?utf-8?q?=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-MixedHeaderParameters",
|
||||
@"plain; parameter=ע; parameter-plain; parameter2=ea",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=;\n parameter-plain; parameter2=ea", nil],
|
||||
[NSArray arrayWithObjects:@"X-MixedHeaderAndNoParameter",
|
||||
@"plain; parameter=ע; parameter-plain; ע",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=; parameter-plain;\n =?utf-8?q?=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-MixedHeaderAndTwoParameter",
|
||||
@"plain; parameter=ע; parameter-plain; z=ע",
|
||||
@"plain;\n parameter==?utf-8?q?=D7=A2?=; parameter-plain;\n z==?utf-8?q?=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"X-MixedHeaderExtrablanks",
|
||||
@"plain; parameter=ע; parameter 2spaces; parameter2=ea",
|
||||
@"plain;\n \\ parameter==?utf-8?q?=D7=A2?=;\n parameter 2spaces; parameter2=ea", nil],
|
||||
[NSArray arrayWithObjects:@"X-Encoded-Unbalanced-Paramter-Quote",
|
||||
@"text/plain; name=\"ע",
|
||||
@"text/plain;\n name==?utf-8?q?=22=D7=A2?=", nil],
|
||||
[NSArray arrayWithObjects:@"content-type",
|
||||
@"text/plain; name=\"АБВГДЕЁЖЗИЙ, КЛМНОПРСТУФ y ЦЧШЩЪЫЬЭЮЯ.txt\"",
|
||||
@"text/plain;\n name=\"=?utf-8?q?=D0=90=D0=91=D0=92=D0=93=D0=94=D0=95=D0=81=D0=96=D0=97=D0=98=D0=99=2C_=D0=9A=D0"
|
||||
@"=9B=D0=9C=D0=9D=D0=9E=D0=9F=D0=A0=D0=A1=D0=A2=D0=A3=D0=A4_y_=D0=A6=D0=A7=D0=A8"
|
||||
@"=D0=A9=D0=AA=D0=AB=D0=AC=D0=AD=D0=AE=D0=AF=2Etxt?=\"", nil],
|
||||
[NSArray arrayWithObjects:@"content-disposition",
|
||||
@"attachment; filename=\"АБВГДЕЁЖЗИЙ, КЛМНОПРСТУФ y ЦЧШЩЪЫЬЭЮЯ.txt\"",
|
||||
@"attachment;\n filename=\"=?utf-8?q?=D0=90=D0=91=D0=92=D0=93=D0=94=D0=95=D0=81=D0=96=D0=97=D0=98=D0=99=2C_=D0=9A=D0"
|
||||
@"=9B=D0=9C=D0=9D=D0=9E=D0=9F=D0=A0=D0=A1=D0=A2=D0=A3=D0=A4_y_=D0=A6=D0=A7=D0=A8"
|
||||
@"=D0=A9=D0=AA=D0=AB=D0=AC=D0=AD=D0=AE=D0=AF=2Etxt?=\"", nil],
|
||||
[NSArray arrayWithObjects:@"content-length", @"2912", @"2912", nil],
|
||||
[NSArray arrayWithObjects:@"content-transfer-encoding", @"quoted-printable", @"quoted-printable", nil],
|
||||
nil
|
||||
];
|
||||
|
||||
[NGMimeMessageGenerator initialize];
|
||||
generator = [[NGMimeMessageGenerator alloc] init];
|
||||
NGMimeMessageGenerator *generator = [[NGMimeMessageGenerator alloc] init];
|
||||
[generator autorelease];
|
||||
|
||||
enumerator = [cases objectEnumerator];
|
||||
while ((testCase = [enumerator nextObject]) != nil)
|
||||
for (NSArray *testCase in cases)
|
||||
{
|
||||
NSData *result;
|
||||
NSMutableData *resultWithNulByte;
|
||||
NSString *header = [testCase objectAtIndex: 0];
|
||||
NSData *headerData = [testCase objectAtIndex: 1];
|
||||
NSString *expected = [testCase objectAtIndex: 2];
|
||||
result = [generator generateDataForHeaderField: header
|
||||
value: headerData];
|
||||
if (result == nil)
|
||||
result = [@"[nil]" dataUsingEncoding: NSUTF8StringEncoding];
|
||||
NSData *result = [generator generateDataForHeaderField: header
|
||||
value: headerData];
|
||||
if (result == nil)
|
||||
result = [@"[nil]" dataUsingEncoding: NSUTF8StringEncoding];
|
||||
|
||||
resultWithNulByte = [result mutableCopy];
|
||||
[resultWithNulByte appendBytes: "\0" length: 1];
|
||||
NSMutableData *resultWithNulByte = [result mutableCopy];
|
||||
[resultWithNulByte appendBytes: "\0" length: 1];
|
||||
NSString *resultString = [NSString stringWithCString:[resultWithNulByte bytes]];
|
||||
|
||||
|
||||
BOOL testResult = [resultString isEqualToString: expected];
|
||||
|
||||
NSString *diff = [self stringFromDiffBetween: [NSString stringWithString: resultString]
|
||||
and: [NSString stringWithString: expected]];
|
||||
NSString *testErrorMsg = [NSString
|
||||
stringWithFormat: @">> For %@ header received:\n%@[END]\n>> instead of:\n%@[END]\n>> for:\n%@\n>> diff:\n%@\n>> lengthReceived: %lu lengthExpected: %lu",
|
||||
header,
|
||||
resultString,
|
||||
expected,
|
||||
headerData,
|
||||
diff,
|
||||
[resultString length],
|
||||
[expected length]
|
||||
];
|
||||
NSString *diff = [self stringFromDiffBetween: resultString and: expected];
|
||||
|
||||
NSString *testErrorMsg = [NSString stringWithFormat:
|
||||
@">> For %@ header received:\n%@[END]\n"
|
||||
@">> instead of:\n%@[END]\n"
|
||||
@">> for:\n%@\n>> diff:\n%@\n"
|
||||
@">> lengthReceived: %lu lengthExpected: %lu", header, resultString,
|
||||
expected, headerData, diff, [resultString length], [expected length]];
|
||||
|
||||
testWithMessage(testResult, testErrorMsg);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
/* TestNSString+Utilities.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2011 Inverse inc
|
||||
* Copyright (C) 2014 Zentyal
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
* Jesús García Sáez <jgarcia@zentyal.com>
|
||||
*
|
||||
* 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
|
||||
@@ -23,7 +25,7 @@
|
||||
/* This file is encoded in utf-8. */
|
||||
|
||||
#import <SOGo/NSString+Utilities.h>
|
||||
|
||||
#import <Foundation/NSNull.h>
|
||||
#import "SOGoTest.h"
|
||||
|
||||
@interface TestNSString_plus_Utilities : SOGoTest
|
||||
@@ -52,7 +54,7 @@
|
||||
NSString *secret = @"this is a secret";
|
||||
NSString *password = @"qwerty";
|
||||
NSString *encresult, *decresult;
|
||||
|
||||
|
||||
encresult = [secret encryptWithKey: nil];
|
||||
failIf(encresult != nil);
|
||||
encresult = [secret encryptWithKey: @""];
|
||||
@@ -70,4 +72,28 @@
|
||||
failIf(![decresult isEqualToString: secret]);
|
||||
}
|
||||
|
||||
- (void) test_objectFromJSONString_single_values
|
||||
{
|
||||
NSString *json, *error;
|
||||
NSInteger expected = 1;
|
||||
id result;
|
||||
|
||||
// Decode null
|
||||
json = [NSString stringWithFormat:@"null"];
|
||||
result = [json objectFromJSONString];
|
||||
testWithMessage(result == [NSNull null], @"Result should be null");
|
||||
|
||||
// Decode number
|
||||
json = [NSString stringWithFormat:@"1"];
|
||||
result = [json objectFromJSONString];
|
||||
error = [NSString stringWithFormat: @"result %@ != expected %d",
|
||||
result, expected];
|
||||
testWithMessage((long)result != (long)expected, error);
|
||||
|
||||
// Decode string
|
||||
json = [NSString stringWithFormat:@"\"kill me\""];
|
||||
result = [json objectFromJSONString];
|
||||
testEquals(result, @"kill me");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSLocale.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
|
||||
@@ -71,6 +72,8 @@
|
||||
{
|
||||
SBJsonParser *parser;
|
||||
id result;
|
||||
NSDecimalNumber *obtained, *expected;
|
||||
NSDictionary *locale;
|
||||
|
||||
parser = [SBJsonParser new];
|
||||
[parser autorelease];
|
||||
@@ -80,17 +83,20 @@
|
||||
|
||||
result = [parser objectWithString: @"[ 0 ]"];
|
||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: 0]]);
|
||||
|
||||
|
||||
result = [parser objectWithString: @"[ -1 ]"];
|
||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithInt: -1]]);
|
||||
|
||||
|
||||
locale = [NSDictionary dictionaryWithObject: @"." forKey: NSLocaleDecimalSeparator];
|
||||
result = [parser objectWithString: @"[ 12.3456 ]"];
|
||||
testEquals ([result objectAtIndex: 0],
|
||||
[NSDecimalNumber decimalNumberWithString: @"12.3456"]);
|
||||
obtained = [result objectAtIndex: 0];
|
||||
expected = [NSDecimalNumber decimalNumberWithString: @"12.3456" locale: locale];
|
||||
test ([obtained compare: expected] == NSOrderedSame);
|
||||
|
||||
result = [parser objectWithString: @"[ -312.3456 ]"];
|
||||
testEquals (result, [NSArray arrayWithObject: [NSNumber numberWithDouble: -312.3456]]);
|
||||
obtained = [result objectAtIndex: 0];
|
||||
expected = [NSDecimalNumber decimalNumberWithString: @"-312.3456" locale: locale];
|
||||
test ([obtained compare: expected] == NSOrderedSame);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
/* TODO: this test fails for obscure reasons, but test__occurrenceForDate_byRRule_ does not, which
|
||||
is a good sign */
|
||||
/*
|
||||
- (void) test_occurrenceForDate_
|
||||
{
|
||||
NSString *periods[] = { (@"BEGIN:DAYLIGHT\r\n"
|
||||
@@ -84,7 +85,7 @@
|
||||
@" delta = %ld", count, delta]));
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
- (void) test__occurrenceForDate_byRRule_
|
||||
{
|
||||
/* all rules are happening on 2010-03-14 */
|
||||
|
||||
+85
-2
@@ -21,15 +21,91 @@
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
#import "SOGoTestRunner.h"
|
||||
|
||||
int main()
|
||||
static void Usage ()
|
||||
{
|
||||
/* Print usage and exit */
|
||||
NSLog (@"sogo-tests [-h|--help] [-f|--format=text|junit]\n"
|
||||
@" -h, --help\t\t\tdisplay this help information\n"
|
||||
@" -f, --format=text|junit\treport format. Default: text\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static SOGoTestOutputFormat ParseArguments (NSArray *args)
|
||||
{
|
||||
/* Parse arguments from command line */
|
||||
BOOL help = NO;
|
||||
NSString *arg, *format = nil;
|
||||
NSUInteger i, max;
|
||||
SOGoTestOutputFormat outFormat;
|
||||
|
||||
max = [args count];
|
||||
/* Skip program name */
|
||||
i = 1;
|
||||
while (!help && i < max)
|
||||
{
|
||||
arg = [args objectAtIndex: i];
|
||||
if ([arg isEqualToString: @"-f"] || [arg isEqualToString: @"--format"])
|
||||
{
|
||||
NSArray *validFormats = [NSArray arrayWithObjects: @"text", @"junit", nil];
|
||||
i++;
|
||||
if (i < max)
|
||||
{
|
||||
arg = [args objectAtIndex: i];
|
||||
if ([validFormats containsObject: arg])
|
||||
format = arg;
|
||||
else
|
||||
{
|
||||
help = YES;
|
||||
NSLog (@"Invalid format: '%@'. Use 'text' or 'junit'", arg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog (@"Missing format argument");
|
||||
help = YES;
|
||||
}
|
||||
}
|
||||
else if ([arg isEqualToString: @"-h"]
|
||||
|| [arg isEqualToString: @"--help"])
|
||||
help = YES;
|
||||
else
|
||||
{
|
||||
NSLog (@"Invalid command line argument: '%@'", arg);
|
||||
help = YES;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
if (help)
|
||||
{
|
||||
Usage ();
|
||||
}
|
||||
|
||||
if (format)
|
||||
{
|
||||
if ([format isEqualToString: @"text"])
|
||||
outFormat = SOGoTestTextOutputFormat;
|
||||
else if ([format isEqualToString: @"junit"])
|
||||
outFormat = SOGoTestJUnitOutputFormat;
|
||||
}
|
||||
else
|
||||
outFormat = SOGoTestTextOutputFormat;
|
||||
|
||||
return outFormat;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char *env[])
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
int rc;
|
||||
NSDictionary *defaults;
|
||||
NSUserDefaults *ud;
|
||||
SOGoTestOutputFormat reportFormat;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
@@ -42,7 +118,14 @@ int main()
|
||||
forName: @"sogo-tests-volatile"];
|
||||
[ud addSuiteNamed: @"sogo-tests-volatile"];
|
||||
|
||||
rc = [[SOGoTestRunner testRunner] run];
|
||||
/* Process arguments */
|
||||
[NSProcessInfo initializeWithArguments: argv
|
||||
count: argc
|
||||
environment: env];
|
||||
|
||||
reportFormat = ParseArguments ([[NSProcessInfo processInfo] arguments]);
|
||||
|
||||
rc = [[SOGoTestRunner testRunnerWithFormat: reportFormat] run];
|
||||
[pool release];
|
||||
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user