PageRenderTime 69ms CodeModel.GetById 24ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 0ms

/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
19#import "GTMSenTestCase.h"
20#import "GTMNSFileManager+Carbon.h"
21#import "GTMUnitTestDevLog.h"
22#import <CoreServices/CoreServices.h>
23
24@interface GTMNSFileManager_CarbonTest : GTMTestCase
25@end
26  
27@implementation GTMNSFileManager_CarbonTest
28
29- (void)testAliasPathFSRefConversion {
30  NSString *path = NSHomeDirectory();
31  STAssertNotNil(path, nil);
32  NSFileManager *fileManager = [NSFileManager defaultManager];
33  FSRef *fsRef = [fileManager gtm_FSRefForPath:path];
34  STAssertNotNULL(fsRef, nil);
35  AliasHandle alias;
36  STAssertNoErr(FSNewAlias(nil, fsRef, &alias), nil);
37  STAssertNotNULL(alias, nil);
38  NSData *aliasData = [NSData dataWithBytes:*alias 
39                                     length:GetAliasSize(alias)];
40  STAssertNotNil(aliasData, nil);
41  NSString *path2 = [fileManager gtm_pathFromAliasData:aliasData];
42  STAssertEqualObjects(path, path2, nil);
43
44  path2 = [fileManager gtm_pathFromAliasData:aliasData
45                                     resolve:YES
46                                      withUI:NO];
47  STAssertEqualObjects(path, path2, nil);
48  
49  path2 = [fileManager gtm_pathFromAliasData:aliasData
50                                     resolve:NO
51                                      withUI:NO];
52  STAssertEqualObjects(path, path2, nil);
53
54  NSData *aliasData2 = [fileManager gtm_aliasDataForPath:path2];
55  STAssertNotNil(aliasData2, nil);
56  NSString *path3 = [fileManager gtm_pathFromAliasData:aliasData2];
57  STAssertEqualObjects(path2, path3, nil);
58  NSString *path4 = [fileManager gtm_pathFromFSRef:fsRef];
59  STAssertEqualObjects(path, path4, nil);
60  
61  // Failure cases
62  [GTMUnitTestDevLogDebug expectPattern:@"DebugAssert: "
63    @"GoogleToolboxForMac: FSPathMakeRef.*"];
64  STAssertNULL([fileManager gtm_FSRefForPath:@"/ptah/taht/dosent/esixt/"], 
65               nil);
66
67  STAssertNULL([fileManager gtm_FSRefForPath:@""], nil);
68  STAssertNULL([fileManager gtm_FSRefForPath:nil], nil);
69  STAssertNil([fileManager gtm_pathFromFSRef:nil], nil);
70  STAssertNil([fileManager gtm_pathFromAliasData:nil], nil);
71  STAssertNil([fileManager gtm_pathFromAliasData:[NSData data]], nil);
72  
73  [GTMUnitTestDevLogDebug expectPattern:@"DebugAssert: "
74   @"GoogleToolboxForMac: FSPathMakeRef.*"];
75  STAssertNil([fileManager gtm_aliasDataForPath:@"/ptah/taht/dosent/esixt/"], nil);
76  STAssertNil([fileManager gtm_aliasDataForPath:@""], nil);
77  STAssertNil([fileManager gtm_aliasDataForPath:nil], nil);
78}
79@end