zxing/iphone/ZXingWidget/Tests/SMTPResultParserTests.m
gln@google.com c9d8400936 Add email, smtp, and isbn result parsers.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1872 59b500cc-1b3d-0410-9834-0bbf25fbcc57
2011-08-01 21:30:04 +00:00

87 lines
2.9 KiB
Objective-C

//
// SMTPResultParserTests.m
// ZXingWidget
//
// Created by George Nachman on 7/27/11.
// Copyright 2011 ZXing Authors. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>
#import "SMTPResultParser.h"
#import "EmailParsedResult.h"
@interface SMTPResultParserTests : SenTestCase
@end
@implementation SMTPResultParserTests
- (void)testWellFormedSMTPResultParser {
NSString *msg =
@"smtp:user@example.com:the subject:the body";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertTrue([result.to isEqualToString:@"user@example.com"],
@"Wrong to %@", result.to);
STAssertTrue([result.subject isEqualToString:@"the subject"],
@"Wrong subject %@", result.subject);
STAssertTrue([result.body isEqualToString:@"the body"],
@"Wrong body %@", result.body);
}
- (void)testWellFormedNoBodySMTPResultParser {
NSString *msg =
@"smtp:user@example.com:the subject";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertTrue([result.to isEqualToString:@"user@example.com"],
@"Wrong to %@", result.to);
STAssertTrue([result.subject isEqualToString:@"the subject"],
@"Wrong subject %@", result.subject);
STAssertNil(result.body,
@"Wrong body %@", result.body);
}
- (void)testWellFormedNoSubjectSMTPResultParser {
NSString *msg = @"smtp:user@example.com";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertTrue([result.to isEqualToString:@"user@example.com"],
@"Wrong to %@", result.to);
STAssertNil(result.subject,
@"Wrong subject %@", result.subject);
STAssertNil(result.body,
@"Wrong body %@", result.body);
}
- (void)testMalformedHeaderOnlySMTPResultParser {
NSString *msg =
@"smtp:";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertNil(result, @"Bogus message parsed");
}
- (void)testMalformedEmptySMTPResultParser {
NSString *msg =
@"";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertNil(result, @"Bogus message parsed");
}
- (void)testMalformedSMTPResultParser {
NSString *msg =
@"I like traffic lights";
EmailParsedResult *result = (EmailParsedResult *)
[SMTPResultParser parsedResultForString:msg
format:BarcodeFormat_QR_CODE];
STAssertNil(result, @"Bogus message parsed");
}
@end