@@ -17,44 +17,40 @@ #include #import "TestsAppDelegate.h" -static OFString *module = @"OFMD5Hash"; +static OFString *const module = @"OFMD5Hash"; -const uint8_t testfile_md5[16] = - "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; +const uint8_t testFileMD5[16] = + "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; @implementation TestsAppDelegate (OFMD5HashTests) - (void)MD5HashTests { void *pool = objc_autoreleasePoolPush(); - OFMD5Hash *md5, *copy; - OFFile *f = [OFFile fileWithPath: @"testfile.bin" - mode: @"r"]; - - TEST(@"+[cryptoHashWithAllowsSwappableMemory:]", - (md5 = [OFMD5Hash cryptoHashWithAllowsSwappableMemory: true])) - - while (!f.atEndOfStream) { - char buf[64]; - size_t len = [f readIntoBuffer: buf - length: 64]; - [md5 updateWithBuffer: buf - length: len]; - } - [f close]; - - TEST(@"-[copy]", (copy = [[md5 copy] autorelease])) + OFMD5Hash *MD5, *MD5Copy; + OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; + + TEST(@"+[hashWithAllowsSwappableMemory:]", + (MD5 = [OFMD5Hash hashWithAllowsSwappableMemory: true])) + + while (!file.atEndOfStream) { + char buffer[64]; + size_t length = [file readIntoBuffer: buffer length: 64]; + [MD5 updateWithBuffer: buffer length: length]; + } + [file close]; + + TEST(@"-[copy]", (MD5Copy = [[MD5 copy] autorelease])) TEST(@"-[digest]", - memcmp(md5.digest, testfile_md5, 16) == 0 && - memcmp(copy.digest, testfile_md5, 16) == 0) + memcmp(MD5.digest, testFileMD5, 16) == 0 && + memcmp(MD5Copy.digest, testFileMD5, 16) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, - [md5 updateWithBuffer: "" - length: 1]) + [MD5 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end