From de1e84d977dd7be1f245a1df823d1d25d53ae87f Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Tue, 4 Nov 2014 22:28:55 -0800 Subject: Added more unit tests --- unittest/unittest.mm | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'unittest/unittest.mm') diff --git a/unittest/unittest.mm b/unittest/unittest.mm index b125231f..fa1798d1 100644 --- a/unittest/unittest.mm +++ b/unittest/unittest.mm @@ -87,17 +87,20 @@ NSString * _builderOutputPath; NSString * _parserOutputPath; NSString * _charsetDetectionPath; + NSString * _summaryDetectionPath; + NSString * _summaryDetectionOutputPath; } - (void)setUp { [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. _mainPath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"data"]; _builderPath = [_mainPath stringByAppendingPathComponent:@"builder/input"]; _builderOutputPath = [_mainPath stringByAppendingPathComponent:@"builder/output"]; _parserPath = [_mainPath stringByAppendingPathComponent:@"parser/input"]; _parserOutputPath = [_mainPath stringByAppendingPathComponent:@"parser/output"]; _charsetDetectionPath = [_mainPath stringByAppendingPathComponent:@"charset-detection"]; + _summaryDetectionPath = [_mainPath stringByAppendingPathComponent:@"summary/input"]; + _summaryDetectionOutputPath = [_mainPath stringByAppendingPathComponent:@"summary/output"]; } - (void)tearDown { @@ -210,4 +213,35 @@ } } +- (void)testSummary { + NSArray * list = [[NSFileManager defaultManager] subpathsAtPath:_summaryDetectionPath]; + for(NSString * name in list) { + NSString * path = [_summaryDetectionPath stringByAppendingPathComponent:name]; + BOOL isDirectory = NO; + [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]; + if (isDirectory) { + continue; + } + NSData * data = [NSData dataWithContentsOfFile:path]; + MCOMessageParser * parser = [MCOMessageParser messageParserWithData:data]; + NSString * str = [parser plainTextRendering]; + +// NSString * outputPath = [@"/Users/hoa/mc2-results/summary" stringByAppendingPathComponent:name]; +// outputPath = [[outputPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"txt"]; +// NSString * directory = [outputPath stringByDeletingLastPathComponent]; +// [[NSFileManager defaultManager] createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:NULL]; +// [str writeToFile:outputPath atomically:YES encoding:NSUTF8StringEncoding error:NULL]; + + NSString * resultPath = [_summaryDetectionOutputPath stringByAppendingPathComponent:name]; + resultPath = [[resultPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"txt"]; + NSData * resultData = [NSData dataWithContentsOfFile:resultPath]; + if (resultData == nil) { + NSLog(@"test %@ is a well-known failing test", name); + continue; + } + + XCTAssertEqualObjects(str, [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding]); + } +} + @end -- cgit v1.2.3