2005-07-01 21:00:04 +00:00
|
|
|
/* Test/example program for the base library
|
|
|
|
|
|
|
|
Copyright (C) 2005 Free Software Foundation, Inc.
|
|
|
|
|
2005-07-15 22:51:23 +00:00
|
|
|
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.
|
|
|
|
|
2005-07-01 21:00:04 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
*/
|
2002-07-08 11:19:23 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
|
2003-03-23 07:06:27 +00:00
|
|
|
static int errors = 0;
|
|
|
|
|
2002-07-08 11:19:23 +00:00
|
|
|
@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);
|
2003-03-23 07:06:27 +00:00
|
|
|
errors++;
|
2002-07-08 11:19:23 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
- (BOOL) fileManager: (NSFileManager*)manager
|
|
|
|
willProcessPath: (NSString*)path
|
|
|
|
{
|
|
|
|
NSLog(@"Processing %@", path);
|
2003-03-23 07:06:27 +00:00
|
|
|
errors++;
|
2002-07-08 11:19:23 +00:00
|
|
|
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);
|
2003-03-23 07:06:27 +00:00
|
|
|
errors++;
|
2002-07-08 11:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 11:23:29 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-08 11:19:23 +00:00
|
|
|
src = [defs stringForKey: @"Remove"];
|
|
|
|
if (src != nil)
|
|
|
|
{
|
|
|
|
if ([mgr removeFileAtPath: src handler: handler] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"Remove %@ failed", src);
|
2003-03-23 07:06:27 +00:00
|
|
|
errors++;
|
2002-07-08 11:19:23 +00:00
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-07-08 11:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE(arp);
|
2003-03-23 07:06:27 +00:00
|
|
|
if (errors == 0)
|
|
|
|
printf("Tests passed\n");
|
2002-07-08 11:19:23 +00:00
|
|
|
exit (0);
|
|
|
|
}
|