ADDED tests/terminal/Makefile Index: tests/terminal/Makefile ================================================================== --- tests/terminal/Makefile +++ tests/terminal/Makefile @@ -0,0 +1,68 @@ +include ../../extra.mk + +PROG_NOINST = terminal_tests${PROG_SUFFIX} +SRCS = TerminalTests.m + +include ../../buildsys.mk + +post-all: ${RUN_TESTS} + +.PHONY: run +run: + rm -f libobjfw.so.${OBJFW_LIB_MAJOR} + rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} + rm -f objfw.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib + rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} + rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} + rm -f objfwrt.dll libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib + rm -f ${OBJFWRT_AMIGA_LIB} + if test -f ../../src/libobjfw.so; then \ + ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ + ${LN_S} ../../src/libobjfw.so \ + libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ + elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ + ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ + libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ + fi + if test -f ../../src/objfw.dll; then \ + ${LN_S} ../../src/objfw.dll objfw.dll; \ + fi + if test -f ../../src/libobjfw.dylib; then \ + ${LN_S} ../../src/libobjfw.dylib \ + libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ + fi + if test -f ../../src/runtime/libobjfwrt.so; then \ + ${LN_S} ../../src/runtime/libobjfwrt.so \ + libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ + ${LN_S} ../../src/runtime/libobjfwrt.so \ + libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ + elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ + ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ + fi + if test -f ../../src/runtime/objfwrt.dll; then \ + ${LN_S} ../../src/runtime/objfwrt.dll objfwrt.dll; \ + fi + if test -f ../../src/runtime/libobjfwrt.dylib; then \ + ${LN_S} ../../src/runtime/libobjfwrt.dylib \ + libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ + fi + if test -f ../../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ + ${LN_S} ../../src/runtime/${OBJFWRT_AMIGA_LIB} \ + ${OBJFWRT_AMIGA_LIB}; \ + fi + LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ + DYLD_FRAMEWORK_PATH=../../src:../../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ + DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ + LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ + ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ + rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ + rm -f objfw.so.${OBJFW_LIB_MAJOR_MINOR} objfw.dll; \ + rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ + rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ + rm -f objfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} objfwrt.dll; \ + rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ + exit $$EXIT + +CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. +LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} +LD = ${OBJC} ADDED tests/terminal/TerminalTests.m Index: tests/terminal/TerminalTests.m ================================================================== --- tests/terminal/TerminalTests.m +++ tests/terminal/TerminalTests.m @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018, 2019, 2020 + * 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 "OFApplication.h" +#import "OFArray.h" +#import "OFColor.h" +#import "OFStdIOStream.h" +#import "OFThread.h" + +@interface TerminalTests: OFObject +@end + +OF_APPLICATION_DELEGATE(TerminalTests) + +@implementation TerminalTests +- (void)applicationDidFinishLaunching +{ + OFArray *colors = [OFArray arrayWithObjects: + [OFColor black], [OFColor silver], [OFColor grey], [OFColor white], + [OFColor maroon], [OFColor red], [OFColor purple], + [OFColor fuchsia], [OFColor green], [OFColor lime], [OFColor olive], + [OFColor yellow], [OFColor navy], [OFColor blue], [OFColor teal], + [OFColor aqua], nil]; + size_t i; + OFEnumerator OF_GENERIC(OFColor *) *reverseEnumerator; + + [of_stdout writeFormat: @"%dx%d\n", of_stdout.columns, of_stdout.rows]; + + i = 0; + for (OFColor *color in colors) { + of_stdout.foregroundColor = color; + [of_stdout writeFormat: @"%zx", i++]; + } + [of_stdout reset]; + [of_stdout writeLine: @"R"]; + + i = 0; + for (OFColor *color in colors) { + of_stdout.backgroundColor = color; + [of_stdout writeFormat: @"%zx", i++]; + } + [of_stdout reset]; + [of_stdout writeLine: @"R"]; + + i = 0; + reverseEnumerator = [colors.reversedArray objectEnumerator]; + for (OFColor *color in colors) { + of_stdout.foregroundColor = color; + of_stdout.backgroundColor = [reverseEnumerator nextObject]; + [of_stdout writeFormat: @"%zx", i++]; + } + [of_stdout reset]; + [of_stdout writeLine: @"R"]; + + for (i = 0; i < colors.count * 2; i++) { + if (i % 2) + of_stdout.backgroundColor = [colors objectAtIndex: + ((i / 2) + 2) % colors.count]; + else + of_stdout.foregroundColor = + [colors objectAtIndex: i / 2]; + + [of_stdout writeFormat: @"%zx", i / 2]; + } + [of_stdout reset]; + [of_stdout writeLine: @"R"]; + + [of_stdout writeLine: @"Press return"]; + [of_stdin readLine]; + + of_stdout.backgroundColor = [OFColor green]; + [of_stdout writeString: @"Hello!"]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout eraseLine]; + [of_stdout writeString: @"World!"]; + [OFThread sleepForTimeInterval: 2]; + + [of_stdout clear]; + [OFThread sleepForTimeInterval: 2]; + + of_stdout.cursorPosition = of_point(5, 3); + [of_stdout writeString: @"Text at (5, 3)"]; + [OFThread sleepForTimeInterval: 2]; + + [of_stdout setRelativeCursorPosition: of_point(-2, 0)]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout setRelativeCursorPosition: of_point(2, 0)]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout setRelativeCursorPosition: of_point(0, -2)]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout setRelativeCursorPosition: of_point(0, 2)]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout setRelativeCursorPosition: of_point(1, 1)]; + [OFThread sleepForTimeInterval: 2]; + [of_stdout setRelativeCursorPosition: of_point(-1, -1)]; + [OFThread sleepForTimeInterval: 2]; + + of_stdout.cursorColumn = 2; + [OFThread sleepForTimeInterval: 2]; + + [of_stdout reset]; + + [OFApplication terminate]; +} +@end