Swiftgram/AsyncDisplayKitTests/ASDispatchTests.m
Adlai Holler 404795dc02 Remove Support for iOS 7 (#2930)
* Drop support for iOS 7

* Copy reference images

* Update deployment for sample projects

* Update version

* Update "Life Without Cocoapods"
2017-02-01 14:40:37 -08:00

39 lines
1.0 KiB
Objective-C

//
// ASDispatchTests.m
// AsyncDisplayKit
//
// Created by Adlai Holler on 8/25/16.
// Copyright © 2016 Facebook. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <AsyncDisplayKit/ASDispatch.h>
@interface ASDispatchTests : XCTestCase
@end
@implementation ASDispatchTests
- (void)testDispatchApply
{
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
NSInteger expectedThreadCount = [NSProcessInfo processInfo].activeProcessorCount * 2;
NSLock *lock = [NSLock new];
NSMutableSet *threads = [NSMutableSet set];
NSMutableIndexSet *indices = [NSMutableIndexSet indexSet];
size_t const iterations = 1E5;
ASDispatchApply(iterations, q, 0, ^(size_t i) {
[lock lock];
[threads addObject:[NSThread currentThread]];
XCTAssertFalse([indices containsIndex:i]);
[indices addIndex:i];
[lock unlock];
});
XCTAssertLessThanOrEqual(threads.count, expectedThreadCount);
XCTAssertEqualObjects(indices, [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, iterations)]);
}
@end