aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSData+zlibTest.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2012-02-06 22:00:33 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2012-02-06 22:00:33 +0000
commit508c07b549332001388dd3a18a88c55b793f439d (patch)
tree2eb8c8e449e962cb31fec014c77200dfab87deb7 /Foundation/GTMNSData+zlibTest.m
parent1aafbe44c74b025faca3c4c91e6d90be4f7d4fe1 (diff)
[Author: thomasvl]
Make the test a little better at getting large data for future tweaks to the buffer size. R=dmaclach
Diffstat (limited to 'Foundation/GTMNSData+zlibTest.m')
-rw-r--r--Foundation/GTMNSData+zlibTest.m43
1 files changed, 26 insertions, 17 deletions
diff --git a/Foundation/GTMNSData+zlibTest.m b/Foundation/GTMNSData+zlibTest.m
index 830f4d0..966c1ae 100644
--- a/Foundation/GTMNSData+zlibTest.m
+++ b/Foundation/GTMNSData+zlibTest.m
@@ -358,33 +358,42 @@ static BOOL HasGzipHeader(NSData *data) {
}
- (void)testLargeData {
- NSData *data1 = [NSData dataWithBytes:randomDataLarge
- length:sizeof(randomDataLarge)];
- STAssertNotNil(data1, @"failed to alloc data block");
- NSData *data2 = [NSData dataWithBytes:randomDataSmall
- length:sizeof(randomDataSmall)];
- STAssertNotNil(data2, @"failed to alloc data block");
-
- NSMutableData *input = [NSMutableData data];
+ // Generate some large data out of the random chunk by xoring over it
+ // to make sure it changes and isn't too repeated.
+ NSData *data = [NSData dataWithBytes:randomDataLarge
+ length:sizeof(randomDataLarge)];
+ STAssertNotNil(data, @"failed to alloc data block");
+ const uint8_t *dataBytes = [data bytes];
+ NSMutableData *scratch = [NSMutableData dataWithLength:[data length]];
+ STAssertNotNil(scratch, @"failed to alloc data block");
+ uint8_t *scratchBytes = [scratch mutableBytes];
+ NSMutableData *input = [NSMutableData dataWithCapacity:200 * [data length]];
for (NSUInteger i = 0; i < 200; ++i) {
- [input appendData:data1];
- for (NSUInteger j = 0; j < i; ++ j) {
- [input appendData:data2];
+ for (NSUInteger j = 0; j < [data length]; ++j) {
+ scratchBytes[j] = dataBytes[j] ^ i;
}
+ [input appendData:scratch];
}
- // Should deflate to > 2048 bytes to take multiple loops during deflation.
+ // The internal buffer size for GTM's deflate/inflate is 1024.
+ NSUInteger internalBufferSize = 1024;
+
+ // Should deflate to more then one buffer size to make sure the internal loop
+ // is working.
NSData *compressed = [NSData gtm_dataByDeflatingData:input
compressionLevel:9];
STAssertNotNil(compressed, @"failed to deflate");
- STAssertGreaterThan([compressed length], (NSUInteger)2048,
- @"should have been more then 2048 bytes");
+ STAssertGreaterThan([compressed length], internalBufferSize,
+ @"should have been more then %d bytes",
+ (int)internalBufferSize);
- // Should inflate to > 2048 bytes to take multiple loops during inflation.
+ // Should inflate to more then one buffer size to make sure the internal loop
+ // is working.
NSData *uncompressed = [NSData gtm_dataByInflatingData:compressed];
STAssertNotNil(uncompressed, @"fail to inflate");
- STAssertGreaterThan([uncompressed length], (NSUInteger)2048,
- @"should have been more then 2048 bytes");
+ STAssertGreaterThan([uncompressed length], internalBufferSize,
+ @"should have been more then %d bytes",
+ (int)internalBufferSize);
STAssertEqualObjects(uncompressed, input,
@"didn't get the same thing back");