1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#import "PopplerDocumentTest.h"
#import "TestSettings.h"
#import <PopplerKit/PopplerKit.h>
#import <Foundation/NSException.h>
@implementation PopplerDocumentTest
- (void) testOpenDocument
{
PopplerDocument* doc = [PopplerDocument documentWithPath: kTestDocument];
[self assertNotNil: doc];
[self assertInt: kTestDocumentPageCount equals: [doc countPages]];
}
- (void) testOpenNonExistingDocument
{
NS_DURING
[PopplerDocument documentWithPath: kNonExistentDocument];
[self fail: @"exception expected"];
NS_HANDLER
[self assert: [localException name] equals: PopplerException];
NS_ENDHANDLER
}
- (void) testOpenNilPath
{
NS_DURING
[PopplerDocument documentWithPath: nil];
[self fail: @"exception expected"];
NS_HANDLER
[self assert: [localException name] equals: NSInvalidArgumentException];
NS_ENDHANDLER
}
- (void) testGetPages
{
PopplerDocument* doc = [PopplerDocument documentWithPath: kTestDocument];
int i;
for (i = 1; i <= [doc countPages]; i++)
{
PopplerPage* page = [doc page: i];
[self assertNotNil: page message: [NSString stringWithFormat: @"page %d is nil", i]];
[self assert: page same: [doc page: i]];
[self assertInt: [page index] equals: i];
[self assert: [page document] same: doc];
}
}
- (void) testGetPageWithInvalidIndex
{
PopplerDocument* doc = [PopplerDocument documentWithPath: kTestDocument];
NS_DURING
[doc page: 0];
[self fail: @"exception expected"];
NS_HANDLER
[self assert: [localException name] equals: NSInvalidArgumentException];
NS_ENDHANDLER
NS_DURING
[doc page: [doc countPages] + 1];
[self fail: @"exception expected"];
NS_HANDLER
[self assert: [localException name] equals: NSInvalidArgumentException];
NS_ENDHANDLER
}
@end
|