aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSFileManager+PathTest.m
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-12-11 17:04:57 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2009-12-11 17:04:57 +0000
commit7252815552530ba1f552d1a48d3fae85ecf67b45 (patch)
treefdf555e71fb5939583cd9ff9b41ef7675b330482 /Foundation/GTMNSFileManager+PathTest.m
parent2f99c0cb93316c3793582d1ed6769f031adffb3f (diff)
[Author: thomasvl]
Some style cleanup. R=dmaclach DELTA=9 (3 added, 1 deleted, 5 changed)
Diffstat (limited to 'Foundation/GTMNSFileManager+PathTest.m')
-rw-r--r--Foundation/GTMNSFileManager+PathTest.m45
1 files changed, 23 insertions, 22 deletions
diff --git a/Foundation/GTMNSFileManager+PathTest.m b/Foundation/GTMNSFileManager+PathTest.m
index 756eb54..86f365f 100644
--- a/Foundation/GTMNSFileManager+PathTest.m
+++ b/Foundation/GTMNSFileManager+PathTest.m
@@ -6,9 +6,9 @@
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
-//
+//
// http://www.apache.org/licenses/LICENSE-2.0
-//
+//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -23,7 +23,7 @@
NSString *baseDir_;
}
@end
-
+
@implementation GTMNSFileManager_PathTest
- (void)setUp {
@@ -55,7 +55,7 @@
@"Unable to delete %@: %@", baseDir_, [error description]);
#else
[fm removeFileAtPath:baseDir_ handler:nil];
-#endif
+#endif
[baseDir_ release];
baseDir_ = nil;
@@ -71,10 +71,10 @@
[baseDir_ stringByAppendingPathComponent:@"/foo/bar/baz"];
STAssertNotNil(testPath, nil);
NSFileManager *fm = [NSFileManager defaultManager];
-
+
STAssertFalse([fm fileExistsAtPath:testPath],
@"You must delete '%@' before running this test", testPath);
-
+
STAssertFalse([fm gtm_createFullPathToDirectory:nil attributes:nil],
@"didn't fail on nil input");
@@ -82,11 +82,11 @@
@"Failed to create nested testPath");
STAssertTrue([fm gtm_createFullPathToDirectory:testPath attributes:nil],
@"Failed to succeed on second create of testPath");
-
+
NSString *pathToFail = [@"/etc" stringByAppendingPathComponent:testPath];
STAssertFalse([fm gtm_createFullPathToDirectory:pathToFail attributes:nil],
@"We were allowed to create a dir in '/etc'?!");
-
+
STAssertFalse([fm gtm_createFullPathToDirectory:nil attributes:nil],
@"Should have failed when passed (nil)");
}
@@ -95,13 +95,13 @@
- (void)testfilePathsWithExtensionsInDirectory {
STAssertNotNil(baseDir_, @"setUp failed");
-
+
NSFileManager *fm = [NSFileManager defaultManager];
NSString *bogusPath = @"/some/place/that/does/not/exist";
// --------------------------------------------------------------------------
// test fail cases first
-
+
// single
STAssertNil([fm gtm_filePathsWithExtension:nil inDirectory:nil],
@"shouldn't have gotten anything for nil dir");
@@ -120,17 +120,17 @@
STAssertNil([fm gtm_filePathsWithExtensions:[NSArray arrayWithObject:@"txt"]
inDirectory:bogusPath],
@"shouldn't have gotten anything for a bogus dir");
-
+
// --------------------------------------------------------------------------
// create some test data
-
+
NSString *testDirs[] = {
@"", @"/foo", // mave a subdir to make sure we don't match w/in it
};
NSString *testFiles[] = {
@"a.txt", @"b.txt", @"c.rtf", @"d.m",
};
-
+
for (size_t i = 0; i < sizeof(testDirs) / sizeof(NSString*); i++) {
NSString *testDir = nil;
if ([testDirs[i] length]) {
@@ -141,13 +141,14 @@
}
for (size_t j = 0; j < sizeof(testFiles) / sizeof(NSString*); j++) {
NSString *testFile = [testDir stringByAppendingPathComponent:testFiles[j]];
+ NSError *err = nil;
STAssertTrue([@"test" writeToFile:testFile
atomically:YES
encoding:NSUTF8StringEncoding
- error:nil], nil);
+ error:&err], @"Error: %@", err);
}
}
-
+
// build set of the top level items
NSMutableArray *allFiles = [NSMutableArray array];
for (size_t i = 0; i < sizeof(testDirs) / sizeof(NSString*); i++) {
@@ -164,7 +165,7 @@
NSArray *matches = nil;
NSArray *expectedMatches = nil;
NSArray *extensions = nil;
-
+
// NOTE: we do all compares w/ sets so order doesn't matter
// --------------------------------------------------------------------------
@@ -189,7 +190,7 @@
STAssertEqualObjects([NSSet setWithArray:matches],
[NSSet setWithArray:allFiles],
@"didn't get all files for nil extension");
-
+
// --------------------------------------------------------------------------
// test match something
@@ -212,10 +213,10 @@
STAssertEqualObjects([NSSet setWithArray:matches],
[NSSet setWithArray:expectedMatches],
@"didn't get expected files");
-
+
// --------------------------------------------------------------------------
// test match nothing
-
+
// single
extensions = [NSArray arrayWithObject:@"xyz"];
matches = [fm gtm_filePathsWithExtension:@"xyz" inDirectory:baseDir_];
@@ -229,14 +230,14 @@
STAssertEqualObjects([NSSet setWithArray:matches],
[NSSet setWithArray:expectedMatches],
@"didn't get expected files");
-
+
// --------------------------------------------------------------------------
// test match an empty dir
-
+
// create the empty dir
NSString *emptyDir = [baseDir_ stringByAppendingPathComponent:@"emptyDir"];
STAssertTrue([fm createDirectoryAtPath:emptyDir attributes:nil], nil);
-
+
// single
matches = [fm gtm_filePathsWithExtension:@"txt" inDirectory:emptyDir];
STAssertEqualObjects([NSSet setWithArray:matches], [NSSet set],