PageRenderTime 53ms CodeModel.GetById 16ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/Common/NSData+HashTest.m

http://macfuse.googlecode.com/
Objective C | 48 lines | 22 code | 11 blank | 15 comment | 0 complexity | f4707010778e04492147b3572224f957 MD5 | raw file
 1// Copyright 2008 Google Inc.
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#import <SenTestingKit/SenTestingKit.h>
16#import "NSData+Hash.h"
17#import "GTMBase64.h"
18
19
20@interface NSData_HashTest : SenTestCase
21@end
22
23
24@implementation NSData_HashTest
25
26- (void)testBasics {
27  NSData *hash;
28  NSString *hashString;
29  NSString *expectedHash;
30
31  // Empty data.
32  NSData *data = [NSData data];
33
34  hash = [data SHA1Hash];
35  hashString = [GTMBase64 stringByEncodingData:hash];
36  expectedHash = @"2jmj7l5rSw0yVb/vlWAYkK/YBwk=";
37  STAssertEqualObjects(hashString, expectedHash, nil);
38
39  // Some actual bytes.
40  data = [@"Don't Hassle The Hoff" dataUsingEncoding:NSUTF8StringEncoding];
41  hash = [data SHA1Hash];
42  hashString = [GTMBase64 stringByEncodingData:hash];
43  expectedHash = @"+WcDyvV4b/Vbj2+U9SEnJI/IAjw=";
44  STAssertEqualObjects(hashString, expectedHash, nil);
45
46}  // testBasics
47
48@end  // NSData_HashTest