libs-base/Testing/nsfilemanager.m
Richard Frith-MacDonald 5d124ff9cf More socket improvments
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25906 72102866-910b-0410-8b05-ffd578937521
2008-01-09 16:11:10 +00:00

92 lines
2.1 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];
NSLog(@"Filesystem free size is %@", freefs);
}
RELEASE(arp);
if (errors == 0)
printf("Tests passed\n");
exit (0);
}