PageRenderTime 55ms CodeModel.GetById 12ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 0ms

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