sogo/Tests/Unit/TestRTFHandler.m

141 lines
4.1 KiB
Mathematica
Raw Normal View History

2014-07-30 21:24:25 +02:00
/* TestRTFHandler.m
*
* Copyright (C) 2014 Zentyal
*
* Author: Jesús García Sáez <jgarcia@zentyal.org>
*
* 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.
*/
/* This file is encoded in utf-8. */
#import "RTFHandler.h"
#import <Foundation/NSFileManager.h>
#import "SOGoTest.h"
@interface TestRTFHandler : SOGoTest
@end
@implementation TestRTFHandler
- (NSString *) rtf2html: (NSData *) rtf
2014-07-30 21:24:25 +02:00
{
NSString *html;
2014-07-30 21:24:25 +02:00
if (!rtf) return @"nil";
RTFHandler *handler = [[RTFHandler alloc] initWithData: rtf];
2014-07-30 21:24:25 +02:00
NSMutableData *data2 = [handler parse];
html = [[NSString alloc] initWithData: data2 encoding: NSUTF8StringEncoding];
if (html == nil) {
html = [[NSString alloc] initWithData: data2 encoding: NSASCIIStringEncoding];
}
if (html == nil) {
html = [[NSString alloc] initWithData: data2 encoding: NSISOLatin1StringEncoding];
}
if (html == nil) {
NSString *error = [NSString stringWithFormat: @"Couldn't convert parsed data"];
testWithMessage(false, error);
}
2014-07-30 21:24:25 +02:00
return html;
}
- (NSData *) dataWithContentsOfFixture: (NSString*) name
2014-07-30 21:24:25 +02:00
{
NSString *file_path = [NSString stringWithFormat: @"Fixtures/%@", name];
2014-07-30 21:24:25 +02:00
if(![[NSFileManager defaultManager] fileExistsAtPath: file_path]) {
NSString *error = [NSString stringWithFormat: @"File %@ doesn't exist", file_path];
testWithMessage(false, error);
}
return [NSData dataWithContentsOfFile: file_path];
}
- (NSData *) dataWithContentsOfZentyalCrash: (unsigned int) number
{
NSString *fixture = [NSString stringWithFormat: @"zentyal_crash_%u.rtf", number];
return [self dataWithContentsOfFixture: fixture];
2014-07-30 21:24:25 +02:00
}
- (void) checkDoesNotCrash: (unsigned int) number
2014-07-30 21:24:25 +02:00
{
// FIXME fork
[self rtf2html: [self dataWithContentsOfZentyalCrash: number]];
2014-07-30 21:24:25 +02:00
}
- (void) checkHTMLConversionOfRTFFile: (NSString*) file
againstExpectedHTML: (NSString*) expected
{
NSData *in = nil;
NSString *out = nil, *error = nil;
in = [self dataWithContentsOfFixture: file];
out = [self rtf2html: in];
error = [NSString stringWithFormat:
@"Html from rtf result is not what we expected.\nActual:\n%@\n Expected:\n%@\n", out, expected];
testWithMessage([out isEqualToString: expected], error);
}
2014-07-30 21:24:25 +02:00
- (void) test_zentyal_crash_2058
{
[self checkDoesNotCrash: 2058];
2014-07-30 21:24:25 +02:00
// Output is not correct... but the original issue was segfault
}
2014-08-07 19:07:41 +02:00
- (void) test_zentyal_crash_2089
{
NSData *in = nil;
NSString *out = nil, *error = nil, *expected = nil;
2014-08-07 19:07:41 +02:00
in = [self dataWithContentsOfZentyalCrash: 2089];
2014-08-07 19:07:41 +02:00
expected = @"<html><meta charset='utf-8'><body><font color=\"#000000\">Lorem Ipsum</font></body></html>";
out = [self rtf2html: in];
error = [NSString stringWithFormat:
@"Html from rtf result `%@` is not what we expected", out];
testWithMessage([out isEqualToString: expected], error);
}
2014-07-30 21:24:25 +02:00
2014-12-23 10:32:05 +01:00
- (void) test_zentyal_crash_6330
{
[self checkDoesNotCrash: 6330];
2014-12-23 10:32:05 +01:00
}
- (void) test_zentyal_crash_8346
{
[self checkDoesNotCrash: 8346];
}
- (void) test_zentyal_crash_6977
{
[self checkDoesNotCrash: 6977];
}
2015-04-16 16:20:57 +02:00
- (void) test_zentyal_crash_7067
{
[self checkDoesNotCrash: 7067];
}
- (void) test_mini_russian
{
NSString *file =@"mini_russian.rtf";
NSString *expected=@"<html><meta charset='utf-8'><body><font face=\"Calibri\"><font face=\"Calibri Cyr\"><font color=\"#000000\">XXзык польски, польщизнаXX</font></font></font></body></html>";
[self checkHTMLConversionOfRTFFile: file
againstExpectedHTML: expected];
2015-04-16 16:20:57 +02:00
}
2014-07-30 21:24:25 +02:00
@end