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 +