Add a unit test for FTermOpenBSD to test the OpenBSD and NetBSD console

This commit is contained in:
Markus Gans 2019-07-14 23:05:54 +02:00
parent ff9673d262
commit c49252ab45
17 changed files with 534 additions and 46 deletions

View File

@ -1,5 +1,7 @@
2019-07-14 Markus Gans <guru.mail@muenster.de> 2019-07-14 Markus Gans <guru.mail@muenster.de>
* Reduces the use of raw loops * Reduces the use of raw loops
* Add a unit test for FTermOpenBSD to test the OpenBSD
and NetBSD console
2019-06-30 Markus Gans <guru.mail@muenster.de> 2019-06-30 Markus Gans <guru.mail@muenster.de>
* Expanding the unit test for FTermLinux * Expanding the unit test for FTermLinux

View File

@ -83,7 +83,7 @@ case "$1" in
;; ;;
"--unit-test"|"unit-test") "--unit-test"|"unit-test")
if ! ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG" --with-unit-test if ! ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -DUNIT_TEST" --with-unit-test
then then
echo "${RED}Configure failed!${NORMAL}" 1>&2 echo "${RED}Configure failed!${NORMAL}" 1>&2
exit 255 exit 255

20
doc/build_openbsd.txt Normal file
View File

@ -0,0 +1,20 @@
Install egcc on OpenBSD
-----------------------
openbsd# pkg_add g++
quirks-3.124 signed on 2019-04-15T12:10:16Z
Ambiguous: choose package for g++
a 0: <None>
1: g++-4.9.4p18
2: g++-8.3.0
Your choice: 2
g++-8.3.0:gcc-libs-8.3.0: ok
g++-8.3.0:gmp-6.1.2p3: ok
g++-8.3.0:mpfr-3.1.5.2p0: ok
g++-8.3.0:libmpc-0.9p2: ok
g++-8.3.0:gcc-8.3.0: ok
g++-8.3.0: ok
Build FINAL CUT with eg++
-------------------------
openbsd# CXX=eg++ ./build.sh

View File

@ -2,8 +2,8 @@
if [ $# -gt 0 ] if [ $# -gt 0 ]
then then
eval cppcheck --force --enable=all -I../src/include/ "$@" eval cppcheck --force --std=c++11 --enable=all -I../src/include/ "$@"
else else
eval cppcheck --force --enable=all -I../src/include/ ../src/ ../examples/ eval cppcheck --force --std=c++11 --enable=all -I../src/include/ ../src/ ../examples/
fi fi

View File

@ -249,7 +249,7 @@ void FButton::hide()
if ( size == 0 ) if ( size == 0 )
return; return;
auto blank = createBlankArray(size + 1); char* blank = createBlankArray(size + 1);
for (std::size_t y = 0; y < getHeight() + s + (f << 1); y++) for (std::size_t y = 0; y < getHeight() + s + (f << 1); y++)
{ {

View File

@ -216,7 +216,7 @@ void FButtonGroup::hide()
if ( size == 0 ) if ( size == 0 )
return; return;
auto blank = createBlankArray(size + 1); char* blank = createBlankArray(size + 1);
for (int y = 0; y < int(getHeight()); y++) for (int y = 0; y < int(getHeight()); y++)
{ {

View File

@ -309,7 +309,7 @@ void FListBox::clear()
if ( size == 0 ) if ( size == 0 )
return; return;
auto blank = createBlankArray(size + 1); char* blank = createBlankArray(size + 1);
std::memset (blank, ' ', size); std::memset (blank, ' ', size);
blank[size] = '\0'; blank[size] = '\0';

View File

@ -65,7 +65,7 @@ void FMenuBar::hide()
FColor bg = wc.term_bg; FColor bg = wc.term_bg;
setColor (fg, bg); setColor (fg, bg);
screenWidth = getDesktopWidth(); screenWidth = getDesktopWidth();
auto blank = createBlankArray (screenWidth + 1); char* blank = createBlankArray (screenWidth + 1);
print() << FPoint(1, 1) << blank; print() << FPoint(1, 1) << blank;
destroyBlankArray (blank); destroyBlankArray (blank);
} }

View File

@ -177,7 +177,7 @@ void FStatusBar::hide()
FColor bg = wc.term_bg; FColor bg = wc.term_bg;
setColor (fg, bg); setColor (fg, bg);
screenWidth = getDesktopWidth(); screenWidth = getDesktopWidth();
auto blank = createBlankArray(screenWidth + 1); char* blank = createBlankArray(screenWidth + 1);
print() << FPoint(1, 1) << blank; print() << FPoint(1, 1) << blank;
destroyBlankArray (blank); destroyBlankArray (blank);
} }

View File

@ -20,13 +20,14 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#include "final/fterm.h"
#include "final/ftermopenbsd.h" #include "final/ftermopenbsd.h"
namespace finalcut namespace finalcut
{ {
// static class attributes // static class attributes
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
kbd_t FTermOpenBSD::bsd_keyboard_encoding = 0; kbd_t FTermOpenBSD::bsd_keyboard_encoding = 0;
bool FTermOpenBSD::meta_sends_escape = true; bool FTermOpenBSD::meta_sends_escape = true;
FSystem* FTermOpenBSD::fsystem = nullptr; FSystem* FTermOpenBSD::fsystem = nullptr;
@ -39,7 +40,7 @@ namespace finalcut
// public methods of FTermOpenBSD // public methods of FTermOpenBSD
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
bool FTermOpenBSD::isBSDConsole() bool FTermOpenBSD::isBSDConsole()
{ {
// Check if it's a NetBSD/OpenBSD workstation console // Check if it's a NetBSD/OpenBSD workstation console
@ -47,7 +48,7 @@ bool FTermOpenBSD::isBSDConsole()
static kbd_t kbdencoding; static kbd_t kbdencoding;
if ( fsystem if ( fsystem
&& fsysten->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 ) && fsystem->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 )
return true; return true;
else else
return false; return false;
@ -58,11 +59,11 @@ void FTermOpenBSD::init()
{ {
// initialize BSD workstation console // initialize BSD workstation console
fsystem = FTerm::getFSystem();
if ( ! isBSDConsole() ) if ( ! isBSDConsole() )
return; return;
fsystem = FTerm::getFSystem();
if ( meta_sends_escape ) if ( meta_sends_escape )
{ {
// save current left alt key mapping // save current left alt key mapping
@ -92,7 +93,7 @@ bool FTermOpenBSD::saveBSDConsoleEncoding()
int ret = -1; int ret = -1;
if ( fsystem ) if ( fsystem )
ret = fsysten->ioctl (0, WSKBDIO_GETENCODING, &k_encoding); ret = fsystem->ioctl (0, WSKBDIO_GETENCODING, &k_encoding);
if ( ret < 0 ) if ( ret < 0 )
return false; return false;
@ -105,8 +106,8 @@ bool FTermOpenBSD::saveBSDConsoleEncoding()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding) bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding)
{ {
if ( fsysten if ( fsystem
&& fsysten->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) && fsystem->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 )
return false; return false;
else else
return true; return true;
@ -125,6 +126,6 @@ bool FTermOpenBSD::resetBSDConsoleEncoding()
{ {
return setBSDConsoleEncoding (bsd_keyboard_encoding); return setBSDConsoleEncoding (bsd_keyboard_encoding);
} }
#endif // defined(__NetBSD__) || defined(__OpenBSD__) #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
} // namespace finalcut } // namespace finalcut

View File

@ -294,7 +294,7 @@ void FTextView::clear()
if ( size == 0 ) if ( size == 0 )
return; return;
auto blank = createBlankArray(size + 1); char* blank = createBlankArray(size + 1);
for (int y = 0; y < int(getTextHeight()); y++) for (int y = 0; y < int(getTextHeight()); y++)
{ {

View File

@ -1638,7 +1638,7 @@ void FWidget::hideSize (const FSize& size)
} }
setColor (fg, bg); setColor (fg, bg);
auto blank = createBlankArray(size.getWidth()); char* blank = createBlankArray(size.getWidth());
if ( blank == 0 ) if ( blank == 0 )
return; return;

View File

@ -38,7 +38,11 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "final/fsystem.h" #include "final/fsystem.h"
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(UNIT_TEST)
#define WSKBDIO_GETENCODING uInt32(0x4004570F)
#define WSKBDIO_SETENCODING uInt32(0x80045710)
typedef uInt32 kbd_t;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/time.h> #include <sys/time.h>
#include <dev/wscons/wsconsio.h> #include <dev/wscons/wsconsio.h>
#endif #endif
@ -83,7 +87,7 @@ class FTermOpenBSD final
static void finish(); static void finish();
private: private:
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
// Methods // Methods
static bool saveBSDConsoleEncoding(); static bool saveBSDConsoleEncoding();
static bool setBSDConsoleEncoding (kbd_t); static bool setBSDConsoleEncoding (kbd_t);
@ -94,7 +98,7 @@ class FTermOpenBSD final
static kbd_t bsd_keyboard_encoding; static kbd_t bsd_keyboard_encoding;
static bool meta_sends_escape; static bool meta_sends_escape;
static FSystem* fsystem; static FSystem* fsystem;
#endif // defined(__NetBSD__) || defined(__OpenBSD__) #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
}; };
#pragma pack(pop) #pragma pack(pop)
@ -104,14 +108,14 @@ inline const char* FTermOpenBSD::getClassName() const
{ return "FTermOpenBSD"; } { return "FTermOpenBSD"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__) #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
inline void FTermOpenBSD::enableMetaSendsEscape() inline void FTermOpenBSD::enableMetaSendsEscape()
{ meta_sends_escape = true; } { meta_sends_escape = true; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTermOpenBSD::disableMetaSendsEscape() inline void FTermOpenBSD::disableMetaSendsEscape()
{ meta_sends_escape = false; } { meta_sends_escape = false; }
#endif // defined(__NetBSD__) || defined(__OpenBSD__) #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
} // namespace finalcut } // namespace finalcut

View File

@ -14,6 +14,7 @@ noinst_PROGRAMS = \
ftermdetection_test \ ftermdetection_test \
ftermcapquirks_test \ ftermcapquirks_test \
ftermlinux_test \ ftermlinux_test \
ftermopenbsd_test \
foptimove_test \ foptimove_test \
foptiattr_test \ foptiattr_test \
fcolorpair_test \ fcolorpair_test \
@ -29,6 +30,7 @@ ftermdata_test_SOURCES = ftermdata-test.cpp
ftermdetection_test_SOURCES = ftermdetection-test.cpp ftermdetection_test_SOURCES = ftermdetection-test.cpp
ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp
ftermlinux_test_SOURCES = ftermlinux-test.cpp ftermlinux_test_SOURCES = ftermlinux-test.cpp
ftermopenbsd_test_SOURCES = ftermopenbsd-test.cpp
foptimove_test_SOURCES = foptimove-test.cpp foptimove_test_SOURCES = foptimove-test.cpp
foptiattr_test_SOURCES = foptiattr-test.cpp foptiattr_test_SOURCES = foptiattr-test.cpp
fcolorpair_test_SOURCES = fcolorpair-test.cpp fcolorpair_test_SOURCES = fcolorpair-test.cpp
@ -44,6 +46,7 @@ TESTS = fobject_test \
ftermdetection_test \ ftermdetection_test \
ftermcapquirks_test \ ftermcapquirks_test \
ftermlinux_test \ ftermlinux_test \
ftermopenbsd_test \
foptimove_test \ foptimove_test \
foptiattr_test \ foptiattr_test \
fcolorpair_test \ fcolorpair_test \

View File

@ -788,8 +788,8 @@ inline char* ConEmu::getSEC_DA (console con)
C_STR("\033[>77;20402;0c"), // Mintty C_STR("\033[>77;20402;0c"), // Mintty
0, // Linux console 0, // Linux console
0, // FreeBSD console 0, // FreeBSD console
0, // NetBSD console C_STR("\033[>24;20;0c"), // NetBSD console
0, // OpenBSD console C_STR("\033[>24;20;0c"), // OpenBSD console
0, // Sun console 0, // Sun console
C_STR("\033[>83;40201;0c"), // screen C_STR("\033[>83;40201;0c"), // screen
C_STR("\033[>84;0;0c") // tmux C_STR("\033[>84;0;0c") // tmux

View File

@ -144,7 +144,7 @@ void FTermDetectionTest::ansiTest()
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
setenv ("TERM", "ansi", 1); setenv ("TERM", "ansi", 1);
data.setTermFileName(C_STR("ansi")); data.setTermType(C_STR("ansi"));
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -212,7 +212,7 @@ void FTermDetectionTest::xtermTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm")); data.setTermType(C_STR("xterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -273,7 +273,7 @@ void FTermDetectionTest::rxvtTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("rxvt-cygwin-native")); data.setTermType(C_STR("rxvt-cygwin-native"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -335,7 +335,7 @@ void FTermDetectionTest::urxvtTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("rxvt-unicode-256color")); data.setTermType(C_STR("rxvt-unicode-256color"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -396,7 +396,7 @@ void FTermDetectionTest::mltermTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("mlterm")); data.setTermType(C_STR("mlterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -465,7 +465,7 @@ void FTermDetectionTest::puttyTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm")); data.setTermType(C_STR("xterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -527,7 +527,7 @@ void FTermDetectionTest::kdeKonsoleTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm-256color")); data.setTermType(C_STR("xterm-256color"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -588,7 +588,7 @@ void FTermDetectionTest::gnomeTerminalTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm-256color")); data.setTermType(C_STR("xterm-256color"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -650,7 +650,7 @@ void FTermDetectionTest::newerVteTerminalTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm-256color")); data.setTermType(C_STR("xterm-256color"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -712,7 +712,7 @@ void FTermDetectionTest::ktermTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("kterm")); data.setTermType(C_STR("kterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -781,7 +781,7 @@ void FTermDetectionTest::teraTermTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm")); data.setTermType(C_STR("xterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -843,7 +843,7 @@ void FTermDetectionTest::cygwinTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("cygwin")); data.setTermType(C_STR("cygwin"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -905,7 +905,7 @@ void FTermDetectionTest::minttyTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm-256color")); data.setTermType(C_STR("xterm-256color"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -967,7 +967,7 @@ void FTermDetectionTest::linuxTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("linux")); data.setTermType(C_STR("linux"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1036,7 +1036,7 @@ void FTermDetectionTest::freebsdTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("xterm")); data.setTermType(C_STR("xterm"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1108,7 +1108,7 @@ void FTermDetectionTest::netbsdTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("wsvt25")); data.setTermType(C_STR("wsvt25"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1178,7 +1178,7 @@ void FTermDetectionTest::openbsdTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("vt220")); data.setTermType(C_STR("vt220"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1248,7 +1248,7 @@ void FTermDetectionTest::sunTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("sun-color")); data.setTermType(C_STR("sun-color"));
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1316,7 +1316,7 @@ void FTermDetectionTest::screenTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("screen")); data.setTermType(C_STR("screen"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();
@ -1384,7 +1384,7 @@ void FTermDetectionTest::tmuxTest()
{ {
finalcut::FTermData& data = *finalcut::FTerm::getFTermData(); finalcut::FTermData& data = *finalcut::FTerm::getFTermData();
finalcut::FTermDetection detect; finalcut::FTermDetection detect;
data.setTermFileName(C_STR("screen")); data.setTermType(C_STR("screen"));
detect.setTerminalDetection(true); detect.setTerminalDetection(true);
pid_t pid = forkConEmu(); pid_t pid = forkConEmu();

458
test/ftermopenbsd-test.cpp Normal file
View File

@ -0,0 +1,458 @@
/***********************************************************************
* ftermopenbsd-test.cpp - FTermOpenBSD unit tests *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <limits>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <unistd.h>
#include <conemu.h>
#include <final/final.h>
#define CPPUNIT_ASSERT_CSTRING(expected, actual) \
check_c_string (expected, actual, CPPUNIT_SOURCELINE())
//----------------------------------------------------------------------
void check_c_string ( const char* s1
, const char* s2
, CppUnit::SourceLine sourceLine )
{
if ( s1 == 0 && s2 == 0 ) // Strings are equal
return;
if ( s1 && s2 && std::strcmp (s1, s2) == 0 ) // Strings are equal
return;
::CppUnit::Asserter::fail ("Strings are not equal", sourceLine);
}
namespace test
{
//----------------------------------------------------------------------
// class FSystemTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FSystemTest : public finalcut::FSystem
{
public:
// Constructor
FSystemTest();
// Destructor
virtual ~FSystemTest();
// Methods
virtual uChar inPortByte (uShort) override;
virtual void outPortByte (uChar, uShort) override;
virtual int isTTY (int) override;
virtual int ioctl (int, uLong, ...) override;
virtual int open (const char*, int, ...) override;
virtual int close (int) override;
virtual FILE* fopen (const char*, const char*) override;
virtual int fclose (FILE*) override;
virtual int putchar (int) override;
virtual int tputs (const char*, int, int (*)(int)) override;
virtual uid_t getuid() override;
private:
kbd_t kbdencoding = 512;
};
#pragma pack(pop)
// constructors and destructor
//----------------------------------------------------------------------
FSystemTest::FSystemTest() // constructor
{
}
//----------------------------------------------------------------------
FSystemTest::~FSystemTest() // destructor
{
}
// public methods of FSystemTest
//----------------------------------------------------------------------
uChar FSystemTest::inPortByte (uShort)
{
return 0;
}
//----------------------------------------------------------------------
void FSystemTest::outPortByte (uChar, uShort)
{
}
//----------------------------------------------------------------------
int FSystemTest::isTTY (int fd)
{
std::cerr << "Call: isatty (fd=" << fd << ")\n";
return 1;
}
//----------------------------------------------------------------------
int FSystemTest::ioctl (int fd, uLong request, ...)
{
va_list args;
void* argp;
std::string req_string;
int ret_val = -1;
va_start (args, request);
argp = va_arg (args, void*);
switch ( request )
{
case WSKBDIO_GETENCODING:
{
req_string = "WSKBDIO_GETENCODING";
kbd_t* kbd_enc = static_cast<kbd_t*>(argp);
*kbd_enc = kbdencoding;
ret_val = 0;
break;
}
case WSKBDIO_SETENCODING:
{
req_string = "WSKBDIO_SETENCODING";
kbd_t* kbd_enc = static_cast<kbd_t*>(argp);
kbdencoding = *kbd_enc;
ret_val = 0;
break;
}
case TIOCGWINSZ:
{
req_string = "TIOCGWINSZ";
struct winsize* win_size = static_cast<winsize*>(argp);
win_size->ws_col = 80;
win_size->ws_row = 25;
ret_val = 0;
break;
}
}
va_end (args);
std::cerr << "Call: ioctl (fd=" << fd
<< ", request=" << req_string
<< "(0x" << std::hex << request << ")"
<< ", argp=" << argp << std::dec << ")\n";
return ret_val;
}
//----------------------------------------------------------------------
int FSystemTest::open (const char* pathname, int flags, ...)
{
va_list args;
va_start (args, flags);
mode_t mode = static_cast<mode_t>(va_arg (args, int));
va_end (args);
std::cerr << "Call: open (pathname=\"" << pathname
<< "\", flags=" << flags
<< ", mode=" << mode << ")\n";
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::close (int fildes)
{
std::cerr << "Call: close (fildes=" << fildes << ")\n";
return 0;
}
//----------------------------------------------------------------------
FILE* FSystemTest::fopen (const char* path, const char* mode)
{
std::cerr << "Call: fopen (path=" << path
<< ", mode=" << mode << ")\n";
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::fclose (FILE* fp)
{
std::cerr << "Call: fclose (fp=" << fp << ")\n";
return 0;
}
//----------------------------------------------------------------------
int FSystemTest::putchar (int c)
{
#if defined(__sun) && defined(__SVR4)
return std::putchar(char(c));
#else
return std::putchar(c);
#endif
}
//----------------------------------------------------------------------
int FSystemTest::tputs (const char* str, int affcnt, int (*putc)(int))
{
return ::tputs (str, affcnt, putc);
}
//----------------------------------------------------------------------
uid_t FSystemTest::getuid()
{
return 0;
}
} // namespace test
//----------------------------------------------------------------------
// class ftermopenbsdTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class ftermopenbsdTest : public CPPUNIT_NS::TestFixture, test::ConEmu
{
public:
ftermopenbsdTest();
protected:
void classNameTest();
void netbsdConsoleTest();
void openbsdConsoleTest();
private:
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (ftermopenbsdTest);
// Add a methods to the test suite
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (netbsdConsoleTest);
CPPUNIT_TEST (openbsdConsoleTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#pragma pack(pop)
//----------------------------------------------------------------------
ftermopenbsdTest::ftermopenbsdTest()
{
}
//----------------------------------------------------------------------
void ftermopenbsdTest::classNameTest()
{
const finalcut::FTermOpenBSD p;
const char* const classname = p.getClassName();
CPPUNIT_ASSERT ( std::strcmp(classname, "FTermOpenBSD") == 0 );
}
//----------------------------------------------------------------------
void ftermopenbsdTest::netbsdConsoleTest()
{
finalcut::FTermData* data;
finalcut::FSystem* fsys;
fsys = new test::FSystemTest();
finalcut::FTerm::setFSystem(fsys);
finalcut::FTermDetection* term_detection;
std::cout << "\n";
data = finalcut::FTerm::getFTermData();
auto& encoding_list = data->getEncodingList();
encoding_list["UTF-8"] = finalcut::fc::UTF8;
encoding_list["UTF8"] = finalcut::fc::UTF8;
encoding_list["VT100"] = finalcut::fc::VT100;
encoding_list["PC"] = finalcut::fc::PC;
encoding_list["ASCII"] = finalcut::fc::ASCII;
data->setTermEncoding(finalcut::fc::VT100);
data->setBaudrate(9600);
data->setTermType("wsvt25");
data->setTermFileName("/dev/ttyE1");
data->setTTYFileDescriptor(0);
data->supportShadowCharacter (false);
data->supportHalfBlockCharacter (false);
data->supportCursorOptimisation (true);
data->setCursorHidden (true);
data->useAlternateScreen (false);
data->setASCIIConsole (true);
data->setVT100Console (false);
data->setUTF8Console (false);
data->setUTF8 (false);
data->setNewFont (false);
data->setVGAFont (false);
data->setMonochron (false);
data->setTermResized (false);
term_detection = finalcut::FTerm::getFTermDetection();
term_detection->setTerminalDetection(true);
finalcut::FTermOpenBSD netbsd;
//term_detection->setNetBSDTerm(true);
pid_t pid = forkConEmu();
if ( isConEmuChildProcess(pid) )
{
setenv ("TERM", "wsvt25", 1);
setenv ("COLUMNS", "80", 1);
setenv ("LINES", "25", 1);
unsetenv("TERMCAP");
unsetenv("COLORTERM");
unsetenv("COLORFGBG");
unsetenv("VTE_VERSION");
unsetenv("XTERM_VERSION");
unsetenv("ROXTERM_ID");
unsetenv("KONSOLE_DBUS_SESSION");
unsetenv("KONSOLE_DCOP");
unsetenv("TMUX");
netbsd.init();
term_detection->detect();
finalcut::FTerm::detectTermSize();
CPPUNIT_ASSERT ( isatty(0) == 1 );
CPPUNIT_ASSERT ( term_detection->isNetBSDTerm() );
CPPUNIT_ASSERT ( data->getTermGeometry().getWidth() == 80 );
CPPUNIT_ASSERT ( data->getTermGeometry().getHeight() == 25 );
CPPUNIT_ASSERT ( ! data->hasShadowCharacter() );
CPPUNIT_ASSERT ( ! data->hasHalfBlockCharacter() );
closeConEmuStdStreams();
exit(EXIT_SUCCESS);
}
else // Parent
{
// Start the terminal emulation
startConEmuTerminal (ConEmu::netbsd_con);
if ( waitpid(pid, 0, WUNTRACED) != pid )
std::cerr << "waitpid error" << std::endl;
}
netbsd.finish();
}
//----------------------------------------------------------------------
void ftermopenbsdTest::openbsdConsoleTest()
{
finalcut::FTermData* data;
finalcut::FSystem* fsys;
fsys = new test::FSystemTest();
finalcut::FTerm::setFSystem(fsys);
finalcut::FTermDetection* term_detection;
std::cout << "\n";
data = finalcut::FTerm::getFTermData();
auto& encoding_list = data->getEncodingList();
encoding_list["UTF-8"] = finalcut::fc::UTF8;
encoding_list["UTF8"] = finalcut::fc::UTF8;
encoding_list["VT100"] = finalcut::fc::VT100;
encoding_list["PC"] = finalcut::fc::PC;
encoding_list["ASCII"] = finalcut::fc::ASCII;
data->setTermEncoding(finalcut::fc::VT100);
data->setBaudrate(9600);
data->setTermType("vt220");
data->setTermFileName("/dev/ttyC0");
data->setTTYFileDescriptor(0);
data->supportShadowCharacter (false);
data->supportHalfBlockCharacter (false);
data->supportCursorOptimisation (true);
data->setCursorHidden (true);
data->useAlternateScreen (false);
data->setASCIIConsole (true);
data->setVT100Console (false);
data->setUTF8Console (false);
data->setUTF8 (false);
data->setNewFont (false);
data->setVGAFont (false);
data->setMonochron (false);
data->setTermResized (false);
term_detection = finalcut::FTerm::getFTermDetection();
term_detection->setTerminalDetection(true);
finalcut::FTermOpenBSD openbsd;
pid_t pid = forkConEmu();
if ( isConEmuChildProcess(pid) )
{
setenv ("TERM", "vt220", 1);
setenv ("COLUMNS", "80", 1);
setenv ("LINES", "25", 1);
unsetenv("TERMCAP");
unsetenv("COLORTERM");
unsetenv("COLORFGBG");
unsetenv("VTE_VERSION");
unsetenv("XTERM_VERSION");
unsetenv("ROXTERM_ID");
unsetenv("KONSOLE_DBUS_SESSION");
unsetenv("KONSOLE_DCOP");
unsetenv("TMUX");
openbsd.init();
term_detection->detect();
finalcut::FTerm::detectTermSize();
CPPUNIT_ASSERT ( isatty(0) == 1 );
CPPUNIT_ASSERT ( term_detection->isOpenBSDTerm() );
CPPUNIT_ASSERT ( data->getTermGeometry().getWidth() == 80 );
CPPUNIT_ASSERT ( data->getTermGeometry().getHeight() == 25 );
CPPUNIT_ASSERT ( ! data->hasShadowCharacter() );
CPPUNIT_ASSERT ( ! data->hasHalfBlockCharacter() );
CPPUNIT_ASSERT_CSTRING ( term_detection->getTermType(), C_STR("pccon") );
closeConEmuStdStreams();
exit(EXIT_SUCCESS);
}
else // Parent
{
// Start the terminal emulation
startConEmuTerminal (ConEmu::openbsd_con);
if ( waitpid(pid, 0, WUNTRACED) != pid )
std::cerr << "waitpid error" << std::endl;
}
openbsd.finish();
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (ftermopenbsdTest);
// The general unit test main part
#include <main-test.inc>