/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSFileManager+CarbonTest.m

http://macfuse.googlecode.com/ · Objective C · 79 lines · 51 code · 10 blank · 18 comment · 0 complexity · 84204b3724cbd17603570116965f4ba9 MD5 · raw file

  1. //
  2. // GTMNSFileManager+CarbonTest.m
  3. //
  4. // Copyright 2006-2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import "GTMSenTestCase.h"
  19. #import "GTMNSFileManager+Carbon.h"
  20. #import "GTMUnitTestDevLog.h"
  21. #import <CoreServices/CoreServices.h>
  22. @interface GTMNSFileManager_CarbonTest : GTMTestCase
  23. @end
  24. @implementation GTMNSFileManager_CarbonTest
  25. - (void)testAliasPathFSRefConversion {
  26. NSString *path = NSHomeDirectory();
  27. STAssertNotNil(path, nil);
  28. NSFileManager *fileManager = [NSFileManager defaultManager];
  29. FSRef *fsRef = [fileManager gtm_FSRefForPath:path];
  30. STAssertNotNULL(fsRef, nil);
  31. AliasHandle alias;
  32. STAssertNoErr(FSNewAlias(nil, fsRef, &alias), nil);
  33. STAssertNotNULL(alias, nil);
  34. NSData *aliasData = [NSData dataWithBytes:*alias
  35. length:GetAliasSize(alias)];
  36. STAssertNotNil(aliasData, nil);
  37. NSString *path2 = [fileManager gtm_pathFromAliasData:aliasData];
  38. STAssertEqualObjects(path, path2, nil);
  39. path2 = [fileManager gtm_pathFromAliasData:aliasData
  40. resolve:YES
  41. withUI:NO];
  42. STAssertEqualObjects(path, path2, nil);
  43. path2 = [fileManager gtm_pathFromAliasData:aliasData
  44. resolve:NO
  45. withUI:NO];
  46. STAssertEqualObjects(path, path2, nil);
  47. NSData *aliasData2 = [fileManager gtm_aliasDataForPath:path2];
  48. STAssertNotNil(aliasData2, nil);
  49. NSString *path3 = [fileManager gtm_pathFromAliasData:aliasData2];
  50. STAssertEqualObjects(path2, path3, nil);
  51. NSString *path4 = [fileManager gtm_pathFromFSRef:fsRef];
  52. STAssertEqualObjects(path, path4, nil);
  53. // Failure cases
  54. [GTMUnitTestDevLogDebug expectPattern:@"DebugAssert: "
  55. @"GoogleToolboxForMac: FSPathMakeRef.*"];
  56. STAssertNULL([fileManager gtm_FSRefForPath:@"/ptah/taht/dosent/esixt/"],
  57. nil);
  58. STAssertNULL([fileManager gtm_FSRefForPath:@""], nil);
  59. STAssertNULL([fileManager gtm_FSRefForPath:nil], nil);
  60. STAssertNil([fileManager gtm_pathFromFSRef:nil], nil);
  61. STAssertNil([fileManager gtm_pathFromAliasData:nil], nil);
  62. STAssertNil([fileManager gtm_pathFromAliasData:[NSData data]], nil);
  63. [GTMUnitTestDevLogDebug expectPattern:@"DebugAssert: "
  64. @"GoogleToolboxForMac: FSPathMakeRef.*"];
  65. STAssertNil([fileManager gtm_aliasDataForPath:@"/ptah/taht/dosent/esixt/"], nil);
  66. STAssertNil([fileManager gtm_aliasDataForPath:@""], nil);
  67. STAssertNil([fileManager gtm_aliasDataForPath:nil], nil);
  68. }
  69. @end