forked from cocos2d/cocos2d-objc
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCCImageTests.m
90 lines (70 loc) · 2.82 KB
/
CCImageTests.m
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// CCImageTests.m
// cocos2d-tests
//
// Created by Andy Korth on 12/17/14.
// Copyright (c) 2014 Cocos2d. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "cocos2d.h"
#import "AppDelegate.h"
#import "CCImage_Private.h"
#import "CCFile_Private.h"
#import "CCFileLocator.h"
/**
Automated unit tests for loading many different types of files into CCImages. The goal with these
tests is to make sure specific infrequently used texture loading methods don't crash. These tests
don't interact with the OpenGL context. See the visual testbed TextureTest.m for a visual and non-automated
version of this test.
*/
@interface CCImageTests : XCTestCase
@end
@implementation CCImageTests
-(void) testImageNamed:(NSString*) fileName withTitle:(NSString*)title
{
CCFileLocator *locator = [[CCFileLocator alloc] init];
locator.searchPaths = @[
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"],
];
CCFile *file = [locator fileNamedWithResolutionSearch:fileName error:nil];
XCTAssertNotNil(file, @"Could find file.");
CCImage *image = [[CCImage alloc]initWithCCFile:file options:nil];
XCTAssertNotNil(image, @"CCImage didn't load from %@ for test <%@>.", fileName, title);
// First check pixel size.
XCTAssertGreaterThan(image.sizeInPixels.width, 0, @"Zero pixel width image");
XCTAssertGreaterThan(image.sizeInPixels.height, 0, @"Zero pixel height image");
// If the CCImage loaded with a sensical width and height, it probably worked.
XCTAssertGreaterThan(image.contentSize.width, 0, @"Zero contentSize.width image");
XCTAssertGreaterThan(image.contentSize.height, 0, @"Zero contentSize.height image");
}
-(void) testPNG
{
[self testImageNamed: @"test_image.png" withTitle: @"PNG loading example (has alpha)"];
}
-(void) testBMP
{
[self testImageNamed: @"test_image.bmp" withTitle: @"BMP loading example (no alpha)"];
}
-(void) testJPEG
{
[self testImageNamed: @"test_image.jpeg" withTitle: @"JPEG loading example (no alpha, white spots)"];
}
-(void) testTIFF
{
[self testImageNamed: @"test_image.tiff" withTitle: @"TIFF loading example (has alpha)"];
}
#if __CC_PLATFORM_IOS
// PVR on iOS only.
// This wasn't supported on purpose. We only noticed that ImageIO happened to load PVR files.
// This only works on iOS 8 however, so we should comment the test out for now.
//-(void) testPVR
//{
// // Important note. This uses ImageIO to load the pvr texture. In normal cocos2d operation, we have our own pvr loading code.
// [self testImageNamed: @"test_image.pvr" withTitle: @"PVR loading example (no alpha)"];
//}
#endif
-(void) testNonPowerOfTwoTextureTest
{
[self testImageNamed: @"test_1021x1024.png" withTitle: @"1021x1024 png. Watch for memory leaks with Instruments. See http://www.cocos2d-iphone.org/forum/topic/31092"];
}
@end