FTermBuffer unit test now also runs on older Linux distributions without multicolored emojis

This commit is contained in:
Markus Gans 2021-02-10 21:09:21 +01:00
parent a1107f96c7
commit 28f41f5d6c
6 changed files with 39 additions and 25 deletions

View File

@ -164,6 +164,7 @@ jobs:
before_install: before_install:
- uname -a - uname -a
- g++ --version - g++ --version
- sudo pkg install -y autoconf-archive
script: script:
- autoreconf -v --install --force - autoreconf -v --install --force
- ./configure --prefix=/usr - ./configure --prefix=/usr

View File

@ -258,9 +258,8 @@ std::size_t FLabel::getAlignOffset (const std::size_t length) const
if ( length < width ) if ( length < width )
return (width - length) / 2; return (width - length) / 2;
} }
else if ( alignment == Align::Right ) else if ( alignment == Align::Right && length < width )
{ {
if ( length < width )
return width - length; return width - length;
} }

View File

@ -1484,9 +1484,8 @@ std::size_t FListView::getAlignOffset ( const Align align
if ( column_width < width ) if ( column_width < width )
return (width - column_width) / 2; return (width - column_width) / 2;
} }
else if ( align == Align::Right ) else if ( align == Align::Right && column_width < width )
{ {
if ( column_width < width )
return width - column_width; return width - column_width;
} }

View File

@ -1880,7 +1880,7 @@ void FVTerm::init_characterLengths()
if ( clr_eol_length == 0 ) if ( clr_eol_length == 0 )
clr_eol_length = INT_MAX; clr_eol_length = INT_MAX;
} }
#include <unistd.h>
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FVTerm::init_combined_character() void FVTerm::init_combined_character()
{ {

View File

@ -178,10 +178,10 @@ class FString
iterator end() noexcept; iterator end() noexcept;
const_iterator begin() const noexcept; const_iterator begin() const noexcept;
const_iterator end() const noexcept; const_iterator end() const noexcept;
reference front() noexcept; reference front();
reference back() noexcept; reference back();
const_reference front() const noexcept; const_reference front() const;
const_reference back() const noexcept; const_reference back() const;
template <typename... Args> template <typename... Args>
FString& sprintf (const FString&, Args&&...); FString& sprintf (const FString&, Args&&...);
@ -403,28 +403,28 @@ inline FString::const_iterator FString::end() const noexcept
{ return string + length; } { return string + length; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::reference FString::front() noexcept inline FString::reference FString::front()
{ {
assert ( ! isEmpty() ); assert ( ! isEmpty() );
return (*this)[0]; return (*this)[0];
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::reference FString::back() noexcept inline FString::reference FString::back()
{ {
assert( ! isEmpty() ); assert( ! isEmpty() );
return (*this)[length - 1]; return (*this)[length - 1];
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_reference FString::front() const noexcept inline FString::const_reference FString::front() const
{ {
assert ( ! isEmpty() ); assert ( ! isEmpty() );
return (*this)[0]; return (*this)[0];
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString::const_reference FString::back() const noexcept inline FString::const_reference FString::back() const
{ {
assert( ! isEmpty() ); assert( ! isEmpty() );
return (*this)[length - 1]; return (*this)[length - 1];

View File

@ -287,6 +287,7 @@ void FTermBufferTest::writeTest()
} }
// Write with style // Write with style
auto multi_color_emojis = bool( wcswidth(L"☕⛄🧸🦡", 4) == 8 );
term_buf.clear(); term_buf.clear();
auto style = finalcut::FStyle(finalcut::Style::Italic | finalcut::Style::Reverse); auto style = finalcut::FStyle(finalcut::Style::Italic | finalcut::Style::Reverse);
term_buf.write (style); term_buf.write (style);
@ -339,20 +340,25 @@ void FTermBufferTest::writeTest()
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[2] == L'\0' ); CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[2] == L'\0' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[3] == L'\0' ); CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[3] == L'\0' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[4] == L'\0' ); CPPUNIT_ASSERT ( term_buf.getBuffer()[i].encoded_char[4] == L'\0' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.byte[2] != 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.byte[3] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.byte[3] == 0 );
if ( multi_color_emojis )
{
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.byte[2] != 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.bit.char_width == 2 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[i].attr.bit.char_width == 2 );
} }
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermBufferTest::streamTest() void FTermBufferTest::streamTest()
{ {
auto multi_color_emojis = bool( wcswidth(L"🚧🚀🚴", 3) == 6 );
const auto& data = finalcut::FTerm::getFTermData(); const auto& data = finalcut::FTerm::getFTermData();
data->setTermEncoding (finalcut::Encoding::UTF8); data->setTermEncoding (finalcut::Encoding::UTF8);
finalcut::FTermBuffer::FCharVector fchar_vec = { finalcut::FChar{} }; finalcut::FTermBuffer::FCharVector fchar_vec = { finalcut::FChar{} };
CPPUNIT_ASSERT ( fchar_vec.size() == 1 ); CPPUNIT_ASSERT ( fchar_vec.size() == 1 );
fchar_vec.front().ch[0] = L'🥨'; fchar_vec.front().ch[0] = L'🚧';
fchar_vec.front().fg_color = finalcut::FColor::White; fchar_vec.front().fg_color = finalcut::FColor::White;
fchar_vec.front().bg_color = finalcut::FColor::Cyan; fchar_vec.front().bg_color = finalcut::FColor::Cyan;
finalcut::addColumnWidth(fchar_vec.front()); finalcut::addColumnWidth(fchar_vec.front());
@ -365,7 +371,7 @@ void FTermBufferTest::streamTest()
<< finalcut::UniChar::NF_Bullet << finalcut::UniChar::NF_Bullet
<< finalcut::FStyle(finalcut::Style::Blink) << finalcut::FStyle(finalcut::Style::Blink)
<< fchar_vec << fchar_vec
<< std::string("🧭") << std::string("🚀")
<< finalcut::FStyle(finalcut::Style::None) << finalcut::FStyle(finalcut::Style::None)
<< finalcut::FStyle(finalcut::Style::DoubleUnderline) << finalcut::FStyle(finalcut::Style::DoubleUnderline)
<< finalcut::FColorPair{finalcut::FColor::Black, finalcut::FColor::White} << finalcut::FColorPair{finalcut::FColor::Black, finalcut::FColor::White}
@ -394,28 +400,37 @@ void FTermBufferTest::streamTest()
CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.byte[0] != 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.byte[0] != 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.byte[1] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.byte[1] == 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.bit.char_width == 1 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[2].attr.bit.char_width == 1 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].ch[0] == L'🥨' ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].ch[0] == L'🚧' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].fg_color == finalcut::FColor::White ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].fg_color == finalcut::FColor::White );
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].bg_color == finalcut::FColor::Cyan ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].bg_color == finalcut::FColor::Cyan );
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.byte[0] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.byte[0] == 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.byte[1] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.byte[1] == 0 );
if ( multi_color_emojis )
CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.bit.char_width == 2 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[3].attr.bit.char_width == 2 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].ch[0] == L'🧭' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].ch[0] == L'🚀' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].fg_color == finalcut::FColor::Cyan ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].fg_color == finalcut::FColor::Cyan );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].bg_color == finalcut::FColor::White ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].bg_color == finalcut::FColor::White );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.dim == 1 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.dim == 1 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.blink == 1 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.blink == 1 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.byte[0] != 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.byte[0] != 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.byte[1] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.byte[1] == 0 );
if ( multi_color_emojis )
CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.char_width == 2 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[4].attr.bit.char_width == 2 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].ch[0] == L'🚴' ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].ch[0] == L'🚴' );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].fg_color == finalcut::FColor::Black ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].fg_color == finalcut::FColor::Black );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].bg_color == finalcut::FColor::White ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].bg_color == finalcut::FColor::White );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.bit.dbl_underline == 1 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.bit.dbl_underline == 1 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.byte[0] == 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.byte[0] == 0 );
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.byte[1] != 0 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.byte[1] != 0 );
if ( multi_color_emojis )
CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.bit.char_width == 2 ); CPPUNIT_ASSERT ( term_buf.getBuffer()[5].attr.bit.char_width == 2 );
CPPUNIT_ASSERT ( term_buf.toString() == "a1\U0000e1f9🥨🧭🚴" );
CPPUNIT_ASSERT ( term_buf.toString() == "a1\U0000e1f9🚧🚀🚴" );
for (std::size_t i{0}; i < 6; i++) for (std::size_t i{0}; i < 6; i++)
{ {