From 14c81d973499c0c475b6a5f57d48b768567883b0 Mon Sep 17 00:00:00 2001 From: dac Date: Thu, 28 Oct 2010 09:06:47 +1000 Subject: Handle am/pm and text months correctly. Workaround FORTIFY_SOURCE issue. --- libqtuitest/qalternatestack_unix.cpp | 14 +--- .../qtwidgets/testdatetimeedit.cpp | 38 +++++++---- tests/qtuitest/sys_input/sys_input.qtt | 74 ++++++---------------- tests/qtuitest/testapps/testapp1/main.cpp | 8 +++ 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/libqtuitest/qalternatestack_unix.cpp b/libqtuitest/qalternatestack_unix.cpp index 93c9167..016102b 100644 --- a/libqtuitest/qalternatestack_unix.cpp +++ b/libqtuitest/qalternatestack_unix.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#undef _FORTIFY_SOURCE #include "qalternatestack_p.h" @@ -194,7 +195,7 @@ void qt_entry_function_wrapper(int) Example: \code - void runsInAlternateStack(QAlternateStack* stack, QVariant const& data) + void runsInAlternateStack(QAlternateStack* stack, const QVariant& data) { int foo = data.toInt(); // ... @@ -227,7 +228,7 @@ void qt_entry_function_wrapper(int) \typedef QAlternateStackEntryPoint Typedef for a pointer to a function with the signature - \c{void my_function(QAlternateStack*,QVariant const&)}. + \c{void my_function(QAlternateStack*,const QVariant&)}. Used as an entry point to a new stack. */ @@ -511,9 +512,6 @@ QList QAlternateStack::instances() /*! Returns true if QAlternateStack is usable on this platform. - QAlternateStack depends on System-V signal stacks, which is not reliable on - some platforms. On these platforms, this function will return false. - Usage of QAlternateStack when this function returns false will typically result in a fatal error at runtime. */ @@ -522,12 +520,6 @@ bool QAlternateStack::isAvailable() #ifdef Q_OS_MAC return false; #endif - -#ifdef QT_QWS_GREENPHONE - // On the Greenphone, it works if and only if the stackbuf has been set up. - return qalternatestack_stackbuf(); -#else return true; -#endif } diff --git a/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp b/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp index a1f6a56..f456424 100644 --- a/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp +++ b/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp @@ -56,7 +56,7 @@ TestDateTimeEdit::TestDateTimeEdit(QObject* _q) this, SLOT(onDateTimeChanged(QDateTime))); } -void TestDateTimeEdit::onDateTimeChanged(QDateTime const& dt) +void TestDateTimeEdit::onDateTimeChanged(const QDateTime& dt) { emit entered(dt); } QString TestDateTimeEdit::text() const @@ -70,7 +70,7 @@ QVariant TestDateTimeEdit::value() const return q->dateTime(); } -QRegExp dateFormatToRegExp(QString const& format) +QRegExp dateFormatToRegExp(const QString& format) { QString re; QString fmt = format; @@ -125,7 +125,7 @@ QRegExp dateFormatToRegExp(QString const& format) return QRegExp(re); } -bool TestDateTimeEdit::canEnter(QVariant const& item) const +bool TestDateTimeEdit::canEnter(const QVariant& item) const { QString text; if (item.canConvert()) { @@ -149,7 +149,7 @@ bool TestDateTimeEdit::canEnter(QVariant const& item) const return ret; } -QPoint TestDateTimeEdit::nextClick( QStringList const& cap, +QPoint TestDateTimeEdit::nextClick( const QStringList& cap, QMap const& capMap, bool *final, bool *ok) { @@ -161,6 +161,7 @@ QPoint TestDateTimeEdit::nextClick( QStringList const& cap, int activeSection = -1; int moveUpDown = 0; int sectionsNeedingChanges = 0; + bool ampm = q->displayedSections() & QDateTimeEdit::AmPmSection; /* Sections, from most to least significant. * It is necessary to edit most significant first because that can affect @@ -194,10 +195,23 @@ QPoint TestDateTimeEdit::nextClick( QStringList const& cap, if (-1 == activeSection) { bool is_int = false; int src = text.toInt(&is_int); - if (!is_int) return ret; int dest = cap.at(cap_i).toInt(&is_int); - if (!is_int) return ret; - moveUpDown = (dest - src); + if (!is_int && section == QDateTimeEdit::MonthSection) { + if (q->displayFormat().contains("MMMM")) { + moveUpDown = QDate::fromString(cap.at(cap_i), "MMMM").month() - QDate::fromString(text, "MMMM").month(); + } else if (q->displayFormat().contains("MMM")) { + moveUpDown = QDate::fromString(cap.at(cap_i), "MMM").month() - QDate::fromString(text, "MMM").month(); + } + } else if (section == QDateTimeEdit::AmPmSection) { + if (text.toUpper() == "PM") + moveUpDown = -1; + else + moveUpDown = 1; + } else if (section == QDateTimeEdit::HourSection && ampm && dest == 12) { + moveUpDown = (src - dest); + } else { + moveUpDown = (dest - src); + } activeSection = cap_i; } } @@ -263,7 +277,7 @@ QPoint TestDateTimeEdit::nextClick( QStringList const& cap, return ret; } -bool TestDateTimeEdit::enterByMouse(QString const& format, QDateTime const& dt) +bool TestDateTimeEdit::enterByMouse(const QString& format, const QDateTime& dt) { bool final = false; bool ok = true; @@ -302,7 +316,7 @@ bool TestDateTimeEdit::enterByMouse(QString const& format, QDateTime const& dt) return ok; } -bool TestDateTimeEdit::enterByKeys(QString const& format, QDateTime const& dt, bool noCommit) +bool TestDateTimeEdit::enterByKeys(const QString& format, const QDateTime& dt, bool noCommit) { if (!hasEditFocus() && !setEditFocus(true)) return false; TestWidgetsLog() << "got focus"; @@ -317,7 +331,7 @@ bool TestDateTimeEdit::enterByKeys(QString const& format, QDateTime const& dt, b return setEditFocus(false); } -bool TestDateTimeEdit::enter(QVariant const& item, bool noCommit) +bool TestDateTimeEdit::enter(const QVariant& item, bool noCommit) { QString text; QDateTime dt; @@ -359,7 +373,7 @@ bool TestDateTimeEdit::enter(QVariant const& item, bool noCommit) } bool TestDateTimeEdit::enterSectionByKeys(QDateTimeEdit::Section section, - QString const& fmt, QDateTime const& dt) + const QString& fmt, const QDateTime& dt) { using namespace QtUiTest; @@ -448,7 +462,7 @@ bool TestDateTimeEdit::enterSectionByKeys(QDateTimeEdit::Section section, TestWidgetsLog() << "Going to enter" << text << "in section" << section; - foreach (QChar const& c, text) { + foreach (const QChar& c, text) { if (!keyClick(q, asciiToKey(c.toLatin1()))) { return false; } diff --git a/tests/qtuitest/sys_input/sys_input.qtt b/tests/qtuitest/sys_input/sys_input.qtt index 51f7301..56a0908 100644 --- a/tests/qtuitest/sys_input/sys_input.qtt +++ b/tests/qtuitest/sys_input/sys_input.qtt @@ -42,61 +42,6 @@ testcase = { - runAsManualTest: function() { - if (!runAsManualTest()) - skip( "This test only makes sense when executed in -force-manual mode" ); - - manualTest( "Do something" ); - startApplication("foobar"); - prompt( "This should all nicely fold into one big prompt" ); - prompt( "Line 1\nLine 2\nLine 3" ); - verify( isVisible( "blah" ) ); - verify( isVisible( activeWindow() ) ); - compare( getText(focusWidget()), "this text" ); - compare( "this text", getText(focusWidget()) ); - compare( getSelectedText(tabBar()), getText(focusWidget()) ); - select( "foo", tabBar() ); - compare( getSelectedText(tabBar()), "First Tab" ); - compare( getSelectedValue("Name"), "a reference value" ); - compare( getValue("Address"), "Elysium road" ); - compare( "Elysium road", getValue("Address") ); - compare( getList( "Friends"), getList( "Other Friends") ); - mouseClick( getCenter( "foo", "bar" ) ); - var l = getLabels( "app" ); - verify(l.contains("Name"), "Verify that labels for 'app' contain 'Name'"); - setClipboardText( l ); - compare( getClipboardText(), "foobar" ); - compare( currentTitle(), "Contacts" ); - compare( getWindowTitles(), "A\nB\nC" ); - activateWindow( "mainwindow" ); - verify( getenv( "PATH" ).contains( "/home/user/foobar" ) ); - verify( checkOS( "linux" ) ); - verifyImage( "task_completed", "", - "Verify that the current task is shown with a green tick indicating completion" ); - verify( compareImage( "expected", "actual" )); - verify( getData("srcFile") == "blah" ); - verify( getImageSize( "srcFile" ) == "12345" ); - getFile("/tmp/foo.conf", "$HOME/Settings/foo.conf" ); - putFile("testdata/my_settings.conf", "$HOME/Settings/foo.conf"); - putFile("testdata/my_file", "$HOME/my_file", 12 ); //QFile.WriteOwner | QFile.ReadOwner | QFile.ReadOther); - }, - - runAutoTest: function() { - if (runAsManualTest()) - skip( "This test only makes sense when NOT executed in -force-manual mode" ); - - startApplication("testapp1"); - manualTest( "step 1"); - manualTest( "step 2"); - manualTest( "step 3"); - - compare(currentTitle(), "testapp1"); - - manualTest( "step4" ); - manualTest( "step5" ); - manualTest( "step6" ); - }, - activate_tabBar: function() { startApplication("testapp1"); @@ -226,6 +171,25 @@ testcase = { simple2: [ new Date(2004, 10, 11) ] }, + // enter() with QDateTimeEdit fields. + enter_QDateTimeEdit: function(date) { + startApplication("testapp1"); + + select("Awesome Tab", tabBar()); + + enter(date, "DateTime"); + + compare( getValue("DateTime"), date ); + + }, + + enter_QDateTimeEdit_data: { + simple1: [ new Date(2000, 6, 15, 17, 27, 0) ], + december: [ new Date(2000, 11, 15, 0, 30, 0) ], + end_of_month: [ new Date(2002, 5, 30, 12, 15, 0) ], + simple2: [ new Date(2004, 10, 11) ] + }, + // Explicit mouse clicks on widgets mouseClick: function() { startApplication("testapp1"); diff --git a/tests/qtuitest/testapps/testapp1/main.cpp b/tests/qtuitest/testapps/testapp1/main.cpp index 1bc3581..aa6c53c 100644 --- a/tests/qtuitest/testapps/testapp1/main.cpp +++ b/tests/qtuitest/testapps/testapp1/main.cpp @@ -204,14 +204,22 @@ void TestWidget::setupWidgets() { de->setDate(QDate(2001, 1, 1)); fl->addRow("Date", de); + QDateTimeEdit *dte = new QDateTimeEdit; + dte->setDate(QDate(2010, 12, 1)); + dte->setTime(QTime(15, 0, 0)); + dte->setDisplayFormat("dd MMMM yyyy hh:mm a"); + fl->addRow("DateTime", dte); + connect(cb, SIGNAL(clicked()), sm, SLOT(map())); connect(pb, SIGNAL(clicked()), sm, SLOT(map())); connect(te, SIGNAL(editingFinished()), sm, SLOT(map())); connect(de, SIGNAL(editingFinished()), sm, SLOT(map())); + connect(dte, SIGNAL(editingFinished()), sm, SLOT(map())); sm->setMapping(cb, "'Checkbox' clicked"); sm->setMapping(pb, "'Clear' clicked"); sm->setMapping(te, "'Time' edited"); sm->setMapping(de, "'Date' edited"); + sm->setMapping(dte, "'DateTime' edited"); connect(sm, SIGNAL(mapped(QString)), statusEdit, SLOT(setText(QString))); -- cgit v1.2.3