1/* 2 Copyright (C) 2005 Free Software Foundation, Inc. 3 4 Written by: David Ayers <d.ayers@inode.at> 5 Date: February 2005 6 7 This file is part of the GNUstep Base Library. 8 9 This library is free software; you can redistribute it and/or 10 modify it under the terms of the GNU Lesser General Public 11 License as published by the Free Software Foundation; either 12 version 2 of the License, or (at your option) any later version. 13 14 This library is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Library General Public License for more details. 18 19 You should have received a copy of the GNU Library General Public 20 License along with this library; if not, write to the Free 21 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. 22 23*/ 24 25#import "Testing.h" 26#import "ObjectTesting.h" 27#import <Foundation/Foundation.h> 28 29int main() 30{ 31 NSAutoreleasePool *arp = [NSAutoreleasePool new]; 32 /* We invert the order so that we really test the FD values when they 33 are not opened in order. */ 34 NSFileHandle *stdErrFH = [NSFileHandle fileHandleWithStandardError]; 35 NSFileHandle *stdOutFH = [NSFileHandle fileHandleWithStandardOutput]; 36 NSFileHandle *stdInFH = [NSFileHandle fileHandleWithStandardInput]; 37 NSFileHandle *stdNullFH = [NSFileHandle fileHandleWithNullDevice]; 38 NSFileHandle *t1FH, *t2FH; 39 NSString *tPath = [NSString stringWithFormat:@"%@/%@",NSTemporaryDirectory(),[[NSProcessInfo processInfo]globallyUniqueString]]; 40 NSData *t1Data = [tPath dataUsingEncoding:NSUTF8StringEncoding]; 41 NSData *t2Data; 42 43 PASS([stdInFH isKindOfClass:[NSFileHandle class]], 44 "NSFileHandle understands +fileHandleWithStandardInput"); 45 PASS([stdInFH fileDescriptor]==0, 46 "NSFileHandle +fileHandleWithStandardInput has 0 as fileDescriptor"); 47 48 PASS([stdOutFH isKindOfClass:[NSFileHandle class]], 49 "NSFileHandle understands +fileHandleWithStandardOutput"); 50 PASS([stdOutFH fileDescriptor]==1, 51 "NSFileHandle +fileHandleWithStandardOutput has 1 as fileDescriptor"); 52 53 PASS([stdErrFH isKindOfClass:[NSFileHandle class]], 54 "NSFileHandle understands +fileHandleWithStandardError"); 55 PASS([stdErrFH fileDescriptor]==2, 56 "NSFileHandle +fileHandleWithStandardError has 2 as fileDescriptor"); 57 58 PASS([stdNullFH isKindOfClass:[NSFileHandle class]], 59 "NSFileHandle understands +fileHandleWithNullDevice"); 60 61 t1FH = [[NSFileHandle alloc] initWithFileDescriptor: 0]; 62 PASS([t1FH isKindOfClass:[NSFileHandle class]], 63 "NSFileHandle understands -initWithFileDescriptor:"); 64 65 t1FH = [NSFileHandle fileHandleForWritingAtPath: tPath]; 66 PASS(t1FH == nil, 67 "NSFileHandle +fileHandleForWritingAtPath: with non-existing file return nil"); 68 69 [@"" writeToFile: tPath atomically: YES]; 70 t1FH = [NSFileHandle fileHandleForWritingAtPath: tPath]; 71 PASS([t1FH isKindOfClass:[NSFileHandle class]], 72 "NSFileHandle understands +fileHandleForWritingAtPath:"); 73 74 t2FH = [NSFileHandle fileHandleForReadingAtPath: tPath]; 75 PASS([t2FH isKindOfClass:[NSFileHandle class]], 76 "NSFileHandle understands +fileHandleForReadingAtPath:"); 77 78 [t1FH writeData: t1Data]; 79 t2Data = [t2FH availableData]; 80 PASS([t1Data isEqual: t2Data], 81 "NSFileHandle -writeData:/-availableData match"); 82 83 [[NSFileManager defaultManager] removeFileAtPath: tPath handler: nil]; 84 85 [arp release]; arp = nil; 86 return 0; 87} 88