Unit tests update

This commit is contained in:
Markus Gans 2018-03-21 00:02:43 +01:00
parent 25117e5d02
commit 8dd23d1673
9 changed files with 117 additions and 18 deletions

View File

@ -205,12 +205,16 @@ void tcapString (const std::string& name, const char cap_str[])
//----------------------------------------------------------------------
void debug (FApplication& TermApp)
{
const FString& ab_s = TermApp.getAnswerbackString();
const FString& sec_da= TermApp.getSecDAString();
#if DEBUG
std::cout << "\n.------------------- debug -------------------\r\n";
#if defined(__linux__)
std::cout << "| Framebuffer bpp: "
<< TermApp.framebuffer_bpp << "\r\n";
#endif
std::cout << "| after init_256colorTerminal(): "
<< TermApp.termtype_256color << "\r\n";
std::cout << "| after parseAnswerbackMsg(): "
@ -218,11 +222,11 @@ void debug (FApplication& TermApp)
std::cout << "| after parseSecDA(): "
<< TermApp.termtype_SecDA << "\r\n";
if ( const FString& s = TermApp.getAnswerbackString() )
tcapString ("| The answerback String", s);
if ( ab_s.isEmpty() )
tcapString ("| The answerback String", ab_s);
if ( const FString& s = TermApp.getSecDAString() )
tcapString ("| The SecDA String", s);
if ( ab_s.isEmpty() )
tcapString ("| The SecDA String", sec_da);
std::cout << "`------------------- debug -------------------\r\n";
#endif

View File

@ -1018,7 +1018,7 @@ void MyDialog::cb_view (FWidget*, data_ptr data)
FString file;
FMenuItem* item = static_cast<FMenuItem*>(data);
if ( item && item->getText() )
if ( item && ! item->getText().isEmpty() )
file = item->getText();
else
file = FFileDialog::fileOpenChooser (this);

View File

@ -226,6 +226,7 @@ class FString
wchar_t front() const;
wchar_t back() const;
FString& sprintf (const FString&, ...);
FString& sprintf (const wchar_t[], ...);
FString& sprintf (const char[], ...)
#if defined(__clang__)

View File

@ -250,10 +250,10 @@ bool FButton::setDown (bool on)
//----------------------------------------------------------------------
void FButton::setText (const FString& txt)
{
if ( txt )
text = txt;
else
if ( txt.isNull() )
text = "";
else
text = txt;
detectHotkey();
}

View File

@ -1212,7 +1212,7 @@ void FDialog::drawTextBar()
print (' ');
// Print title bar text
if ( tb_text )
if ( ! tb_text.isEmpty() )
{
if ( length <= getWidth() - MENU_BTN - zoom_btn )
print (tb_text);

View File

@ -108,7 +108,7 @@ FFileDialog::FFileDialog ( const FString& dirname
, dlg_type(type)
, show_hidden(false)
{
if ( dirname )
if ( ! dirname.isNull() )
setPath(dirname);
init();

View File

@ -371,11 +371,10 @@ bool FMouseGPM::gpmMouse (bool on)
switch ( gpm_fd )
{
case -1:
case -1: // error
return false;
case -2:
Gpm_Close();
case -2: // xterm is in use
return false;
default:
@ -503,11 +502,11 @@ void FMouseX11::setRawData (char fifo_buf[], int fifo_buf_size)
for (n = len; n < fifo_buf_size; n++)
fifo_buf[n - len] = fifo_buf[n];
n = fifo_buf_size - len - 1;
n = fifo_buf_size - len;
// Fill rest with '\0'
for (; n < fifo_buf_size; n++)
fifo_buf[n - len] = '\0';
fifo_buf[n] = '\0';
input_data_pending = bool(fifo_buf[0] != '\0');
}
@ -1238,8 +1237,6 @@ void FMouseControl::clearEvent()
#ifdef F_HAVE_LIBGPM
void FMouseControl::setStdinNo (int file_descriptor)
{
FMouse* mouse = mouse_protocol[FMouse::gpm];
FMouseGPM* gpm_mouse = static_cast<FMouseGPM*>(mouse);

View File

@ -734,6 +734,27 @@ uInt FString::getUTF8length() const
return len;
}
//----------------------------------------------------------------------
FString& FString::sprintf (const FString& format, ...)
{
static const int BUFSIZE = 4096;
wchar_t buffer[BUFSIZE];
va_list args;
if ( ! format )
{
clear();
return *this;
}
va_start (args, format);
std::vswprintf (buffer, BUFSIZE, format.wc_str(), args);
va_end (args);
_assign (buffer);
return *this;
}
//----------------------------------------------------------------------
FString& FString::sprintf (const wchar_t format[], ...)
{
@ -741,6 +762,12 @@ FString& FString::sprintf (const wchar_t format[], ...)
wchar_t buffer[BUFSIZE];
va_list args;
if ( ! format )
{
clear();
return *this;
}
va_start (args, format);
std::vswprintf (buffer, BUFSIZE, format, args);
va_end (args);
@ -758,6 +785,12 @@ FString& FString::sprintf (const char format[], ...)
int len;
va_list args;
if ( ! format )
{
clear();
return *this;
}
buffer = buf;
va_start (args, format);
len = vsnprintf (buffer, sizeof(buf), format, args);

View File

@ -96,7 +96,10 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
void noArgumentTest();
void doubleClickTest();
void workspaceSizeTest();
#ifdef F_HAVE_LIBGPM
void gpmMouseTest();
#endif
void x11MouseTest();
private:
// Adds code needed to register the test suite
@ -107,6 +110,10 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (doubleClickTest);
CPPUNIT_TEST (workspaceSizeTest);
#ifdef F_HAVE_LIBGPM
CPPUNIT_TEST (gpmMouseTest);
#endif
CPPUNIT_TEST (x11MouseTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
@ -221,6 +228,63 @@ void FMouseTest::workspaceSizeTest()
CPPUNIT_ASSERT ( mouse.getMaxHeight() == 30 );
}
#ifdef F_HAVE_LIBGPM
//----------------------------------------------------------------------
void FMouseTest::gpmMouseTest()
{
FMouseGPM gpm_mouse;
CPPUNIT_ASSERT ( ! gpm_mouse.isGpmMouseEnabled() );
gpm_mouse.setStdinNo(fileno(stdin));
if ( gpm_mouse.enableGpmMouse() )
{
CPPUNIT_ASSERT ( gpm_mouse.isGpmMouseEnabled() );
timeval tv;
FObject::getCurrentTime(&tv);
gpm_mouse.processEvent(&tv);
CPPUNIT_ASSERT ( ! gpm_mouse.hasEvent() );
}
else
CPPUNIT_ASSERT ( ! gpm_mouse.isGpmMouseEnabled() );
gpm_mouse.disableGpmMouse();
CPPUNIT_ASSERT ( ! gpm_mouse.isGpmMouseEnabled() );
}
#endif
//----------------------------------------------------------------------
void FMouseTest::x11MouseTest()
{
FMouseX11 x11_mouse;
CPPUNIT_ASSERT ( ! x11_mouse.hasData() );
char x11_mouse_data[8] = { 0x1b, '[', 'M', 0x23, 0x50, 0x32, 0x40, 0x40 };
x11_mouse.setRawData (x11_mouse_data, 8);
CPPUNIT_ASSERT ( x11_mouse.hasData() );
CPPUNIT_ASSERT ( x11_mouse.isInputDataPending() );
timeval tv;
FObject::getCurrentTime(&tv);
x11_mouse.processEvent (&tv);
CPPUNIT_ASSERT ( x11_mouse.getPos() == FPoint(48, 18) );
CPPUNIT_ASSERT ( x11_mouse.hasEvent() );
CPPUNIT_ASSERT ( ! x11_mouse.isLeftButtonPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isLeftButtonReleased() );
CPPUNIT_ASSERT ( ! x11_mouse.isLeftButtonDoubleClick() );
CPPUNIT_ASSERT ( ! x11_mouse.isRightButtonPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isRightButtonReleased() );
CPPUNIT_ASSERT ( ! x11_mouse.isMiddleButtonPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isMiddleButtonReleased() );
CPPUNIT_ASSERT ( ! x11_mouse.isShiftKeyPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isControlKeyPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isMetaKeyPressed() );
CPPUNIT_ASSERT ( ! x11_mouse.isWheelUp() );
CPPUNIT_ASSERT ( ! x11_mouse.isWheelDown() );
CPPUNIT_ASSERT ( ! x11_mouse.isMoved() );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FMouseTest);