libs-base/Testing/nsfilemanager.m
rfm 0776eec235 print home directory
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26211 72102866-910b-0410-8b05-ffd578937521
2008-03-05 19:12:52 +00:00

96 lines
2.2 KiB
Objective-C

/* Test/example program for the base library
Copyright (C) 2005 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
This file is part of the GNUstep Base Library.
*/
#include <Foundation/Foundation.h>
static int errors = 0;
@interface Handler : NSObject
- (BOOL) fileManager: (NSFileManager*)manager
shouldProceedAfterError: (NSString*)error;
- (BOOL) fileManager: (NSFileManager*)manager
willProcessPath: (NSString*)path;
@end
@implementation Handler
- (BOOL) fileManager: (NSFileManager*)manager
shouldProceedAfterError: (NSString*)error
{
NSLog(@"Error - %@", error);
errors++;
return NO;
}
- (BOOL) fileManager: (NSFileManager*)manager
willProcessPath: (NSString*)path
{
NSLog(@"Processing %@", path);
errors++;
return NO;
}
@end
int
main ()
{
CREATE_AUTORELEASE_POOL(arp);
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *src;
NSString *dst;
Handler *handler = AUTORELEASE([Handler new]);
src = [defs stringForKey: @"CopySrc"];
dst = [defs objectForKey: @"CopyDst"];
if (src != nil && dst != nil)
{
if ([mgr copyPath: src toPath: dst handler: handler] == NO)
{
NSLog(@"Copy %@ to %@ failed", src, dst);
errors++;
}
}
src = [defs stringForKey: @"LinkSrc"];
dst = [defs objectForKey: @"LinkDst"];
if (src != nil && dst != nil)
{
if ([mgr linkPath: src toPath: dst handler: handler] == NO)
{
NSLog(@"Link %@ to %@ failed", src, dst);
errors++;
}
}
src = [defs stringForKey: @"Remove"];
if (src != nil)
{
if ([mgr removeFileAtPath: src handler: handler] == NO)
{
NSLog(@"Remove %@ failed", src);
errors++;
}
}
{
NSDictionary *attributes = [mgr fileSystemAttributesAtPath: @"/"];
NSNumber *freefs = [attributes objectForKey: NSFileSystemFreeSize];
unsigned long long s = [freefs unsignedLongLongValue];
NSLog(@"Filesystem free size is %llu", s);
}
NSLog(@"Home directory is %@", NSHomeDirectory());
RELEASE(arp);
if (errors == 0)
printf("Tests passed\n");
exit (0);
}