Skip to content

Instantly share code, notes, and snippets.

@capnslipp
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save capnslipp/11388990 to your computer and use it in GitHub Desktop.

Select an option

Save capnslipp/11388990 to your computer and use it in GitHub Desktop.
#import "TestCGBitmapContextCreate_iOSTests.h"
@implementation TestCGBitmapContextCreate_iOSTests
- (void)setUp
{
[super setUp];
_colorSpace = CGColorSpaceCreateDeviceRGB();
}
- (void)tearDown
{
CGColorSpaceRelease(_colorSpace);
[super tearDown];
}
static const size_t kWidth = 512, kHeight = 512;
static const size_t kBitsPerComponent = 8;
static const size_t kComponentsPerPixel = 4;
- (void)subTestCGImageAlphaMode:(CGImageAlphaInfo)alphaMode expectSuccess:(BOOL)shouldBeSuccessful
{
size_t bytesPerRow = kBitsPerComponent * kComponentsPerPixel * kWidth / 8;
CGContextRef cgContext = CGBitmapContextCreate(
NULL, // data
kWidth, kHeight,
kBitsPerComponent, bytesPerRow,
_colorSpace,
alphaMode
);
NSLog(@"\t" @"cgContext with CGImageAlphaInfo %d: %@", alphaMode, cgContext);
if (shouldBeSuccessful)
STAssertNotNil((__bridge id)cgContext, @"Unable to create context with CGImageAlphaInfo %d", alphaMode);
else
STAssertNil((__bridge id)cgContext, @"Unexpectedly created context with CGImageAlphaInfo %d", alphaMode);
CGContextRelease(cgContext);
}
- (void)subTestCGImageAlphaMode:(CGImageAlphaInfo)alphaMode {
[self subTestCGImageAlphaMode:alphaMode expectSuccess:YES];
}
- (void)testAllCGImageAlphaModes
{
[self subTestCGImageAlphaMode:kCGImageAlphaNone];
[self subTestCGImageAlphaMode:kCGImageAlphaPremultipliedLast];
[self subTestCGImageAlphaMode:kCGImageAlphaPremultipliedFirst];
[self subTestCGImageAlphaMode:kCGImageAlphaLast];
[self subTestCGImageAlphaMode:kCGImageAlphaFirst];
[self subTestCGImageAlphaMode:kCGImageAlphaNoneSkipLast];
[self subTestCGImageAlphaMode:kCGImageAlphaNoneSkipFirst];
[self subTestCGImageAlphaMode:kCGImageAlphaOnly];
}
- (void)testInvalidCGImageAlphaModes
{
unsigned int highestCGImageAlphaMode = 0;
highestCGImageAlphaMode = (kCGImageAlphaNone > highestCGImageAlphaMode) ? kCGImageAlphaNone : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaPremultipliedLast > highestCGImageAlphaMode) ? kCGImageAlphaPremultipliedLast : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaPremultipliedFirst > highestCGImageAlphaMode) ? kCGImageAlphaPremultipliedFirst : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaLast > highestCGImageAlphaMode) ? kCGImageAlphaLast : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaFirst > highestCGImageAlphaMode) ? kCGImageAlphaFirst : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaNoneSkipLast > highestCGImageAlphaMode) ? kCGImageAlphaNoneSkipLast : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaNoneSkipFirst > highestCGImageAlphaMode) ? kCGImageAlphaNoneSkipFirst : highestCGImageAlphaMode;
highestCGImageAlphaMode = (kCGImageAlphaOnly > highestCGImageAlphaMode) ? kCGImageAlphaOnly : highestCGImageAlphaMode;
for (int invalidModeI = (highestCGImageAlphaMode + 1); invalidModeI <= kCGBitmapAlphaInfoMask; ++invalidModeI) {
[self subTestCGImageAlphaMode:invalidModeI expectSuccess:NO];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment