Index: .fossil-settings/clean-glob ================================================================== --- .fossil-settings/clean-glob +++ .fossil-settings/clean-glob @@ -27,10 +27,11 @@ generators/library/gen_libraries generators/unicode/gen_tables new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist +new_tests/testfile_bin.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -29,10 +29,11 @@ generators/library/gen_libraries generators/unicode/gen_tables new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist +new_tests/testfile_bin.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro @@ -54,10 +55,11 @@ tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/subprocess/subprocess tests/terminal/terminal_tests +tests/testfile_bin.m tests/testfile_bin.m tests/testfile_ini.m tests/tests tests/tests.3dsx tests/tests.arm9 Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -29,10 +29,11 @@ generators/library/gen_libraries generators/unicode/gen_tables new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist +new_tests/testfile_bin.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -1,15 +1,18 @@ include ../extra.mk SUBDIRS = ${TESTPLUGIN} + +CLEAN = testfile_bin.m PROG_NOINST = tests${PROG_SUFFIX} SRCS = OFArrayTests.m \ OFCharacterSetTests.m \ OFColorTests.m \ OFConcreteArrayTests.m \ OFConcreteMutableArrayTests.m \ + OFCryptographicHashTests.m \ OFDateTests.m \ OFIRITests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFMatrix4x4Tests.m \ @@ -18,16 +21,20 @@ OFNumberTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ ${USE_SRCS_PLUGINS} \ - ${USE_SRCS_SOCKETS} + ${USE_SRCS_SOCKETS} \ + testfile_bin.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFSocketTests.m include ../buildsys.mk +testfile_bin.m: testfile.bin + ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ + .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib ADDED new_tests/OFCryptographicHashTests.m Index: new_tests/OFCryptographicHashTests.m ================================================================== --- new_tests/OFCryptographicHashTests.m +++ new_tests/OFCryptographicHashTests.m @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFCryptographicHashTests: OTTestCase +{ + OFStream *_file; +} +@end + +const unsigned char testFileMD5[16] = + "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; +const unsigned char testFileRIPEMD160[20] = + "\x46\x02\x97\xF5\x85\xDF\xB9\x21\x00\xC8\xF9\x87\xC6\xEC\x84\x0D" + "\xCE\xE6\x08\x8B"; +const unsigned char testFileSHA1[20] = + "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96" + "\xF5\x94\xE7\x17"; +const unsigned char testFileSHA224[28] = + "\x27\x69\xD8\x04\x2D\x0F\xCA\x84\x6C\xF1\x62\x44\xBA\x0C\xBD\x46" + "\x64\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; +const unsigned char testFileSHA256[32] = + "\x1A\x02\xD6\x46\xF5\xA6\xBA\xAA\xFF\x7F\xD5\x87\xBA\xC3\xF6\xC6" + "\xB5\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; +const unsigned char testFileSHA384[48] = + "\x7E\xDE\x62\xE2\x10\xA5\x1E\x18\x8A\x11\x7F\x78\xD7\xC7\x55\xB6" + "\x43\x94\x1B\xD2\x78\x5C\xCF\xF3\x8A\xB8\x98\x22\xC7\x0E\xFE\xF1" + "\xEC\x53\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; +const unsigned char testFileSHA512[64] = + "\x8F\x36\x6E\x3C\x19\x4B\xBB\xC7\x82\xAA\xCD\x7D\x55\xA2\xD3\x29" + "\x29\x97\x6A\x3F\xEB\x9B\xB2\xCB\x75\xC9\xEC\xC8\x10\x07\xD6\x07" + "\x31\x4A\xB1\x30\x97\x82\x58\xA5\x1F\x71\x42\xE6\x56\x07\x99\x57" + "\xB2\xB8\x3B\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; + +@implementation OFCryptographicHashTests +- (void)setUp +{ + OFIRI *IRI; + + [super setUp]; + + IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; + _file = [[OFIRIHandler openItemAtIRI: IRI mode: @"r"] retain]; +} + +- (void)tearDown +{ + [_file close]; +} + +- (void)dealloc +{ + [_file release]; + + [super dealloc]; +} + +- (void)testHash: (Class)hashClass + expectedDigest: (const unsigned char *)expectedDigest +{ + id hash = + [hashClass hashWithAllowsSwappableMemory: true]; + id copy; + + OTAssertNotNil(hash); + + while (!_file.atEndOfStream) { + char buffer[64]; + size_t length = [_file readIntoBuffer: buffer length: 64]; + [hash updateWithBuffer: buffer length: length]; + } + + copy = [[hash copy] autorelease]; + + [hash calculate]; + [copy calculate]; + + OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); + OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); + + OTAssertThrowsSpecific([hash updateWithBuffer: "" length: 1], + OFHashAlreadyCalculatedException); +} + +- (void)testMD5 +{ + [self testHash: [OFMD5Hash class] expectedDigest: testFileMD5]; +} + +- (void)testRIPEMD160 +{ + [self testHash: [OFRIPEMD160Hash class] + expectedDigest: testFileRIPEMD160]; +} + +- (void)testSHA1 +{ + [self testHash: [OFSHA1Hash class] expectedDigest: testFileSHA1]; +} + +- (void)testSHA224 +{ + [self testHash: [OFSHA224Hash class] expectedDigest: testFileSHA224]; +} + +- (void)testSHA256 +{ + [self testHash: [OFSHA256Hash class] expectedDigest: testFileSHA256]; +} + +- (void)testSHA384 +{ + [self testHash: [OFSHA384Hash class] expectedDigest: testFileSHA384]; +} + +- (void)testSHA512 +{ + [self testHash: [OFSHA512Hash class] expectedDigest: testFileSHA512]; +} +@end ADDED new_tests/testfile.bin Index: new_tests/testfile.bin ================================================================== --- new_tests/testfile.bin +++ new_tests/testfile.bin cannot compute difference between binary files Index: src/test/OTAppDelegate.m ================================================================== --- src/test/OTAppDelegate.m +++ src/test/OTAppDelegate.m @@ -16,10 +16,11 @@ #include "config.h" #import "OTAppDelegate.h" #import "OFColor.h" +#import "OFMethodSignature.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFValue.h" #import "OTTestCase.h" @@ -87,17 +88,31 @@ @try { tests = [OFMutableSet set]; for (Method *iter = methods; *iter != NULL; iter++) { SEL selector = method_getName(*iter); + void *pool; + OFMethodSignature *sig; if (selector == NULL) continue; - if (strncmp(sel_getName(selector), "test", 4) == 0) + if (strncmp(sel_getName(selector), "test", 4) != 0) + continue; + + pool = objc_autoreleasePoolPush(); + sig = [OFMethodSignature signatureWithObjCTypes: + method_getTypeEncoding(*iter)]; + + if (strcmp(sig.methodReturnType, "v") == 0 && + sig.numberOfArguments == 2 && + strcmp([sig argumentTypeAtIndex: 0], "@") == 0 && + strcmp([sig argumentTypeAtIndex: 1], ":") == 0) [tests addObject: [OFValue valueWithPointer: selector]]; + + objc_autoreleasePoolPop(pool); } } @finally { OFFreeMemory(methods); } Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -22,20 +22,13 @@ OFDictionaryTests.m \ OFHMACTests.m \ OFINIFileTests.m \ OFListTests.m \ OFLocaleTests.m \ - OFMD5HashTests.m \ OFMemoryStreamTests.m \ OFNotificationCenterTests.m \ OFObjectTests.m \ - OFRIPEMD160HashTests.m \ - OFSHA1HashTests.m \ - OFSHA224HashTests.m \ - OFSHA256HashTests.m \ - OFSHA384HashTests.m \ - OFSHA512HashTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFValueTests.m \ DELETED tests/OFMD5HashTests.m Index: tests/OFMD5HashTests.m ================================================================== --- tests/OFMD5HashTests.m +++ tests/OFMD5HashTests.m @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFMD5Hash"; - -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, *MD5Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI 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(@"-[calculate]", R([MD5 calculate]) && R([MD5Copy calculate])) - - TEST(@"-[digest]", - 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]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFRIPEMD160HashTests.m Index: tests/OFRIPEMD160HashTests.m ================================================================== --- tests/OFRIPEMD160HashTests.m +++ tests/OFRIPEMD160HashTests.m @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFRIPEMD160Hash"; - -const uint8_t testFileRIPEMD160[20] = - "\x46\x02\x97\xF5\x85\xDF\xB9\x21\x00\xC8\xF9\x87\xC6\xEC\x84\x0D\xCE" - "\xE6\x08\x8B"; - -@implementation TestsAppDelegate (OFRIPEMD160HashTests) -- (void)RIPEMD160HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFRIPEMD160Hash *RIPEMD160, *RIPEMD160Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (RIPEMD160 = [OFRIPEMD160Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[64]; - size_t length = [file readIntoBuffer: buffer length: 64]; - [RIPEMD160 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (RIPEMD160Copy = [[RIPEMD160 copy] autorelease])) - - TEST(@"-[calculate]", - R([RIPEMD160 calculate]) && R([RIPEMD160Copy calculate])) - - TEST(@"-[digest]", - memcmp(RIPEMD160.digest, testFileRIPEMD160, 20) == 0 && - memcmp(RIPEMD160Copy.digest, testFileRIPEMD160, 20) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, - [RIPEMD160 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFSHA1HashTests.m Index: tests/OFSHA1HashTests.m ================================================================== --- tests/OFSHA1HashTests.m +++ tests/OFSHA1HashTests.m @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSHA1Hash"; - -const uint8_t testFileSHA1[20] = - "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96\xF5" - "\x94\xE7\x17"; - -@implementation TestsAppDelegate (SHA1HashTests) -- (void)SHA1HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFSHA1Hash *SHA1, *SHA1Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (SHA1 = [OFSHA1Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[64]; - size_t length = [file readIntoBuffer: buffer length: 64]; - [SHA1 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (SHA1Copy = [[SHA1 copy] autorelease])) - - TEST(@"-[calculate]", R([SHA1 calculate]) && R([SHA1Copy calculate])) - - TEST(@"-[digest]", - memcmp(SHA1.digest, testFileSHA1, 20) == 0 && - memcmp(SHA1Copy.digest, testFileSHA1, 20) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, - [SHA1 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFSHA224HashTests.m Index: tests/OFSHA224HashTests.m ================================================================== --- tests/OFSHA224HashTests.m +++ tests/OFSHA224HashTests.m @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSHA224Hash"; - -const uint8_t testFileSHA224[28] = - "\x27\x69\xD8\x04\x2D\x0F\xCA\x84\x6C\xF1\x62\x44\xBA\x0C\xBD\x46\x64" - "\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; - -@implementation TestsAppDelegate (SHA224HashTests) -- (void)SHA224HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFSHA224Hash *SHA224, *SHA224Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (SHA224 = [OFSHA224Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[64]; - size_t length = [file readIntoBuffer: buffer length: 64]; - [SHA224 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (SHA224Copy = [[SHA224 copy] autorelease])) - - TEST(@"-[calculate]", - R([SHA224 calculate]) && R([SHA224Copy calculate])) - - TEST(@"-[digest]", - memcmp(SHA224.digest, testFileSHA224, 28) == 0 && - memcmp(SHA224Copy.digest, testFileSHA224, 28) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, - [SHA224 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFSHA256HashTests.m Index: tests/OFSHA256HashTests.m ================================================================== --- tests/OFSHA256HashTests.m +++ tests/OFSHA256HashTests.m @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSHA256Hash"; - -const uint8_t testFileSHA256[32] = - "\x1A\x02\xD6\x46\xF5\xA6\xBA\xAA\xFF\x7F\xD5\x87\xBA\xC3\xF6\xC6\xB5" - "\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; - -@implementation TestsAppDelegate (SHA256HashTests) -- (void)SHA256HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFSHA256Hash *SHA256, *SHA256Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (SHA256 = [OFSHA256Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[64]; - size_t length = [file readIntoBuffer: buffer length: 64]; - [SHA256 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (SHA256Copy = [[SHA256 copy] autorelease])) - - TEST(@"-[calculate]", - R([SHA256 calculate]) && R([SHA256Copy calculate])) - - TEST(@"-[digest]", - memcmp(SHA256.digest, testFileSHA256, 32) == 0 && - memcmp(SHA256Copy.digest, testFileSHA256, 32) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, - [SHA256 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFSHA384HashTests.m Index: tests/OFSHA384HashTests.m ================================================================== --- tests/OFSHA384HashTests.m +++ tests/OFSHA384HashTests.m @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSHA384Hash"; - -const uint8_t testFileSHA384[48] = - "\x7E\xDE\x62\xE2\x10\xA5\x1E\x18\x8A\x11\x7F\x78\xD7\xC7\x55\xB6\x43" - "\x94\x1B\xD2\x78\x5C\xCF\xF3\x8A\xB8\x98\x22\xC7\x0E\xFE\xF1\xEC\x53" - "\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; - -@implementation TestsAppDelegate (SHA384HashTests) -- (void)SHA384HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFSHA384Hash *SHA384, *SHA384Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (SHA384 = [OFSHA384Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[128]; - size_t length = [file readIntoBuffer: buffer length: 128]; - [SHA384 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (SHA384Copy = [[SHA384 copy] autorelease])) - - TEST(@"-[calculate]", - R([SHA384 calculate]) && R([SHA384Copy calculate])) - - TEST(@"-[digest]", - memcmp(SHA384.digest, testFileSHA384, 48) == 0 && - memcmp(SHA384Copy.digest, testFileSHA384, 48) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, - [SHA384 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFSHA512HashTests.m Index: tests/OFSHA512HashTests.m ================================================================== --- tests/OFSHA512HashTests.m +++ tests/OFSHA512HashTests.m @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFSHA512Hash"; - -const uint8_t testFileSHA512[64] = - "\x8F\x36\x6E\x3C\x19\x4B\xBB\xC7\x82\xAA\xCD\x7D\x55\xA2\xD3\x29\x29" - "\x97\x6A\x3F\xEB\x9B\xB2\xCB\x75\xC9\xEC\xC8\x10\x07\xD6\x07\x31\x4A" - "\xB1\x30\x97\x82\x58\xA5\x1F\x71\x42\xE6\x56\x07\x99\x57\xB2\xB8\x3B" - "\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; - -@implementation TestsAppDelegate (SHA512HashTests) -- (void)SHA512HashTests -{ - void *pool = objc_autoreleasePoolPush(); - OFSHA512Hash *SHA512, *SHA512Copy; - OFIRI *IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; - OFStream *file = [OFIRIHandler openItemAtIRI: IRI mode: @"r"]; - - TEST(@"+[hashWithAllowsSwappableMemory:]", - (SHA512 = [OFSHA512Hash hashWithAllowsSwappableMemory: true])) - - while (!file.atEndOfStream) { - char buffer[128]; - size_t length = [file readIntoBuffer: buffer length: 128]; - [SHA512 updateWithBuffer: buffer length: length]; - } - [file close]; - - TEST(@"-[copy]", (SHA512Copy = [[SHA512 copy] autorelease])) - - TEST(@"-[calculate]", - R([SHA512 calculate]) && R([SHA512Copy calculate])) - - TEST(@"-[digest]", - memcmp(SHA512.digest, testFileSHA512, 64) == 0 && - memcmp(SHA512Copy.digest, testFileSHA512, 64) == 0) - - EXPECT_EXCEPTION(@"Detect invalid call of " - @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, - [SHA512 updateWithBuffer: "" length: 1]) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -117,14 +117,10 @@ @interface TestsAppDelegate (OFLocaleTests) - (void)localeTests; @end -@interface TestsAppDelegate (OFMD5HashTests) -- (void)MD5HashTests; -@end - @interface TestsAppDelegate (OFMemoryStreamTests) - (void)memoryStreamTests; @end @interface TestsAppDelegate (OFNotificationCenterTests) @@ -141,34 +137,10 @@ @interface TestsAppDelegate (RuntimeARCTests) - (void)runtimeARCTests; @end -@interface TestsAppDelegate (OFRIPEMD160HashTests) -- (void)RIPEMD160HashTests; -@end - -@interface TestsAppDelegate (OFSHA1HashTests) -- (void)SHA1HashTests; -@end - -@interface TestsAppDelegate (OFSHA224HashTests) -- (void)SHA224HashTests; -@end - -@interface TestsAppDelegate (OFSHA256HashTests) -- (void)SHA256HashTests; -@end - -@interface TestsAppDelegate (OFSHA384HashTests) -- (void)SHA384HashTests; -@end - -@interface TestsAppDelegate (OFSHA512HashTests) -- (void)SHA512HashTests; -@end - @interface TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests; @end @interface TestsAppDelegate (OFSPXStreamSocketTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -386,17 +386,10 @@ [self setTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; - [self MD5HashTests]; - [self RIPEMD160HashTests]; - [self SHA1HashTests]; - [self SHA224HashTests]; - [self SHA256HashTests]; - [self SHA384HashTests]; - [self SHA512HashTests]; [self HMACTests]; #ifdef HAVE_CODEPAGE_437 [self INIFileTests]; #endif #ifdef OF_HAVE_SOCKETS