From 063091f72a93383253734d789a9866737df7c4fe Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 7 Jan 2010 16:37:36 +0000 Subject: [PATCH] Monotone-Parent: f36c1a3969587db790c18c96805411a8dfe38f00 Monotone-Revision: 1e9c4371dcc93fa8a7f07290f63d3623a276fb8e Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-01-07T16:37:36 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 +++ SoObjects/SOGo/NSScanner+BSJSONAdditions.m | 2 +- UnitTests/GNUmakefile | 12 ++++- UnitTests/SOGoTest.h | 3 +- UnitTests/TestBSJSONAdditions.m | 62 ++++++++++++++++++++++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 UnitTests/TestBSJSONAdditions.m diff --git a/ChangeLog b/ChangeLog index 19fe646eb..35ef54d4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-01-07 Wolfgang Sourdeau + * SoObjects/SOGo/NSScanner+BSJSONAdditions.m (-scanJSONString): we + now accept lowercase characters in characters coded in UCN. + + * UnitTests/TestBSJSONAdditions.m: new unit test for + BSJSONAdditions. + * UnitTests/SOGoTest.m: base class for our unit test testcases. Similar to JUnit and family. diff --git a/SoObjects/SOGo/NSScanner+BSJSONAdditions.m b/SoObjects/SOGo/NSScanner+BSJSONAdditions.m index b23138f30..6f9f41efd 100644 --- a/SoObjects/SOGo/NSScanner+BSJSONAdditions.m +++ b/SoObjects/SOGo/NSScanner+BSJSONAdditions.m @@ -162,7 +162,7 @@ NSString *jsonNullString = @"null"; /* START Updated code modified from code fix submitted by Bill Garrison - March 28, 2006 - http://www.standardorbit.net */ NSScanner *hexScanner = [NSScanner scannerWithString:digits]; NSString *verifiedHexDigits; - NSCharacterSet *hexDigitSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEF"]; + NSCharacterSet *hexDigitSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFabcdef"]; if (NO == [hexScanner scanCharactersFromSet:hexDigitSet intoString:&verifiedHexDigits]) return NO; if (4 != [verifiedHexDigits length]) diff --git a/UnitTests/GNUmakefile b/UnitTests/GNUmakefile index bdc05f509..94a5cf204 100644 --- a/UnitTests/GNUmakefile +++ b/UnitTests/GNUmakefile @@ -1,5 +1,7 @@ # GNUstep makefile +debug=yes + include ../config.make include $(GNUSTEP_MAKEFILES)/common.make include ../Version @@ -9,10 +11,18 @@ $(TEST_TOOL)_INSTALL_DIR = $(SOGO_ADMIN_TOOLS) $(TEST_TOOL)_OBJC_FILES += \ sogo-tests.m \ \ - SOGoTest.m + SOGoTest.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 diff --git a/UnitTests/SOGoTest.h b/UnitTests/SOGoTest.h index 5b8ba515d..09b289834 100644 --- a/UnitTests/SOGoTest.h +++ b/UnitTests/SOGoTest.h @@ -24,6 +24,7 @@ #define SOGOTEST_H #import +#import @class NSArray; @class NSMutableArray; @@ -71,7 +72,7 @@ typedef enum { #define testEquals(a,b) \ testWithMessage(([a isEqual: b]), \ - ([NSString stringWithFormat: @"objects %@ and %@ differs", a, b])) + ([NSString stringWithFormat: @"objects '%@' and '%@' differs", (a), (b)])) #define testEqualsWithMessage(a,b,m) \ testWithMessage(([a isEqual: b]), (m)) diff --git a/UnitTests/TestBSJSONAdditions.m b/UnitTests/TestBSJSONAdditions.m new file mode 100644 index 000000000..2a35328f7 --- /dev/null +++ b/UnitTests/TestBSJSONAdditions.m @@ -0,0 +1,62 @@ +/* BSJSONAdditions.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * 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 +#import + +#import + +#import "SOGoTest.h" + +@interface TestBSJSONAdditions : SOGoTest +@end + +@implementation TestBSJSONAdditions + +- (void) test_scanJSONString +{ + NSScanner *testScanner; + NSString *testStrings[] = { @"\"\\\\\"", @"\\", + @"\"\\u0041\"", @"A", + @"\"\\u000A\"", @"\n", + @"\"\\u000a\"", @"\n", + nil }; + NSString *currentString, *expected, *error; + NSMutableString *resultString; + int count; + + 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