Replaced TestBSJSONAdditions by TestSBJsonParser.
Monotone-Parent: a74b60fda113d212de9a6c3b5429b105fa0dfd5f Monotone-Revision: abc7b5684e08c490b08ff31f36d8b78db35016a1 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2010-11-11T18:13:39 Monotone-Branch: ca.inverse.sogomaint-2.0.2
parent
abec9aeb20
commit
d2073d7f03
|
@ -17,7 +17,7 @@ $(TEST_TOOL)_OBJC_FILES += \
|
|||
TestiCalTimeZonePeriod.m \
|
||||
TestiCalRecurrenceCalculator.m \
|
||||
\
|
||||
TestBSJSONAdditions.m \
|
||||
TestSBJsonParser.m \
|
||||
\
|
||||
TestNGMimeAddressHeaderFieldGenerator.m
|
||||
|
||||
|
@ -27,7 +27,7 @@ ADDITIONAL_INCLUDE_DIRS += \
|
|||
-D_GNU_SOURCE -I../SOPE/ -I../SoObjects/ -I../UI/
|
||||
|
||||
ADDITIONAL_LIB_DIRS += \
|
||||
-L../SoObjects/SOGo -lSOGo -lNGMime
|
||||
-L../SoObjects/SOGo -lSOGo -lNGMime -lNGCards -lGDLContentStore
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
/* 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 <Foundation/NSValue.h>
|
||||
|
||||
#import "SOGo/NSScanner+BSJSONAdditions.h"
|
||||
#import "SOGo/NSDictionary+BSJSONAdditions.h"
|
||||
|
||||
#import "SOGo/NSString+Utilities.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++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) test_scanJSONNumber
|
||||
{
|
||||
NSScanner *testScanner;
|
||||
NSNumber *result;
|
||||
|
||||
testScanner = [NSScanner scannerWithString: @""];
|
||||
[testScanner scanJSONNumber: &result];
|
||||
testEquals (result, nil);
|
||||
|
||||
testScanner = [NSScanner scannerWithString: @"0"];
|
||||
[testScanner scanJSONNumber: &result];
|
||||
testEquals (result, [NSNumber numberWithInt: 0]);
|
||||
|
||||
testScanner = [NSScanner scannerWithString: @"-1"];
|
||||
[testScanner scanJSONNumber: &result];
|
||||
testEquals (result, [NSNumber numberWithInt: -1]);
|
||||
|
||||
testScanner = [NSScanner scannerWithString: @"12.3456"];
|
||||
[testScanner scanJSONNumber: &result];
|
||||
testEquals (result, [NSNumber numberWithDouble: 12.3456]);
|
||||
|
||||
testScanner = [NSScanner scannerWithString: @"-312.3456"];
|
||||
[testScanner scanJSONNumber: &result];
|
||||
testEquals (result, [NSNumber numberWithDouble: -312.3456]);
|
||||
}
|
||||
|
||||
@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
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/* TestSBJsonParser.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 <Foundation/NSValue.h>
|
||||
|
||||
#import <SBJson/SBJsonParser.h>
|
||||
|
||||
#import "SOGo/NSString+Utilities.h"
|
||||
|
||||
#import "SOGoTest.h"
|
||||
|
||||
@interface TestSBJsonParser : SOGoTest
|
||||
@end
|
||||
|
||||
@implementation TestSBJsonParser
|
||||
|
||||
- (void) test_parseJSONString
|
||||
{
|
||||
SBJsonParser *parser;
|
||||
NSString *currentString, *expected, *error;
|
||||
NSObject *resultObject;
|
||||
int count;
|
||||
NSString *testStrings[] = { @"\"\\\\\"", @"\\",
|
||||
@"\"\\u0041\"", @"A",
|
||||
@"\"\\u000A\"", @"\n",
|
||||
@"\"\\u000a\"", @"\n",
|
||||
nil };
|
||||
|
||||
parser = [SBJsonParser new];
|
||||
[parser autorelease];
|
||||
count = 0;
|
||||
while ((currentString = testStrings[count * 2]))
|
||||
{
|
||||
resultObject = [parser objectWithString: currentString];
|
||||
expected = testStrings[count * 2 + 1];
|
||||
error = [NSString stringWithFormat:
|
||||
@"objects '%@' and '%@' differs (count: %d)",
|
||||
expected, resultObject, count];
|
||||
testEqualsWithMessage(expected, resultObject, error);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) test_parseJSONNumber
|
||||
{
|
||||
SBJsonParser *parser;
|
||||
NSObject *result;
|
||||
|
||||
parser = [SBJsonParser new];
|
||||
[parser autorelease];
|
||||
|
||||
result = [parser objectWithString: @""];
|
||||
testEquals (result, nil);
|
||||
|
||||
result = [parser objectWithString: @"0"];
|
||||
testEquals (result, [NSNumber numberWithInt: 0]);
|
||||
|
||||
result = [parser objectWithString: @"-1"];
|
||||
testEquals (result, [NSNumber numberWithInt: -1]);
|
||||
|
||||
result = [parser objectWithString: @"12.3456"];
|
||||
testEquals (result, [NSNumber numberWithDouble: 12.3456]);
|
||||
|
||||
result = [parser objectWithString: @"-312.3456"];
|
||||
testEquals (result, [NSNumber numberWithDouble: -312.3456]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue