1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-30 04:50:08 +00:00

Allow for GZipped tests.

This commit is contained in:
Thomas Harte 2022-08-07 21:53:19 -04:00
parent 2f3dfdcc67
commit cfccfd48e5

View File

@ -12,6 +12,7 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <zlib.h>
namespace Amiga { namespace Amiga {
/// An empty stub to satisfy Amiga::Blitter's inheritance from Amiga::DMADevice; /// An empty stub to satisfy Amiga::Blitter's inheritance from Amiga::DMADevice;
@ -37,9 +38,34 @@ struct Chipset {
Amiga::Chipset nonChipset; Amiga::Chipset nonChipset;
Amiga::Blitter<true> blitter(nonChipset, ram, 256 * 1024); Amiga::Blitter<true> blitter(nonChipset, ram, 256 * 1024);
NSURL *const traceURL = [[NSBundle bundleForClass:[self class]] URLForResource:name withExtension:@"json" subdirectory:@"Amiga Blitter Tests"]; NSURL *const traceURL = [[NSBundle bundleForClass:[self class]]
NSData *const traceData = [NSData dataWithContentsOfURL:traceURL]; 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]; NSArray *const trace = [NSJSONSerialization JSONObjectWithData:traceData options:0 error:nil];
XCTAssertNotNil(trace);
using TransactionType = Amiga::Blitter<true>::Transaction::Type; using TransactionType = Amiga::Blitter<true>::Transaction::Type;