diff --git a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm index 091030b0b..5b9d71f46 100644 --- a/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm +++ b/OSBindings/Mac/Clock SignalTests/AmigaBlitterTests.mm @@ -12,6 +12,7 @@ #include #include +#include namespace Amiga { /// An empty stub to satisfy Amiga::Blitter's inheritance from Amiga::DMADevice; @@ -37,9 +38,34 @@ struct Chipset { Amiga::Chipset nonChipset; Amiga::Blitter blitter(nonChipset, ram, 256 * 1024); - NSURL *const traceURL = [[NSBundle bundleForClass:[self class]] URLForResource:name withExtension:@"json" subdirectory:@"Amiga Blitter Tests"]; - NSData *const traceData = [NSData dataWithContentsOfURL:traceURL]; + NSURL *const traceURL = [[NSBundle bundleForClass:[self class]] + URLForResource:name withExtension:@"json.gz" subdirectory:@"Amiga Blitter Tests"]; + + // Use gzopen/etc to decompress to a temporary file, then read that back + // into memory to provide to the JSON deserialiser. This avoids having to wade + // too deeply into ZLib's slightly circuitous handling of decompression when + // the destination size is unkoinw. + NSString *const tempDir = NSTemporaryDirectory(); + NSString *const tempFile = [tempDir stringByAppendingPathComponent:@"temp.json"]; + + const gzFile compressedFile = gzopen([traceURL fileSystemRepresentation], "rb"); + FILE *const uncompressedFile = fopen([tempFile UTF8String], "wb"); + + uint8_t buffer[64 * 1024]; + while(true) { + const auto length = gzread(compressedFile, buffer, sizeof(buffer)); + if(!length) break; + fwrite(buffer, 1, length, uncompressedFile); + if(length != sizeof(buffer)) break; + } + + fclose(uncompressedFile); + gzclose(compressedFile); + + // Open and parse. + NSData *const traceData = [NSData dataWithContentsOfFile:tempFile]; NSArray *const trace = [NSJSONSerialization JSONObjectWithData:traceData options:0 error:nil]; + XCTAssertNotNil(trace); using TransactionType = Amiga::Blitter::Transaction::Type;