Added unit test for FTermcapQuirks

This commit is contained in:
Markus Gans 2018-08-09 00:04:00 +02:00
parent 8c575e0aad
commit 0c3be5e726
17 changed files with 854 additions and 14 deletions

View File

@ -1,3 +1,6 @@
2017-08-08 Markus Gans <guru.mail@muenster.de>
* Added unit test for FTermcapQuirks
2017-07-29 Markus Gans <guru.mail@muenster.de>
* Added numeric Keypad [/], [*], [-], [+] support
* Handling of keys that are substrings of other keys

View File

@ -47,6 +47,9 @@ class FColorPalette
// Typedefs
typedef void (*funcp)(short, int, int, int);
// Accessor
virtual const char* getClassName() const;
// Methods
static void set8ColorPalette (funcp);
static void set16ColorPalette (funcp);
@ -55,5 +58,9 @@ class FColorPalette
};
#pragma pack(pop)
// FColorPalette inline functions
//----------------------------------------------------------------------
inline const char* FColorPalette::getClassName() const
{ return "FColorPalette"; }
#endif // FCOLORPALETTE_H

View File

@ -239,7 +239,7 @@ class FTerm
static bool isUTF8();
// Mutators
static void setTermType (char[]);
static void setTermType (const char[]);
static void setInsertCursor (bool on);
static void setInsertCursor();
static void unsetInsertCursor();

View File

@ -97,7 +97,6 @@ class FTermBuffer
private:
std::vector<charData> data;
};
#pragma pack(pop)

View File

@ -66,7 +66,9 @@ class FTermcap
~FTermcap()
{ }
// Accessor
// Accessors
const char* getClassName() const;
static tcap_map* getTermcapMap()
{
return tcap;
@ -96,4 +98,9 @@ class FTermcap
};
#pragma pack(pop)
// FOptiMove inline functions
//----------------------------------------------------------------------
inline const char* FTermcap::getClassName() const
{ return "FTermcap"; }
#endif // FTERMCAP_H

View File

@ -57,8 +57,11 @@ class FTermcapQuirks
// Destructor
~FTermcapQuirks();
// Accessor
const char* getClassName() const;
// Mutator
static void setTerminalType (char[]);
static void setTerminalType (const char[]);
static void setTermcapMap (FTermcap::tcap_map*);
static void setFTermDetection (FTermDetection*);
@ -88,4 +91,9 @@ class FTermcapQuirks
};
#pragma pack(pop)
// FTermcapQuirks inline functions
//----------------------------------------------------------------------
inline const char* FTermcapQuirks::getClassName() const
{ return "FTermcapQuirks"; }
#endif // FTERMCAPQUIRKS_H

View File

@ -92,6 +92,7 @@ class FTermDetection
~FTermDetection();
// Accessor
const char* getClassName() const;
static char* getTermType();
static char* getTermFileName();
static int getGnomeTerminalID();
@ -238,6 +239,10 @@ class FTermDetection
#pragma pack(pop)
// FTermDetection inline functions
//----------------------------------------------------------------------
inline const char* FTermDetection::getClassName() const
{ return "FTermDetection"; }
//----------------------------------------------------------------------
inline char* FTermDetection::getTermType()
{ return termtype; }

View File

@ -66,6 +66,7 @@ class FTermFreeBSD
~FTermFreeBSD();
// Accessors
const char* getClassName() const;
static CursorStyle getCursorStyle();
// Inquiry
@ -106,6 +107,10 @@ class FTermFreeBSD
#pragma pack(pop)
// FTermFreeBSD inline functions
//----------------------------------------------------------------------
inline const char* FTermFreeBSD::getClassName() const
{ return "FTermFreeBSD"; }
//----------------------------------------------------------------------
#if defined(__FreeBSD__) || defined(__DragonFly__)
inline void FTermFreeBSD::enableChangeCursorStyle()

View File

@ -58,6 +58,7 @@ class FTermios
~FTermios();
// Accessors
const char* getClassName() const;
static termios getTTY();
static int getStdIn();
static int getStdOut();
@ -90,6 +91,10 @@ class FTermios
#pragma pack(pop)
// FTermios inline functions
//----------------------------------------------------------------------
inline const char* FTermios::getClassName() const
{ return "FTermios"; }
//----------------------------------------------------------------------
inline int FTermios::getStdIn()
{ return stdin_no; }

View File

@ -74,6 +74,7 @@ class FTermLinux
~FTermLinux();
// Accessors
const char* getClassName() const;
static fc::linuxConsoleCursorStyle getCursorStyle();
static int getFramebufferBpp();
@ -186,6 +187,10 @@ class FTermLinux
#pragma pack(pop)
// FTermLinux inline functions
//----------------------------------------------------------------------
inline const char* FTermLinux::getClassName() const
{ return "FTermLinux"; }
//----------------------------------------------------------------------
#if defined(__linux__)
inline int FTermLinux::getFramebufferBpp()

View File

@ -58,6 +58,9 @@ class FTermOpenBSD
// Destructor
~FTermOpenBSD();
// Accessor
const char* getClassName() const;
// Inquiries
static bool isBSDConsole();
@ -91,6 +94,10 @@ class FTermOpenBSD
#pragma pack(pop)
// FTermOpenBSD inline functions
//----------------------------------------------------------------------
inline const char* FTermOpenBSD::getClassName() const
{ return "FTermOpenBSD"; }
//----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__)
inline void FTermOpenBSD::enableMetaSendsEscape()

View File

@ -76,6 +76,7 @@ class FTermXTerminal
static void metaSendsESC (bool);
// Accessors
const char* getClassName() const;
static fc::xtermCursorStyle getCursorStyle();
static const FString* getFont();
static const FString* getTitle();
@ -150,6 +151,10 @@ class FTermXTerminal
#pragma pack(pop)
// FTermXTerminal inline functions
//----------------------------------------------------------------------
inline const char* FTermXTerminal::getClassName() const
{ return "FTermXTerminal"; }
//----------------------------------------------------------------------
inline void FTermXTerminal::setTermcapMap (FTermcap::tcap_map* tc)
{ tcap = tc; }

View File

@ -163,7 +163,7 @@ bool FTerm::isNormal (charData*& ch)
}
//----------------------------------------------------------------------
void FTerm::setTermType (char term_name[])
void FTerm::setTermType (const char term_name[])
{
if ( ! term_name )
return;
@ -1218,11 +1218,11 @@ void FTerm::init_termcap_variables (char*& buffer)
init_termcap_strings(buffer);
// Terminal quirks
FTermcapQuirks termcap_quirks;
termcap_quirks.setTermcapMap (tcap);
termcap_quirks.setFTermDetection (term_detection);
termcap_quirks.setTerminalType (termtype);
termcap_quirks.terminalFixup(); // Fix terminal quirks
FTermcapQuirks quirks;
quirks.setTermcapMap (tcap);
quirks.setFTermDetection (term_detection);
quirks.setTerminalType (termtype);
quirks.terminalFixup(); // Fix terminal quirks
// Get termcap keys
init_termcap_keys(buffer);

View File

@ -44,7 +44,7 @@ FTermcapQuirks::~FTermcapQuirks() // destructor
// public methods of FTermcapQuirks
//----------------------------------------------------------------------
void FTermcapQuirks::setTerminalType (char tt[])
void FTermcapQuirks::setTerminalType (const char tt[])
{
std::strncpy (termtype, tt, sizeof(termtype) - 1);
}
@ -62,7 +62,6 @@ void FTermcapQuirks::setFTermDetection (FTermDetection* td)
}
// private methods of FTermcapQuirks
//----------------------------------------------------------------------
void FTermcapQuirks::terminalFixup()

View File

@ -10,6 +10,7 @@ noinst_PROGRAMS = \
fobject_test \
fmouse_test \
fkeyboard_test \
ftermcapquirks_test \
foptimove_test \
foptiattr_test \
fstring_test \
@ -19,6 +20,7 @@ noinst_PROGRAMS = \
fobject_test_SOURCES = fobject-test.cpp
fmouse_test_SOURCES = fmouse-test.cpp
fkeyboard_test_SOURCES = fkeyboard-test.cpp
ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp
foptimove_test_SOURCES = foptimove-test.cpp
foptiattr_test_SOURCES = foptiattr-test.cpp
fstring_test_SOURCES = fstring-test.cpp
@ -28,6 +30,7 @@ frect_test_SOURCES = frect-test.cpp
TESTS = fobject_test \
fmouse_test \
fkeyboard_test \
ftermcapquirks_test \
foptimove_test \
foptiattr_test \
fstring_test \

View File

@ -85,12 +85,14 @@ host_triplet = @host@
@CPPUNIT_TEST_TRUE@noinst_PROGRAMS = fobject_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fmouse_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fkeyboard_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ ftermcapquirks_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptimove_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptiattr_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fstring_test$(EXEEXT) fpoint_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ frect_test$(EXEEXT)
@CPPUNIT_TEST_TRUE@TESTS = fobject_test$(EXEEXT) fmouse_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fkeyboard_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ ftermcapquirks_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptimove_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptiattr_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fstring_test$(EXEEXT) fpoint_test$(EXEEXT) \
@ -114,6 +116,7 @@ CONFIG_CLEAN_VPATH_FILES =
@CPPUNIT_TEST_TRUE@am__EXEEXT_1 = fobject_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fmouse_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fkeyboard_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ ftermcapquirks_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptimove_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ foptiattr_test$(EXEEXT) \
@CPPUNIT_TEST_TRUE@ fstring_test$(EXEEXT) fpoint_test$(EXEEXT) \
@ -158,6 +161,11 @@ am__fstring_test_SOURCES_DIST = fstring-test.cpp
@CPPUNIT_TEST_TRUE@am_fstring_test_OBJECTS = fstring-test.$(OBJEXT)
fstring_test_OBJECTS = $(am_fstring_test_OBJECTS)
fstring_test_LDADD = $(LDADD)
am__ftermcapquirks_test_SOURCES_DIST = ftermcapquirks-test.cpp
@CPPUNIT_TEST_TRUE@am_ftermcapquirks_test_OBJECTS = \
@CPPUNIT_TEST_TRUE@ ftermcapquirks-test.$(OBJEXT)
ftermcapquirks_test_OBJECTS = $(am_ftermcapquirks_test_OBJECTS)
ftermcapquirks_test_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@ -195,14 +203,16 @@ am__v_CXXLD_1 =
SOURCES = $(fkeyboard_test_SOURCES) $(fmouse_test_SOURCES) \
$(fobject_test_SOURCES) $(foptiattr_test_SOURCES) \
$(foptimove_test_SOURCES) $(fpoint_test_SOURCES) \
$(frect_test_SOURCES) $(fstring_test_SOURCES)
$(frect_test_SOURCES) $(fstring_test_SOURCES) \
$(ftermcapquirks_test_SOURCES)
DIST_SOURCES = $(am__fkeyboard_test_SOURCES_DIST) \
$(am__fmouse_test_SOURCES_DIST) \
$(am__fobject_test_SOURCES_DIST) \
$(am__foptiattr_test_SOURCES_DIST) \
$(am__foptimove_test_SOURCES_DIST) \
$(am__fpoint_test_SOURCES_DIST) $(am__frect_test_SOURCES_DIST) \
$(am__fstring_test_SOURCES_DIST)
$(am__fstring_test_SOURCES_DIST) \
$(am__ftermcapquirks_test_SOURCES_DIST)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -563,6 +573,7 @@ top_srcdir = @top_srcdir@
@CPPUNIT_TEST_TRUE@fobject_test_SOURCES = fobject-test.cpp
@CPPUNIT_TEST_TRUE@fmouse_test_SOURCES = fmouse-test.cpp
@CPPUNIT_TEST_TRUE@fkeyboard_test_SOURCES = fkeyboard-test.cpp
@CPPUNIT_TEST_TRUE@ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp
@CPPUNIT_TEST_TRUE@foptimove_test_SOURCES = foptimove-test.cpp
@CPPUNIT_TEST_TRUE@foptiattr_test_SOURCES = foptiattr-test.cpp
@CPPUNIT_TEST_TRUE@fstring_test_SOURCES = fstring-test.cpp
@ -653,6 +664,10 @@ fstring_test$(EXEEXT): $(fstring_test_OBJECTS) $(fstring_test_DEPENDENCIES) $(EX
@rm -f fstring_test$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(fstring_test_OBJECTS) $(fstring_test_LDADD) $(LIBS)
ftermcapquirks_test$(EXEEXT): $(ftermcapquirks_test_OBJECTS) $(ftermcapquirks_test_DEPENDENCIES) $(EXTRA_ftermcapquirks_test_DEPENDENCIES)
@rm -f ftermcapquirks_test$(EXEEXT)
$(AM_V_CXXLD)$(CXXLINK) $(ftermcapquirks_test_OBJECTS) $(ftermcapquirks_test_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -667,6 +682,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpoint-test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/frect-test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring-test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftermcapquirks-test.Po@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@ -909,6 +925,13 @@ fkeyboard_test.log: fkeyboard_test$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
ftermcapquirks_test.log: ftermcapquirks_test$(EXEEXT)
@p='ftermcapquirks_test$(EXEEXT)'; \
b='ftermcapquirks_test'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
foptimove_test.log: foptimove_test$(EXEEXT)
@p='foptimove_test$(EXEEXT)'; \
b='foptimove_test'; \

View File

@ -0,0 +1,759 @@
/***********************************************************************
* ftermcapquirks-test.cpp - FTermcapQuirks unit tests *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2018 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 <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 <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
{
#pragma pack(push)
#pragma pack(1)
typedef struct
{
char* string;
char tname[3];
}
tcap_map;
#pragma pack(pop)
static tcap_map tcap[] =
{
{ 0, "bl" }, // bell
{ 0, "ec" }, // erase_chars
{ 0, "cl" }, // clear_screen
{ 0, "cd" }, // clr_eos
{ 0, "ce" }, // clr_eol
{ 0, "cb" }, // clr_bol
{ 0, "ho" }, // cursor_home
{ 0, "ll" }, // cursor_to_ll
{ 0, "cr" }, // carriage_return
{ 0, "ta" }, // tab
{ 0, "bt" }, // back_tab
{ 0, "ip" }, // insert_padding
{ 0, "ic" }, // insert_character
{ 0, "IC" }, // parm_ich
{ 0, "rp" }, // repeat_char
{ 0, "Ic" }, // initialize_color
{ 0, "Ip" }, // initialize_pair
{ 0, "AF" }, // set_a_foreground
{ 0, "AB" }, // set_a_background
{ 0, "Sf" }, // set_foreground
{ 0, "Sb" }, // set_background
{ 0, "sp" }, // set_color_pair
{ 0, "op" }, // orig_pair
{ 0, "oc" }, // orig_colors
{ 0, "NC" }, // no_color_video
{ 0, "cm" }, // cursor_address
{ 0, "ch" }, // column_address
{ 0, "cv" }, // row_address
{ 0, "vs" }, // cursor_visible
{ 0, "vi" }, // cursor_invisible
{ 0, "ve" }, // cursor_normal
{ 0, "up" }, // cursor_up
{ 0, "do" }, // cursor_down
{ 0, "le" }, // cursor_left
{ 0, "nd" }, // cursor_right
{ 0, "UP" }, // parm_up_cursor
{ 0, "DO" }, // parm_down_cursor
{ 0, "LE" }, // parm_left_cursor
{ 0, "RI" }, // parm_right_cursor
{ 0, "sc" }, // save_cursor
{ 0, "rc" }, // restore_cursor
{ 0, "Ss" }, // set cursor style
{ 0, "sf" }, // scroll_forward
{ 0, "sr" }, // scroll_reverse
{ 0, "ti" }, // enter_ca_mode
{ 0, "te" }, // exit_ca_mode
{ 0, "eA" }, // enable_acs
{ 0, "md" }, // enter_bold_mode
{ 0, "me" }, // exit_bold_mode
{ 0, "mh" }, // enter_dim_mode
{ 0, "me" }, // exit_dim_mode
{ 0, "ZH" }, // enter_italics_mode
{ 0, "ZR" }, // exit_italics_mode
{ 0, "us" }, // enter_underline_mode
{ 0, "ue" }, // exit_underline_mode
{ 0, "mb" }, // enter_blink_mode
{ 0, "me" }, // exit_blink_mode
{ 0, "mr" }, // enter_reverse_mode
{ 0, "me" }, // exit_reverse_mode
{ 0, "so" }, // enter_standout_mode
{ 0, "se" }, // exit_standout_mode
{ 0, "mk" }, // enter_secure_mode
{ 0, "me" }, // exit_secure_mode
{ 0, "mp" }, // enter_protected_mode
{ 0, "me" }, // exit_protected_mode
{ 0, "XX" }, // enter_crossed_out_mode
{ 0, "me" }, // exit_crossed_out_mode
{ 0, "Us" }, // enter_dbl_underline_mode
{ 0, "Ue" }, // exit_dbl_underline_mode
{ 0, "sa" }, // set_attributes
{ 0, "me" }, // exit_attribute_mode
{ 0, "as" }, // enter_alt_charset_mode
{ 0, "ae" }, // exit_alt_charset_mode
{ 0, "S2" }, // enter_pc_charset_mode
{ 0, "S3" }, // exit_pc_charset_mode
{ 0, "im" }, // enter_insert_mode
{ 0, "ei" }, // exit_insert_mode
{ 0, "SA" }, // enter_am_mode
{ 0, "RA" }, // exit_am_mode
{ 0, "ac" }, // acs_chars
{ 0, "ks" }, // keypad_xmit
{ 0, "ke" }, // keypad_local
{ 0, "Km" }, // key_mouse
{ 0, "\0" }
};
} // namespace test
//----------------------------------------------------------------------
// class FTermcapQuirksTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FTermcapQuirksTest : public CPPUNIT_NS::TestFixture
{
public:
FTermcapQuirksTest();
~FTermcapQuirksTest();
protected:
void classNameTest();
void generalTest();
void xtermTest();
#if defined(__FreeBSD__) || defined(__DragonFly__)
void freebsdTest();
#endif
void cygwinTest();
void linuxTest();
void rxvtTest();
void vteTest();
void puttyTest();
void teratermTest();
void sunTest();
void screenTest();
private:
std::string printSequence (const std::string&);
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FTermcapQuirksTest);
// Add a methods to the test suite
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (generalTest);
CPPUNIT_TEST (xtermTest);
#if defined(__FreeBSD__) || defined(__DragonFly__)
CPPUNIT_TEST (freebsdTest);
#endif
CPPUNIT_TEST (cygwinTest);
CPPUNIT_TEST (linuxTest);
CPPUNIT_TEST (rxvtTest);
CPPUNIT_TEST (vteTest);
CPPUNIT_TEST (puttyTest);
CPPUNIT_TEST (teratermTest);
CPPUNIT_TEST (sunTest);
CPPUNIT_TEST (screenTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#pragma pack(pop)
//----------------------------------------------------------------------
FTermcapQuirksTest::FTermcapQuirksTest()
{ }
//----------------------------------------------------------------------
FTermcapQuirksTest::~FTermcapQuirksTest()
{ }
//----------------------------------------------------------------------
void FTermcapQuirksTest::classNameTest()
{
FTermcapQuirks q;
const char* const classname = q.getClassName();
CPPUNIT_ASSERT ( std::strcmp(classname, "FTermcapQuirks") == 0 );
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::generalTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::tabstop = -1;
FTermcap::attr_without_color = -1;
FTermcapQuirks quirks;
FTermDetection detect;
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::tabstop == 8 );
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "3%p1%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "4%p1%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_initialize_color].string
, C_STR(OSC "P%p1%x"
"%p2%{255}%*%{1000}%/%02x"
"%p3%{255}%*%{1000}%/%02x"
"%p4%{255}%*%{1000}%/%02x") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_ca_mode].string
, C_STR(ESC "7" CSI "?47h" ) );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_ca_mode].string
, C_STR(CSI "?47l" ESC "8" CSI "m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_cursor_address].string
, C_STR(CSI "%i%p1%d;%p2%dH") );
// Non standard ECMA-48 (ANSI X3.64) terminal
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_dbl_underline_mode].string
, 0 );
caps[fc::t_exit_underline_mode].string = C_STR(CSI "24m");
quirks.terminalFixup();
// Standard ECMA-48 (ANSI X3.64) terminal
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_dbl_underline_mode].string
, C_STR(CSI "21m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_dbl_underline_mode].string
, C_STR(CSI "24m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_bold_mode].string
, C_STR(CSI "22m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_dim_mode].string
, C_STR(CSI "22m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_underline_mode].string
, C_STR(CSI "24m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_blink_mode].string
, C_STR(CSI "25m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_reverse_mode].string
, C_STR(CSI "27m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_secure_mode].string
, C_STR(CSI "28m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_crossed_out_mode].string
, C_STR(CSI "9m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_crossed_out_mode].string
, C_STR(CSI "29m") );
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::xtermTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcapQuirks quirks;
FTermDetection detect;
detect.setXTerminal (true);
quirks.setTerminalType ("xterm");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
/*
printf ("\n(%s)\n", printSequence(caps[fc::t_initialize_color].string).c_str());
printf ("\n(%s)\n", printSequence(C_STR(OSC "4;%p1%d;rgb:"
"%p2%{255}%*%{1000}%/%2.2X/"
"%p3%{255}%*%{1000}%/%2.2X/"
"%p4%{255}%*%{1000}%/%2.2X" ESC "\\")).c_str());
*/
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_initialize_color].string
, C_STR(OSC "4;%p1%d;rgb:"
"%p2%{255}%*%{1000}%/%2.2X/"
"%p3%{255}%*%{1000}%/%2.2X/"
"%p4%{255}%*%{1000}%/%2.2X" ESC "\\") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_cursor_invisible].string
, C_STR(CSI "?25l") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_cursor_normal].string
, C_STR(CSI "?12l" CSI "?25h") );
detect.setXTerminal (false);
delete[] caps;
}
#if defined(__FreeBSD__) || defined(__DragonFly__)
//----------------------------------------------------------------------
void FTermcapQuirksTest::freebsdTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::attr_without_color = -1;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setFreeBSDTerm (true);
quirks.setTerminalType ("xterm-16color");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 18 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_acs_chars].string
, C_STR("-\036.\0370\333"
"a\260f\370g\361"
"h\261j\331k\277"
"l\332m\300n\305"
"q\304t\303u\264"
"v\301w\302x\263"
"y\363z\362~\371") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_attributes].string
, C_STR(CSI "0"
"%?%p1%p6%|%t;1%;"
"%?%p2%t;4%;"
"%?%p1%p3%|%t;7%;"
"%?%p4%t;5%;m"
"%?%p9%t\016%e\017%;") );
detect.setFreeBSDTerm (false);
delete[] caps;
}
#endif
//----------------------------------------------------------------------
void FTermcapQuirksTest::cygwinTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::background_color_erase = false;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setCygwinTerminal (true);
quirks.setTerminalType ("cygwin");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::background_color_erase == true );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_cursor_invisible].string
, C_STR(CSI "?25l") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_cursor_visible].string
, C_STR(CSI "?25h") );
detect.setCygwinTerminal (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::linuxTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::max_color = 8;
FTermcap::attr_without_color = -1;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setLinuxTerm (true);
quirks.setTerminalType ("linux");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
// 8 colors
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "3%p1%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "4%p1%dm") );
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 18 );
// 16 colors
FTermcap::max_color = 16;
quirks.terminalFixup();
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "3%p1%{8}%m%d%?%p1%{7}%>%t;1%e;22%;m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "4%p1%{8}%m%d%?%p1%{7}%>%t;5%e;25%;m") );
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 26 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_attributes].string
, C_STR(CSI "0"
"%?%p6%t;1%;"
"%?%p1%p3%|%t;7%;"
"%?%p4%t;5%;m"
"%?%p9%t\016%e\017%;") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_alt_charset_mode].string
, C_STR("\016") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_alt_charset_mode].string
, C_STR("\017") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_attribute_mode].string
, C_STR(CSI "0m\017") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_bold_mode].string
, C_STR(CSI "22m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_blink_mode].string
, C_STR(CSI "25m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_reverse_mode].string
, C_STR(CSI "27m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_secure_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_protected_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_crossed_out_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_orig_pair].string
, C_STR(CSI "39;49;25m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_dim_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_dim_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_underline_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_underline_mode].string
, 0 );
detect.setLinuxTerm (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::rxvtTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcapQuirks quirks;
FTermDetection detect;
detect.setRxvtTerminal (true);
quirks.setTerminalType ("rxvt");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
// rxvt
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_alt_charset_mode].string
, 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_alt_charset_mode].string
, 0 );
// rxvt-16color
quirks.setTerminalType ("rxvt-16color");
quirks.terminalFixup();
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_alt_charset_mode].string
, C_STR(ESC "(0") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_alt_charset_mode].string
, C_STR(ESC "(B") );
// urxvt
detect.setUrxvtTerminal (true);
quirks.terminalFixup();
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "%?%p1%{8}%<%t%p1%{30}%+%e%p1%'R'%+%;%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "%?%p1%{8}%<%t%p1%'('%+%e%p1%{92}%+%;%dm") );
detect.setUrxvtTerminal (false);
detect.setRxvtTerminal (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::vteTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::attr_without_color = -1;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setGnomeTerminal (true);
quirks.setTerminalType ("gnome-256color");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_underline_mode].string
, C_STR(CSI "24m") );
detect.setGnomeTerminal (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::puttyTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::background_color_erase = false;
FTermcap::osc_support = false;
FTermcap::attr_without_color = -1;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setPuttyTerminal (true);
quirks.setTerminalType ("putty");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::background_color_erase == true );
CPPUNIT_ASSERT ( FTermcap::osc_support == true );
CPPUNIT_ASSERT ( FTermcap::attr_without_color == 0 );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "%?%p1%{8}%<"
"%t3%p1%d"
"%e%p1%{16}%<"
"%t9%p1%{8}%-%d"
"%e38;5;%p1%d%;m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "%?%p1%{8}%<"
"%t4%p1%d"
"%e%p1%{16}%<"
"%t10%p1%{8}%-%d"
"%e48;5;%p1%d%;m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_attributes].string
, C_STR(CSI "0"
"%?%p1%p6%|%t;1%;"
"%?%p5%t;2%;"
"%?%p2%t;4%;"
"%?%p1%p3%|%t;7%;"
"%?%p4%t;5%;m"
"%?%p9%t\016%e\017%;") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_dim_mode].string
, C_STR(CSI "2m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_dim_mode].string
, C_STR(CSI "22m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_clr_bol].string
, C_STR(CSI "1K") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_orig_pair].string
, C_STR(CSI "39;49m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_orig_colors].string
, C_STR(OSC "R") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_column_address].string
, C_STR(CSI "%i%p1%dG") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_row_address].string
, C_STR(CSI "%i%p1%dd") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enable_acs].string
, C_STR(ESC "(B" ESC ")0") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_am_mode].string
, C_STR(CSI "?7h") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_am_mode].string
, C_STR(CSI "?7l") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_enter_pc_charset_mode].string
, C_STR(CSI "11m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_pc_charset_mode].string
, C_STR(CSI "10m") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_key_mouse].string
, C_STR(CSI "M") );
detect.setPuttyTerminal (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::teratermTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::eat_nl_glitch = false;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setTeraTerm (true);
quirks.setTerminalType ("teraterm");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::eat_nl_glitch == true );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_foreground].string
, C_STR(CSI "38;5;%p1%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_set_a_background].string
, C_STR(CSI "48;5;%p1%dm") );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_exit_attribute_mode].string
, C_STR(CSI "0m" SI) );
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_orig_pair].string
, C_STR(CSI "39;49m") );
detect.setTeraTerm (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::sunTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcap::eat_nl_glitch = false;
FTermcapQuirks quirks;
FTermDetection detect;
detect.setSunTerminal (true);
quirks.setTerminalType ("sun-color");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT ( FTermcap::eat_nl_glitch == true );
detect.setSunTerminal (false);
delete[] caps;
}
//----------------------------------------------------------------------
void FTermcapQuirksTest::screenTest()
{
const int last_item = int(sizeof(test::tcap) / sizeof(test::tcap[0])) - 1;
test::tcap_map* caps = new test::tcap_map[last_item];
for (int i = 0; i < last_item; i++)
memcpy(&caps[i], &test::tcap[i], sizeof(test::tcap[0]));
FTermcapQuirks quirks;
FTermDetection detect;
detect.setScreenTerm (true);
quirks.setTerminalType ("screen-256color");
quirks.setTermcapMap (reinterpret_cast<FTermcap::tcap_map*>(caps));
quirks.setFTermDetection (&detect);
quirks.terminalFixup();
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_initialize_color].string
, C_STR(ESC "P" OSC "4;%p1%d;rgb:"
"%p2%{255}%*%{1000}%/%2.2X/"
"%p3%{255}%*%{1000}%/%2.2X/"
"%p4%{255}%*%{1000}%/%2.2X" BEL ESC "\\") );
detect.setTmuxTerm (true);
caps[fc::t_initialize_color].string = 0;
quirks.terminalFixup();
CPPUNIT_ASSERT_CSTRING ( caps[fc::t_initialize_color].string
, C_STR(ESC "Ptmux;" ESC OSC "4;%p1%d;rgb:"
"%p2%{255}%*%{1000}%/%2.2X/"
"%p3%{255}%*%{1000}%/%2.2X/"
"%p4%{255}%*%{1000}%/%2.2X" BEL ESC "\\") );
detect.setTmuxTerm (false);
detect.setScreenTerm (false);
delete[] caps;
}
// private methods of FOptiMoveTest
//----------------------------------------------------------------------
std::string FTermcapQuirksTest::printSequence (const std::string& s)
{
std::ostringstream sequence;
for (std::string::size_type i = 0; i < s.length(); ++i)
{
switch ( int(s[i]) )
{
case 0x08:
sequence << "BS ";
break;
case 0x09:
sequence << "TAB ";
break;
case 0x0a:
sequence << "LF ";
break;
case 0x0d:
sequence << "CR ";
break;
case 0x1b:
sequence << "Esc ";
break;
default:
sequence << s[i];
sequence << ' ';
}
}
return sequence.str();
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FTermcapQuirksTest);
// The general unit test main part
#include <main-test.inc>