Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: b0e858148a
Fetching contributors…

Cannot retrieve contributors at this time

111 lines (78 sloc) 2.67 kb
//
// CWBlockQueueTests.m
// Zangetsu
//
// Created by Colin Wheeler on 2/27/12.
// Copyright (c) 2012. All rights reserved.
//
#import "CWBlockQueueTests.h"
#import "CWBlockQueue.h"
#import "CWAssertionMacros.h"
@implementation CWBlockQueueTests
-(void)testBasicOperation
{
__block NSString *result = nil;
CWBlockQueue *queue = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetPrivateQueue
concurrent:YES
label:nil];
[queue addoperationWithBlock:^{
result = @"Hello World!";
}];
[queue waitForQueueToFinish];
CWAssertEqualsStrings(@"Hello World!", result);
}
-(void)testCompletionBlock
{
__block NSString *result = nil;
CWBlockQueue *queue = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetPrivateQueue
concurrent:YES
label:nil];
CWBlockOperation *operation = [CWBlockOperation operationWithBlock:^{
NSLog(@"Obey Hypnotoad!");
}];
[operation setCompletionBlock:^{
result = @"Obey Hypnotoad!";
}];
[queue addOperation:operation];
[queue waitForQueueToFinish];
CWAssertEqualsStrings(@"Obey Hypnotoad!", result);
}
-(void)testSynchronousOperations
{
// test -addSynchronousOperationWithBlock:
__block NSInteger result = 0;
CWBlockQueue *queue = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetPrivateQueue
concurrent:NO
label:nil];
[queue addSynchronousOperationWithBlock:^{
result = 42;
}];
STAssertTrue(result == 42,@"The result should 42 if the block executed");
// test -addSynchronousOperation
CWBlockOperation *op = [CWBlockOperation operationWithBlock:^{
result = 1729;
}];
[queue addSynchronousOperation:op];
STAssertTrue(result == 1729,@"The result should 1729 if the block executed");
}
-(void)testQueuesAreEqual
{
CWBlockQueue *queue1 = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetMainQueue
concurrent:NO
label:nil];
CWBlockQueue *queue2 = [[CWBlockQueue alloc] initWithGCDQueue:dispatch_get_main_queue()];
STAssertTrue([queue1 isEqual:queue2],@"Queues should be equal");
CWBlockQueue *queue3 = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetPrivateQueue
concurrent:NO
label:nil];
STAssertFalse([queue1 isEqual:queue3],@"Queues should not be equal");
}
-(void)testQueueLabel
{
const NSString *label = @"TestQueue";
CWBlockQueue *queue = [[CWBlockQueue alloc] initWithQueueType:kCWBlockQueueTargetPrivateQueue
concurrent:NO
label:(NSString *)label];
CWAssertEqualsStrings([queue label], (NSString *)label);
}
@end
Jump to Line
Something went wrong with that request. Please try again.