/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. #import <SenTestingKit/SenTestingKit.h>
  15. #import "NSData+Hash.h"
  16. #import "GTMBase64.h"
  17. @interface NSData_HashTest : SenTestCase
  18. @end
  19. @implementation NSData_HashTest
  20. - (void)testBasics {
  21. NSData *hash;
  22. NSString *hashString;
  23. NSString *expectedHash;
  24. // Empty data.
  25. NSData *data = [NSData data];
  26. hash = [data SHA1Hash];
  27. hashString = [GTMBase64 stringByEncodingData:hash];
  28. expectedHash = @"2jmj7l5rSw0yVb/vlWAYkK/YBwk=";
  29. STAssertEqualObjects(hashString, expectedHash, nil);
  30. // Some actual bytes.
  31. data = [@"Don't Hassle The Hoff" dataUsingEncoding:NSUTF8StringEncoding];
  32. hash = [data SHA1Hash];
  33. hashString = [GTMBase64 stringByEncodingData:hash];
  34. expectedHash = @"+WcDyvV4b/Vbj2+U9SEnJI/IAjw=";
  35. STAssertEqualObjects(hashString, expectedHash, nil);
  36. } // testBasics
  37. @end // NSData_HashTest