From 1fa8dbf31e6f8ad2152e73975292c2047637277a Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 26 Aug 2010 15:27:25 +0000 Subject: [PATCH] Monotone-Parent: f6c7d4502b60b66206223a822d4911218f4bbacf Monotone-Revision: 5fc2d7189c72402367ef086530caefea5fa4fa97 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-08-26T15:27:25 Monotone-Branch: ca.inverse.sogo --- Tests/Unit/GNUmakefile | 7 +- .../TestNGMimeAddressHeaderFieldGenerator.m | 87 +++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Tests/Unit/TestNGMimeAddressHeaderFieldGenerator.m diff --git a/Tests/Unit/GNUmakefile b/Tests/Unit/GNUmakefile index e6afe78c3..2e01b879e 100644 --- a/Tests/Unit/GNUmakefile +++ b/Tests/Unit/GNUmakefile @@ -17,7 +17,9 @@ $(TEST_TOOL)_OBJC_FILES += \ TestiCalTimeZonePeriod.m \ TestiCalRecurrenceCalculator.m \ \ - TestBSJSONAdditions.m + TestBSJSONAdditions.m \ + \ + TestNGMimeAddressHeaderFieldGenerator.m TOOL_NAME = $(TEST_TOOL) @@ -25,8 +27,9 @@ ADDITIONAL_INCLUDE_DIRS += \ -D_GNU_SOURCE -I../SOPE/ -I../SoObjects/ -I../UI/ ADDITIONAL_LIB_DIRS += \ - -L../SoObjects/SOGo -lSOGo + -L../SoObjects/SOGo -lSOGo -lNGMime -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/tool.make -include GNUmakefile.postamble + diff --git a/Tests/Unit/TestNGMimeAddressHeaderFieldGenerator.m b/Tests/Unit/TestNGMimeAddressHeaderFieldGenerator.m new file mode 100644 index 000000000..538cd2577 --- /dev/null +++ b/Tests/Unit/TestNGMimeAddressHeaderFieldGenerator.m @@ -0,0 +1,87 @@ +/* TestNGMimeAddressHeaderFieldGenerator.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 "SOGoTest.h" + +@interface TestNGMimeAddressHeaderFieldGenerator : SOGoTest +@end + +@implementation TestNGMimeAddressHeaderFieldGenerator + +/* important: this file must be encoded in iso-8859-1, due to issues with the + objc compiler */ +- (void) test_generateDataForHeaderFieldNamed_value_ +{ + NSString *rawAddresses[] + = { @"wolfgang@test.com", // email alone + @"", // email between brackets + @"\"\" ", // doubled + @"\"wolfgang@inverse.ca\" ", // with and without br. + @"Àñinéoblabla ", // accented full name + @"Àñinéoblabla Bla Blé ", // accented and multiword + @"Wolfgang Sourdeau \"Bla Bla\" ", // partly quoted + @"Wolfgang Sourdeau ", // full name + email + nil }; + NSString *expectedAddresses[] + = { @"wolfgang@test.com", // email alone + @"wolfgang@test.com", // email between brackets + @"\"\" ", // doubled + @"\"wolfgang@inverse.ca\" ", // with and without br. + @"=?utf-8?q?=C3=80=C3=B1in=C3=A9oblabla?= ", // accented full name + @"=?utf-8?q?=C3=80=C3=B1in=C3=A9oblabla_Bla_Bl=C3=A9?= ", // accented + // and multiword + + /* NOTE: the following are wrong but tolerated for now */ + @"Wolfgang Sourdeau \"Bla Bla\" ", // partly quoted + @"Wolfgang Sourdeau ", // full name + email + nil }; + NSString **currentRaw, **currentExp, *result, *error; + NGMimeAddressHeaderFieldGenerator *generator; + + generator = [NGMimeAddressHeaderFieldGenerator headerFieldGenerator]; + + currentRaw = rawAddresses; + currentExp = expectedAddresses; + while (*currentRaw) + { + result + = [[NSString alloc] + initWithData: + [generator generateDataForHeaderFieldNamed: @"from" + value: *currentRaw] + encoding: NSASCIIStringEncoding]; + + error = [NSString + stringWithFormat: @"received '%@' instead of '%@' for '%@'", + result, *currentExp, *currentRaw]; + testWithMessage([result isEqualToString: *currentExp], error); + + [result release]; + currentRaw++; + currentExp++; + } +} + +@end +