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) void debug (FApplication& TermApp)
{ {
const FString& ab_s = TermApp.getAnswerbackString();
const FString& sec_da= TermApp.getSecDAString();
#if DEBUG #if DEBUG
std::cout << "\n.------------------- debug -------------------\r\n"; std::cout << "\n.------------------- debug -------------------\r\n";
#if defined(__linux__) #if defined(__linux__)
std::cout << "| Framebuffer bpp: " std::cout << "| Framebuffer bpp: "
<< TermApp.framebuffer_bpp << "\r\n"; << TermApp.framebuffer_bpp << "\r\n";
#endif #endif
std::cout << "| after init_256colorTerminal(): " std::cout << "| after init_256colorTerminal(): "
<< TermApp.termtype_256color << "\r\n"; << TermApp.termtype_256color << "\r\n";
std::cout << "| after parseAnswerbackMsg(): " std::cout << "| after parseAnswerbackMsg(): "
@ -218,11 +222,11 @@ void debug (FApplication& TermApp)
std::cout << "| after parseSecDA(): " std::cout << "| after parseSecDA(): "
<< TermApp.termtype_SecDA << "\r\n"; << TermApp.termtype_SecDA << "\r\n";
if ( const FString& s = TermApp.getAnswerbackString() ) if ( ab_s.isEmpty() )
tcapString ("| The answerback String", s); tcapString ("| The answerback String", ab_s);
if ( const FString& s = TermApp.getSecDAString() ) if ( ab_s.isEmpty() )
tcapString ("| The SecDA String", s); tcapString ("| The SecDA String", sec_da);
std::cout << "`------------------- debug -------------------\r\n"; std::cout << "`------------------- debug -------------------\r\n";
#endif #endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -96,7 +96,10 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
void noArgumentTest(); void noArgumentTest();
void doubleClickTest(); void doubleClickTest();
void workspaceSizeTest(); void workspaceSizeTest();
#ifdef F_HAVE_LIBGPM
void gpmMouseTest();
#endif
void x11MouseTest();
private: private:
// Adds code needed to register the test suite // Adds code needed to register the test suite
@ -107,6 +110,10 @@ class FMouseTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (noArgumentTest); CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (doubleClickTest); CPPUNIT_TEST (doubleClickTest);
CPPUNIT_TEST (workspaceSizeTest); CPPUNIT_TEST (workspaceSizeTest);
#ifdef F_HAVE_LIBGPM
CPPUNIT_TEST (gpmMouseTest);
#endif
CPPUNIT_TEST (x11MouseTest);
// End of test suite definition // End of test suite definition
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -221,6 +228,63 @@ void FMouseTest::workspaceSizeTest()
CPPUNIT_ASSERT ( mouse.getMaxHeight() == 30 ); 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 // Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FMouseTest); CPPUNIT_TEST_SUITE_REGISTRATION (FMouseTest);