Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -9,10 +9,11 @@ OFHashes.m \ OFList.m \ OFNumber.m \ OFObject.m \ ${OFPLUGIN_M} \ + OFStream.m \ OFString.m \ OFTCPSocket.m \ ${OFTHREAD_M} \ OFXMLElement.m \ OFXMLParser.m \ ADDED tests/OFStream.m Index: tests/OFStream.m ================================================================== --- tests/OFStream.m +++ tests/OFStream.m @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008 - 2010 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#include "config.h" + +#include + +#import "OFStream.h" +#import "OFAutoreleasePool.h" + +#import "main.h" + +static OFString *module = @"OFStream"; + +@interface StreamTester: OFStream +{ + int state; +} +@end + +@implementation StreamTester +- (BOOL)atEndOfStreamWithoutCache +{ + return (state > 1 ? YES : NO); +} + +- (size_t)readNBytesWithoutCache: (size_t)size + intoBuffer: (char*)buf +{ + switch (state) { + case 0: + if (size < 1) + return 0; + + memcpy(buf, "f", 1); + + state++; + return 1; + case 1: + if (size < of_pagesize) + return 0; + + memcpy(buf, "oo\n", 3); + memset(buf + 3, 'X', of_pagesize - 3); + + state++; + return of_pagesize; + } + + return 0; +} +@end + +void +stream_tests() +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + StreamTester *t = [[[StreamTester alloc] init] autorelease]; + OFString *str; + char *cstr; + + cstr = [t allocMemoryWithSize: of_pagesize - 2]; + memset(cstr, 'X', of_pagesize - 3); + cstr[of_pagesize - 3] = '\0'; + + TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] && + [(str = [t readLine]) length] == of_pagesize - 3 && + !strcmp([str cString], cstr)) + + [pool drain]; +} Index: tests/main.m ================================================================== --- tests/main.m +++ tests/main.m @@ -30,10 +30,11 @@ extern void plugin_tests(); #endif #ifdef OF_HAVE_PROPERTIES extern void properties_tests(); #endif +extern void stream_tests(); extern void string_tests(); extern void tcpsocket_tests(); #ifdef OF_THREADS extern void thread_tests(); #endif @@ -109,10 +110,11 @@ dataarray_tests(); array_tests(); dictionary_tests(); list_tests(); number_tests(); + stream_tests(); tcpsocket_tests(); #ifdef OF_THREADS thread_tests(); #endif xmlelement_tests();