Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -48,10 +48,11 @@ OFObjectTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ OFSetTests.m \ + OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFUTF8StringTests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ ADDED new_tests/OFStreamTests.m Index: new_tests/OFStreamTests.m ================================================================== --- new_tests/OFStreamTests.m +++ new_tests/OFStreamTests.m @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2008-2024 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.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFStreamTests: OTTestCase +@end + +@interface OFTestStream: OFStream +{ + int _state; +} +@end + +@implementation OFStreamTests +- (void)testStream +{ + size_t pageSize = [OFSystemInfo pageSize]; + OFTestStream *stream = [[[OFTestStream alloc] init] autorelease]; + char *cString = OFAllocMemory(pageSize - 2, 1); + + @try { + OFString *string; + + memset(cString, 'X', pageSize - 3); + cString[pageSize - 3] = '\0'; + + OTAssertEqualObjects([stream readLine], @"foo"); + + string = [stream readLine]; + OTAssertNotNil(string); + OTAssertEqual(string.length, pageSize - 3); + OTAssertEqual(strcmp(string.UTF8String, cString), 0); + } @finally { + OFFreeMemory(cString); + } +} +@end + +@implementation OFTestStream +- (bool)lowlevelIsAtEndOfStream +{ + return (_state > 1); +} + +- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size +{ + size_t pageSize = [OFSystemInfo pageSize]; + + switch (_state) { + case 0: + if (size < 1) + return 0; + + memcpy(buffer, "f", 1); + + _state++; + return 1; + case 1: + if (size < pageSize) + return 0; + + memcpy(buffer, "oo\n", 3); + memset((char *)buffer + 3, 'X', pageSize - 3); + + _state++; + return pageSize; + } + + return 0; +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -11,12 +11,11 @@ ${PROG_NOINST}.rpx DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} -SRCS = OFStreamTests.m \ - TestsAppDelegate.m +SRCS = TestsAppDelegate.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk DELETED tests/OFStreamTests.m Index: tests/OFStreamTests.m ================================================================== --- tests/OFStreamTests.m +++ tests/OFStreamTests.m @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2008-2024 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.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFStream"; - -@interface StreamTest: OFStream -{ - int state; -} -@end - -@implementation StreamTest -- (bool)lowlevelIsAtEndOfStream -{ - return (state > 1); -} - -- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size -{ - size_t pageSize = [OFSystemInfo pageSize]; - - switch (state) { - case 0: - if (size < 1) - return 0; - - memcpy(buffer, "f", 1); - - state++; - return 1; - case 1: - if (size < pageSize) - return 0; - - memcpy(buffer, "oo\n", 3); - memset((char *)buffer + 3, 'X', pageSize - 3); - - state++; - return pageSize; - } - - return 0; -} -@end - -@implementation TestsAppDelegate (OFStreamTests) -- (void)streamTests -{ - void *pool = objc_autoreleasePoolPush(); - size_t pageSize = [OFSystemInfo pageSize]; - StreamTest *test = [[[StreamTest alloc] init] autorelease]; - OFString *string; - char *cString; - - cString = OFAllocMemory(pageSize - 2, 1); - memset(cString, 'X', pageSize - 3); - cString[pageSize - 3] = '\0'; - - TEST(@"-[readLine] #1", [[test readLine] isEqual: @"foo"]) - - string = [test readLine]; - TEST(@"-[readLine] #2", string != nil && - string.length == pageSize - 3 && - !strcmp(string.UTF8String, cString)) - - OFFreeMemory(cString); - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -56,9 +56,5 @@ - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end - -@interface TestsAppDelegate (OFStreamTests) -- (void)streamTests; -@end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -368,12 +368,10 @@ #if defined(OF_WII) && defined(OF_HAVE_FILES) [[OFFileManager defaultManager] changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif - [self streamTests]; - [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails]; [OFApplication terminateWithStatus: _fails];