ObjFW  Diff

Differences From Artifact [178723d8a9]:

To Artifact [4f485b9d65]:


15
16
17
18
19
20
21
22

23
24

25
26
27
28
29
30
31
32
33


34
35
36
37


38
39
40
41



42
43

44
45
46

47
48

49
50
51
52


53
54
55
56

57
58
59
60
61
15
16
17
18
19
20
21

22
23

24
25
26
27
28
29
30
31


32
33

34


35
36
37



38
39
40


41

42

43
44

45
46
47


48
49
50
51
52

53

54
55
56
57







-
+

-
+







-
-
+
+
-

-
-
+
+

-
-
-
+
+
+
-
-
+
-

-
+

-
+


-
-
+
+



-
+
-





#include "config.h"

#include <string.h>

#import "TestsAppDelegate.h"

static OFString *module = @"OFSHA1Hash";
static OFString *const module = @"OFSHA1Hash";

const uint8_t testfile_sha1[20] =
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, *copy;
	OFFile *f = [OFFile fileWithPath: @"testfile.bin"
	OFSHA1Hash *SHA1, *SHA1Copy;
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
				    mode: @"r"];

	TEST(@"+[cryptoHashWithAllowsSwappableMemory:]",
	    (sha1 = [OFSHA1Hash cryptoHashWithAllowsSwappableMemory: true]))
	TEST(@"+[hashWithAllowsSwappableMemory:]",
	    (SHA1 = [OFSHA1Hash hashWithAllowsSwappableMemory: true]))

	while (!f.atEndOfStream) {
		char buf[64];
		size_t len = [f readIntoBuffer: buf
	while (!file.atEndOfStream) {
		char buffer[64];
		size_t length = [file readIntoBuffer: buffer length: 64];
					length: 64];
		[sha1 updateWithBuffer: buf
		[SHA1 updateWithBuffer: buffer length: length];
				length: len];
	}
	[f close];
	[file close];

	TEST(@"-[copy]", (copy = [[sha1 copy] autorelease]))
	TEST(@"-[copy]", (SHA1Copy = [[SHA1 copy] autorelease]))

	TEST(@"-[digest]",
	    memcmp(sha1.digest, testfile_sha1, 20) == 0 &&
	    memcmp(copy.digest, testfile_sha1, 20) == 0)
	    memcmp(SHA1.digest, testFileSHA1, 20) == 0 &&
	    memcmp(SHA1Copy.digest, testFileSHA1, 20) == 0)

	EXPECT_EXCEPTION(@"Detect invalid call of "
	    @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException,
	    [sha1 updateWithBuffer: ""
	    [SHA1 updateWithBuffer: "" length: 1])
			    length: 1])

	objc_autoreleasePoolPop(pool);
}
@end