// // NSDataTest.m // PonyExpress // // Created by Michael Lewis on 2/13/13. // // #import #import "NSData+PIOAdditions.h" #import "Common.h" @interface NSDataTest : SenTestCase @end @implementation NSDataTest - (void)testEfficientForOneSegment; { dispatch_data_t data = dispatch_data_create("hello", 5, dispatch_get_main_queue(), DISPATCH_DATA_DESTRUCTOR_DEFAULT); NSData *d1 = [NSData dataWithDispatchData:data]; dispatch_data_t newData = [d1 copyDispatchData]; STAssertEquals(newData, data, @"Should not have created a new data object since it was one segment"); sr_dispatch_release(data); sr_dispatch_release(newData); } - (void)testEfficientForDataCopy; { NSData *data = [[NSData alloc] initWithBytes:"hello" length:5]; dispatch_data_t newData = [data copyDispatchData]; NSData *data2 = [NSData dataWithDispatchData:newData]; STAssertEquals(data.bytes, data2.bytes, @"Should all ahve the same buffer"); sr_dispatch_release(newData); } @end