/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSString+FindFolderTest.m

http://macfuse.googlecode.com/ · Objective C · 83 lines · 46 code · 13 blank · 24 comment · 1 complexity · 0f2f401be87f07e71f45e72f4c09abf8 MD5 · raw file

  1. //
  2. // GTMNSString+FindFolderTest.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 "GTMNSString+FindFolder.h"
  20. @interface GTMNSString_FindFolderTest : GTMTestCase
  21. @end
  22. @implementation GTMNSString_FindFolderTest
  23. - (void)testStringWithPathForFolder {
  24. // for gtm_stringWithPathForFolder:inDomain:doCreate:
  25. // the parameters all get passed through to FSFindFolder so there's no point testing
  26. // other combinations; our semantics will match FSFindFolder's
  27. NSString *prefsPath = [NSString gtm_stringWithPathForFolder:kPreferencesFolderType
  28. inDomain:kUserDomain
  29. doCreate:NO];
  30. NSString *realPrefsPath = [@"~/Library/Preferences" stringByExpandingTildeInPath];
  31. STAssertEqualObjects(realPrefsPath, prefsPath, @"Found incorrect prefs path");
  32. // test the subfolder method; it should return nil if we pass NO and the
  33. // subfolder doesn't already exist
  34. NSString *googCacheNoCreatePath = [NSString gtm_stringWithPathForFolder:kCachedDataFolderType
  35. subfolderName:@"GTMUnitTestDuzntExist"
  36. inDomain:kUserDomain
  37. doCreate:NO];
  38. STAssertNil(googCacheNoCreatePath, @"Should not exist: %@", googCacheNoCreatePath);
  39. // test creating ~/Library/Cache/GTMUnitTestCreated
  40. NSString *folderName = @"GTMUnitTestCreated";
  41. NSString *gtmCachePath = [NSString gtm_stringWithPathForFolder:kCachedDataFolderType
  42. subfolderName:folderName
  43. inDomain:kUserDomain
  44. doCreate:YES];
  45. NSString *testPath = [NSString gtm_stringWithPathForFolder:kCachedDataFolderType
  46. inDomain:kUserDomain
  47. doCreate:NO];
  48. NSString *testPathAppended = [testPath stringByAppendingPathComponent:folderName];
  49. STAssertEqualObjects(gtmCachePath, testPathAppended, @"Unexpected path name");
  50. NSFileManager* fileMgr = [NSFileManager defaultManager];
  51. BOOL isDir = NO;
  52. BOOL pathExists = [fileMgr fileExistsAtPath:gtmCachePath isDirectory:&isDir] && isDir;
  53. STAssertTrue(pathExists, @"Path %@ is not existing like it should", gtmCachePath);
  54. // test finding it again w/o having to create it
  55. NSString *gtmCachePath2 = [NSString gtm_stringWithPathForFolder:kCachedDataFolderType
  56. subfolderName:folderName
  57. inDomain:kUserDomain
  58. doCreate:NO];
  59. STAssertEqualObjects(gtmCachePath2, gtmCachePath, nil);
  60. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  61. NSError *error = nil;
  62. BOOL didRemove = [fileMgr removeItemAtPath:gtmCachePath error:&error];
  63. STAssertTrue(didRemove, @"Error removing %@ (%@)", gtmCachePath, error);
  64. #else
  65. BOOL didRemove = [fileMgr removeFileAtPath:gtmCachePath
  66. handler:nil];
  67. STAssertTrue(didRemove, @"Error removing %@", gtmCachePath);
  68. #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  69. }
  70. @end