add simple tests for create/reading/remove empty file

This commit is contained in:
rfm 2024-02-15 11:16:20 +00:00
parent 87fc1f5e2e
commit 01573cb25e

View file

@ -53,18 +53,20 @@
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *dir = @"NSFileManagerTestDir";
MyHandler *handler = [MyHandler new];
NSDictionary *attr;
NSString *dirInDir;
NSString *str1,*str2;
NSString *tmp;
NSError *err;
NSDictionary *errInfo;
BOOL exists;
BOOL isDir;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *dir = @"NSFileManagerTestDir";
MyHandler *handler = [MyHandler new];
NSDictionary *attr;
NSString *dirInDir;
NSString *str1;
NSString *str2;
NSMutableString *mstr;
NSString *tmp;
NSError *err;
NSDictionary *errInfo;
BOOL exists;
BOOL isDir;
dirInDir = [dir stringByAppendingPathComponent: @"WithinDirectory"];
@ -127,6 +129,19 @@ int main()
"NSFileManager can get current dir");
}
PASS([mgr createFileAtPath: @"NSFMFile"
contents: [NSData data]
attributes: nil],
"NSFileManager creates an empty file")
PASS([mgr fileExistsAtPath: @"NSFMFile"],"-fileExistsAtPath: agrees")
str1 = [NSString stringWithContentsOfFile: @"NSFMFile"];
PASS_EQUAL(str1, @"", "empty file produces empty string")
mstr = [NSMutableString stringWithContentsOfFile: @"NSFMFile"];
PASS([mstr isKindOfClass: [NSMutableString class]] && [mstr isEqual: @""],
"empty file produces empty mutable string")
PASS([mgr removeFileAtPath: @"NSFMFile" handler: handler],
"NSFileManager removes an empty file")
str1 = @"A string";
PASS([mgr createFileAtPath: @"NSFMFile"
contents: [str1 dataUsingEncoding: 1]