diff --git a/src/plugins/qttest/dialogs.cpp b/src/plugins/qttest/dialogs.cpp index 7a6e2c4c835358c1eb7b5501f046e78f57eeb7f6..718212f3473c20943605db58564fd04386465eb6 100644 --- a/src/plugins/qttest/dialogs.cpp +++ b/src/plugins/qttest/dialogs.cpp @@ -90,14 +90,14 @@ void SelectDlg::addSelectableItem(const QString &item) if (groupsList->columnCount() > 1) { int row = groupsList->rowCount(); groupsList->insertRow(row); - QStringList tmp = item.split("|"); + QStringList tmp = item.split(QLatin1Char('|')); if (tmp.count() > groupsList->columnCount()) { for (int i = 0; i < (groupsList->columnCount() - 1); ++i) groupsList->setItem(row, i, new QTableWidgetItem(tmp[i])); QString s; for (int i = groupsList->columnCount(); i < tmp.count(); ++i) { - if (!s.isEmpty()) s+= "|"; + if (!s.isEmpty()) s+= QLatin1Char('|'); s += tmp[i]; } groupsList->setItem(row, (groupsList->columnCount() - 1), new QTableWidgetItem(s)); @@ -105,7 +105,7 @@ void SelectDlg::addSelectableItem(const QString &item) for (int i = 0; i < tmp.count(); ++i) groupsList->setItem(row, i, new QTableWidgetItem(tmp[i])); for (int i = tmp.count(); i < groupsList->columnCount(); ++i) - groupsList->setItem(row, i, new QTableWidgetItem("")); + groupsList->setItem(row, i, new QTableWidgetItem(QString())); } else { for (int i = 0; i < tmp.count(); ++i) groupsList->setItem(row, i, new QTableWidgetItem(tmp[i])); @@ -130,7 +130,7 @@ QStringList SelectDlg::selectedItems() if (item && item->isSelected()) { QString S = item->text(); for (int col = 1; col < groupsList->columnCount(); ++col) { - S+= "|"; + S+= QLatin1Char('|'); item = groupsList->item(row, col); if (item) S += item->text(); diff --git a/src/plugins/qttest/dialogs.h b/src/plugins/qttest/dialogs.h index ca4675f0afc6f0e96b91758c01ba13aa61cc6c27..82bb078442a0108bc3d2b5cc08a5513141130bde 100644 --- a/src/plugins/qttest/dialogs.h +++ b/src/plugins/qttest/dialogs.h @@ -65,7 +65,7 @@ class NewTestFunctionDlg : public QDialog, public Ui::NewTestFunctionDlg Q_OBJECT public: - NewTestFunctionDlg(const QString &testCase, QWidget *parent = 0); + explicit NewTestFunctionDlg(const QString &testCase, QWidget *parent = 0); private slots: void onChanged(); diff --git a/src/plugins/qttest/qsystem.cpp b/src/plugins/qttest/qsystem.cpp index 0680b705d4f88679b52fe0b52bb609b41a521698..1b4ca25c90ae8cd18c89b6ae9efd6bdbda31f719 100644 --- a/src/plugins/qttest/qsystem.cpp +++ b/src/plugins/qttest/qsystem.cpp @@ -88,15 +88,15 @@ QString QSystem::userName() QString userName; #if defined Q_OS_TEMP - userName = "WinCE"; + userName = QLatin1String("WinCE"); #elif defined Q_OS_WIN32 - userName = getenv("USERNAME"); + userName = QString::fromLocal8Bit(qgetenv("USERNAME")); #elif defined Q_OS_UNIX - userName = getenv("USER"); - if (userName == "") - userName = getenv("LOGNAME"); + userName = QString::fromLocal8Bit(qgetenv("USER")); + if (userName.isEmpty()) + userName = QString::fromLocal8Bit(qgetenv("LOGNAME")); #elif defined Q_OS_MAC - userName = getenv(); + userName = getenv(); // TODO? #endif return userName.toLower(); @@ -116,10 +116,9 @@ QString QSystem::hostName() hostName = QHostInfo::localHostName(); // convert anarki.troll.no to anarki - int pos = hostName.indexOf("."); + const int pos = hostName.indexOf(QLatin1Char('.')); if (pos > 0) - hostName = hostName.left(pos); - + hostName.truncate(pos); return hostName; } @@ -129,86 +128,86 @@ QString QSystem::hostName() QString QSystem::OSName() { #if defined(Q_OS_MAC) - return "Mac-OSX"; + return QLatin1String("Mac-OSX"); #elif defined(Q_OS_MSDOS) - return "MSDOS"; + return QLatin1String("MSDOS"); #elif defined(Q_OS_OS2EMX) - return "OS2EMX"; + return QLatin1String("OS2EMX"); #elif defined(Q_OS_OS2) - return "OS2"; -#elif defined(Q_OS_WIN32) || defined (Q_OS_WIN64) - return "Windows"; + return QLatin1String("OS2"); +#elif defined(Q_OS_WIN) + return QLatin1String("Windows"); #elif defined(Q_OS_SOLARIS) - return "Solaris"; + return QLatin1String("Solaris"); #elif defined(Q_OS_SUN) && defined(Q_OS_BSD4) - return "Sun"; + return QLatin1String("Sun"); #elif defined(Q_OS_HPUX) - return "HPUX"; + return QLatin1String("HPUX"); #elif defined(Q_OS_ULTRIX) - return "ULTRIX"; + return QLatin1String("ULTRIX"); #elif defined(Q_OS_RELIANT) - return "RELIANT"; + return QLatin1String("RELIANT"); #elif defined(Q_OS_LINUX) - return "Linux"; + return QLatin1String("Linux"); #elif defined(Q_OS_FREEBSD) && defined(Q_OS_BSD4) - return "FREEBSD"; + return QLatin1String("FREEBSD"); #elif defined(Q_OS_NETBSD) && defined(Q_OS_BSD4) - return "NETBSD"; + return QLatin1String("NETBSD"); #elif defined(Q_OS_OPENBSD) && defined(Q_OS_BSD4) - return "OPENBSD"; + return QLatin1String("OPENBSD"); #elif defined(Q_OS_BSDI) && defined(Q_OS_BSD4) - return "BSDI"; + return QLatin1String("BSDI"); #elif defined(Q_OS_IRIX) - return "IRIX"; + return QLatin1String("IRIX"); #elif defined(Q_OS_OSF) - return "OSF"; + return QLatin1String("OSF"); #elif defined(Q_OS_AIX) - return "AIX"; + return QLatin1String("AIX"); #elif defined(Q_OS_LYNX) - return "LYNX"; + return QLatin1String("LYNX"); #elif defined(Q_OS_UNIXWARE) - return "UNIXWARE"; + return QLatin1String("UNIXWARE"); #elif defined(Q_OS_HURD) - return "HURD"; + return QLatin1String("HURD"); #elif defined(Q_OS_DGUX) - return "DGUX"; + return QLatin1String("DGUX"); #elif defined(Q_OS_QNX6) - return "QNX6"; + return QLatin1String("QNX6"); #elif defined(Q_OS_QNX) - return "QNX"; + return QLatin1String("QNX"); #elif defined(Q_OS_SCO) - return "SCO"; + return QLatin1String("SCO"); #elif defined(Q_OS_UNIXWARE7) - return "UNIXWARE7"; + return QLatin1String("UNIXWARE7"); #elif defined(Q_OS_DYNIX) - return "DYNIX"; + return QLatin1String("DYNIX"); #elif defined(Q_OS_SVR4) - return "SVR4"; + return QLatin1String("SVR4"); #else - return "UNKNOWN"; + return QLatin1String("UNKNOWN"); #endif } QString which_p(const QString &path, const QString &applicationName) { QStringList paths; -#if defined Q_OS_WIN32 - paths = path.split(";"); +#if defined Q_OS_WIN + paths = path.split(QLatin1Char(';')); #else - paths = path.split(":"); + paths = path.split(QLatin1Char(':')); #endif foreach (const QString &p, paths) { QString fname = p + QDir::separator() + applicationName; if (QFile::exists(fname)) return fname; -#if defined Q_OS_WIN32 - if (QFile::exists(fname + ".exe")) - return fname + ".exe"; - if (QFile::exists(fname + ".bat")) - return fname + ".bat"; +#if defined Q_OS_WIN + if (QFile::exists(fname + QLatin1String(".exe"))) + return fname + QLatin1String(".exe"); + if (QFile::exists(fname + QLatin1String(".bat"))) + return fname + QLatin1String(".bat"); #endif } - return ""; + return QString(); } /*! @@ -219,8 +218,8 @@ QString which_p(const QString &path, const QString &applicationName) QString QSystem::which(const QString &path, const QString &applicationName) { QString ret = which_p(path, applicationName); - if (ret.contains(" ")) - return '"' + ret + '"'; + if (ret.contains(QLatin1Char(' '))) + return QLatin1Char('"') + ret + QLatin1Char('"'); return ret; } @@ -268,20 +267,20 @@ bool QSystem::processEnvValue(QStringList *envList, QString &envString) QString prefix; bool isSetCmd = false; - if (_envString.startsWith("export ")) { + if (_envString.startsWith(QLatin1String("export "))) { _envString = _envString.mid(7); - prefix = "export "; + prefix = QLatin1String("export "); isSetCmd = true; } - if (_envString.startsWith("set ")) { + if (_envString.startsWith(QLatin1String("set "))) { _envString = _envString.mid(4); - prefix = "set "; + prefix = QLatin1String("set "); isSetCmd = true; } if (isSetCmd) { - int pos = _envString.indexOf("="); + int pos = _envString.indexOf(QLatin1Char('=')); if (pos < 0) { // nothing to do return false; @@ -292,7 +291,7 @@ bool QSystem::processEnvValue(QStringList *envList, QString &envString) if (processEnvValue(envList, value)) { setEnvKey(envList, key, value); - envString = /*prefix +*/ key + "=" + value; + envString = /*prefix +*/ key + QLatin1Char('=') + value; return true; } else { return false; @@ -309,7 +308,7 @@ bool QSystem::processEnvValue(QStringList *envList, QString &envString) int len = key.length()+1; if (_envString.at(pos) == '%') len++; - if (_envString.indexOf("("+ key + ")") == (pos + 1)) + if (_envString.indexOf(QLatin1Char('(')+ key + QLatin1Char(')')) == (pos + 1)) len += 2; _envString.remove(pos, len); _envString.insert(pos, replacementValue); @@ -332,7 +331,7 @@ bool QSystem::processEnvValue(QStringList *envList, QString &envString) bool QSystem::hasEnvKey(const QString &envString, QString &key, int &pos, int start) { pos = -1; - key = ""; + key.clear(); int end = -1; bool winKey = false; @@ -340,9 +339,9 @@ bool QSystem::hasEnvKey(const QString &envString, QString &key, int &pos, int st ++start; int pos1, pos2, pos3; - pos1 = envString.indexOf("$", start); - pos2 = envString.indexOf("%", start); - pos3 = envString.indexOf("%", pos2 + 1); + pos1 = envString.indexOf(QLatin1Char('$'), start); + pos2 = envString.indexOf(QLatin1Char('%'), start); + pos3 = envString.indexOf(QLatin1Char('%'), pos2 + 1); if (pos1 < 0 && pos2 < 0) return false; @@ -371,20 +370,20 @@ bool QSystem::hasEnvKey(const QString &envString, QString &key, int &pos, int st end = -1; if (winKey) { // if we found a % we only look for a closing one - end = envString.indexOf("%", pos+1); + end = envString.indexOf(QLatin1Char('%'), pos+1); } else { // else look for some other characters that close a KEY const uint maxSrch = 8; int term[maxSrch]; - term[0] = envString.indexOf("/", pos+1); - term[1] = envString.indexOf(":", pos+1); - term[2] = envString.indexOf("\\", pos+1); - term[3] = envString.indexOf(";", pos+1); - term[4] = envString.indexOf(" ", pos+1); - term[5] = envString.indexOf("-", pos+1); - term[6] = envString.indexOf(".", pos+1); + term[0] = envString.indexOf(QLatin1Char('/'), pos+1); + term[1] = envString.indexOf(QLatin1Char(':'), pos+1); + term[2] = envString.indexOf(QLatin1Char('\\'), pos+1); + term[3] = envString.indexOf(QLatin1Char(';'), pos+1); + term[4] = envString.indexOf(QLatin1Char(' '), pos+1); + term[5] = envString.indexOf(QLatin1Char('-'), pos+1); + term[6] = envString.indexOf(QLatin1Char('.'), pos+1); term[7] = envString.length(); // now lets see which char comes first after pos: Thats the one we are looking for. @@ -404,7 +403,7 @@ bool QSystem::hasEnvKey(const QString &envString, QString &key, int &pos, int st QString tmpKey = envString.mid(pos + 1, end - (pos+1)); // see if we have a string that looks like $(QTDIR) and convert it to QTDIR - if (tmpKey.startsWith("(") && tmpKey.endsWith(")")) + if (tmpKey.startsWith(QLatin1Char('(')) && tmpKey.endsWith(QLatin1Char(')'))) tmpKey = tmpKey.mid(1, tmpKey.length()-2); if (!tmpKey.isEmpty()) { @@ -418,7 +417,7 @@ bool QSystem::hasEnvKey(const QString &envString, QString &key, int &pos, int st } /*! - Removes any occurance of environment \a key from the environment \a list. + Removes any occurrence of environment \a key from the environment \a list. The function returns true if the list was valid and no more instances of \a key exist in the list. */ @@ -434,7 +433,7 @@ bool QSystem::unsetEnvKey(QStringList *list, const QString &key) QStringList::Iterator it; for (int i = list->size() - 1; i > 0; --i) { QString s = list->at(i); - int pos = s.indexOf("="); + int pos = s.indexOf(QLatin1Char('=')); if (pos > 0) { QString keyName = (s.left(pos)).toUpper(); if (keyName == envKey) { @@ -469,7 +468,7 @@ bool QSystem::setEnvKey(QStringList *list, const QString &key, const QString &va replacementValue = QSystem::envKey(list, tmpKey.toUpper()); if (!replacementValue.isEmpty()) { int len = tmpKey.length() + 1; - if (envValue.at(pos) == '%') + if (envValue.at(pos) == QLatin1Char('%')) ++len; envValue.remove(pos, len); envValue.insert(pos, replacementValue); @@ -482,18 +481,18 @@ bool QSystem::setEnvKey(QStringList *list, const QString &key, const QString &va QStringList::Iterator end = list->end(); for (QStringList::Iterator it = list->begin(); it != end; ++it) { QString s = *it; - pos = s.indexOf("="); + pos = s.indexOf(QLatin1Char('=')); if (pos > 0) { QString keyName = (s.left(pos)).toUpper(); if (keyName == envKey) { - *it = envKey + "=" + envValue; + *it = envKey + QLatin1Char('=') + envValue; list->sort(); return true; } } } - list->append(envKey + "=" + envValue); + list->append(envKey + QLatin1Char('=') + envValue); list->sort(); return true; } @@ -503,9 +502,9 @@ void QSystem::addEnvPath(QStringList *environment, const QString &key, const QSt QString dyldPath = QSystem::envKey(environment, key); if (!dyldPath.contains(addedPath)) { #ifdef Q_OS_WIN - dyldPath = addedPath + ";" + dyldPath; + dyldPath = addedPath + QLatin1Char(';') + dyldPath; #else - dyldPath = addedPath + ":" + dyldPath; + dyldPath = addedPath + QLatin1Char(':') + dyldPath; #endif QSystem::setEnvKey(environment, key, dyldPath); } @@ -520,7 +519,7 @@ QString QSystem::envKey(QStringList *list, const QString &key) { QString value; if (list == 0) - return ""; + return QString(); QString srchKey = key.toUpper(); @@ -528,14 +527,14 @@ QString QSystem::envKey(QStringList *list, const QString &key) QStringList::Iterator end = list->end(); for (QStringList::Iterator it = list->begin(); it != end; ++it) { QString s = *it; - pos = s.indexOf("="); + pos = s.indexOf(QLatin1Char('=')); if (pos > 0) { QString keyName = (s.left(pos)).toUpper(); if (keyName == srchKey) { value = s.mid(pos+1); - if (value.endsWith(";%" + keyName + "%")) { + if (value.endsWith(QLatin1String(";%") + keyName + QLatin1Char('%'))) { value = value.left(value.length() - (3 + keyName.length())); - } else if (value.endsWith(":$" + keyName)) { + } else if (value.endsWith(QLatin1String(":$") + keyName)) { value = value.left(value.length() - (2 + keyName.length())); } return value; @@ -543,5 +542,5 @@ QString QSystem::envKey(QStringList *list, const QString &key) } } - return ""; + return QString(); } diff --git a/src/plugins/qttest/qttestplugin.cpp b/src/plugins/qttest/qttestplugin.cpp index 2a0eeb89ab1e78a1e928640e6ab00841f985a310..21bc4ef3f9f21481724a7c13f04ec5985f7f1386 100644 --- a/src/plugins/qttest/qttestplugin.cpp +++ b/src/plugins/qttest/qttestplugin.cpp @@ -35,6 +35,11 @@ #include "dialogs.h" #include "qsystem.h" #include "testsettingspropertiespage.h" +#include "resultsview.h" +#include "testexecuter.h" +#include "testcontextmenu.h" +#include "testsuite.h" +#include "testoutputwindow.h" #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actioncontainer.h> @@ -48,6 +53,7 @@ #include <coreplugin/progressmanager/progressmanager.h> #include <qmljseditor/qmljseditorconstants.h> +#include <texteditor/basetexteditor.h> #include <cppeditor/cppeditorconstants.h> #include <cpptools/cpptoolsconstants.h> #include <extensionsystem/pluginmanager.h> @@ -76,6 +82,8 @@ using namespace QtTest::Internal; +enum { debug = 0 }; + Core::NavigationView TestNavigationWidgetFactory::createWidget() { Core::NavigationView view; @@ -109,16 +117,15 @@ Core::NavigationView TestNavigationWidgetFactory::createWidget() QString TestNavigationWidgetFactory::displayName() const { - return "Tests"; + return QtTestPlugin::tr("Tests"); } //****************************************** -QtTestPlugin::QtTestPlugin() +QtTestPlugin::QtTestPlugin() : + m_messageOutputWindow(0), m_testResultsWindow(0), + m_contextMenu(new TestContextMenu(this)) { - m_messageOutputWindow = 0; - m_testResultsWindow = 0; - m_contextMenu = new TestContextMenu(this); } QtTestPlugin::~QtTestPlugin() @@ -235,9 +242,10 @@ void QtTestPlugin::testDebug() Debugger::DebuggerRunControl *runControl = 0; Debugger::DebuggerStartParameters params; params.startMode = Debugger::NoStartMode; // we'll start the test runner here - params.executable = ".qtt"; + params.executable = QLatin1String(".qtt"); runControl = Debugger::DebuggerPlugin::createDebugger(params); - qDebug() << "Debugger run control" << runControl; + if (debug) + qDebug() << "Debugger run control" << runControl; runControl->start(); #ifdef QTTEST_DEBUGGER_SUPPORT @@ -276,7 +284,7 @@ void QtTestPlugin::retryTests(const QStringList &tests) QStringList newSelection; foreach (const QString &test, currentSelection) { - QString testName = test.mid(test.lastIndexOf("/") + 1); + QString testName = test.mid(test.lastIndexOf(QLatin1Char('/')) + 1); if (tests.contains(testName)) newSelection.append(test); } @@ -288,8 +296,8 @@ void QtTestPlugin::insertTestFunction() { TestCode *currentTest = m_testCollection.currentEditedTest(); if (currentTest) { - QString prompt = "<b>" + currentTest->testTypeString() - + " Test: </b>" + currentTest->testCase(); + QString prompt = QLatin1String("<b>") + currentTest->testTypeString() + + QLatin1String(" Test: </b>") + currentTest->testCase(); NewTestFunctionDlg dlg(prompt); dlg.exec(); diff --git a/src/plugins/qttest/qttestplugin.h b/src/plugins/qttest/qttestplugin.h index 2249b8787f339630cc4364d08a9dda93f78eb317..e8d9f08f71013a3380eda2af681adffa5a2fd54b 100644 --- a/src/plugins/qttest/qttestplugin.h +++ b/src/plugins/qttest/qttestplugin.h @@ -33,17 +33,16 @@ #ifndef QTTESTPLUGIN_H #define QTTESTPLUGIN_H -#include "testoutputwindow.h" -#include "testselector.h" -#include "resultsview.h" -#include "testexecuter.h" -#include "testcontextmenu.h" #include "testsuite.h" #include <coreplugin/inavigationwidgetfactory.h> #include <extensionsystem/iplugin.h> #include <QtCore/QObject> +class TestContextMenu; +class TestResultsWindow; +class TestOutputWindow; + namespace QtTest { namespace Internal { diff --git a/src/plugins/qttest/resultsview.cpp b/src/plugins/qttest/resultsview.cpp index 9ed01873f5e32270d83d22cfdfc40593135e299a..8600af512cd26a133072688b3e8347f4fa5f0b96 100644 --- a/src/plugins/qttest/resultsview.cpp +++ b/src/plugins/qttest/resultsview.cpp @@ -54,12 +54,13 @@ #include <QApplication> #include <QDebug> -enum { - RES_SIZE = 100, - RESULT_POS = 0, - DETAILS_POS = 1, - REASON_POS = 2, - SCREEN_POS = 3 +enum +{ + ResultSize = 100, + ResultPosition = 0, + DetailsPosition = 1, + ReasonPosition = 2, + ScreenPosition = 3 }; // Role for data which holds the identifier for use with m_pendingScreenshots @@ -67,9 +68,6 @@ static const int ScreenshotIdRole = Qt::UserRole + 10; // Role for the link to the .png file of a failure screenshot static const int ScreenshotLinkRole = Qt::UserRole + 100; -static QBrush passBrush(QColor("lightgreen")); -static QBrush failBrush(QColor("orangered")); -static QBrush unexpectedBrush(QColor("orange")); /* Constructs a screenshot ID for the test failure at the given \a file and @@ -80,10 +78,15 @@ static QString screenshotId(const QString &file, int line) return QString::fromLatin1("%1 %2").arg(QFileInfo(file).canonicalFilePath()).arg(line); } -ResultsView::ResultsView(QWidget *parent, const char *name) : - QTableWidget(parent) +ResultsView::ResultsView(QWidget *parent) : + QTableWidget(parent), + m_lastRow(-1), + m_ignoreEvent(false), + m_userLock(false), + m_passBrush(QColor("lightgreen")), + m_failBrush(QColor("orangered")), + m_unexpectedBrush(QColor("orange")) { - setObjectName(name); setColumnCount(3); setGridStyle(Qt::NoPen); @@ -103,11 +106,6 @@ ResultsView::ResultsView(QWidget *parent, const char *name) : verticalHeader()->hide(); horizontalHeader()->show(); - m_lastRow = -1; - - m_ignoreEvent = false; - m_userLock = false; - connect(this, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(onChanged()), Qt::DirectConnection); connect(this, SIGNAL(itemClicked(QTableWidgetItem*)), @@ -122,14 +120,14 @@ ResultsView::~ResultsView() void ResultsView::resize(int width) { - resizeColumnToContents(RESULT_POS); - if (columnWidth(RESULT_POS) < RES_SIZE) - setColumnWidth(RESULT_POS, RES_SIZE); - resizeColumnToContents(DETAILS_POS); - if (columnWidth(DETAILS_POS) < RES_SIZE) - setColumnWidth(DETAILS_POS, RES_SIZE); - setColumnWidth(DETAILS_POS, columnWidth(DETAILS_POS) + 20); - setColumnWidth(REASON_POS, width - columnWidth(RESULT_POS) - columnWidth(DETAILS_POS)); + resizeColumnToContents(ResultPosition); + if (columnWidth(ResultPosition) < ResultSize) + setColumnWidth(ResultPosition, ResultSize); + resizeColumnToContents(DetailsPosition); + if (columnWidth(DetailsPosition) < ResultSize) + setColumnWidth(DetailsPosition, ResultSize); + setColumnWidth(DetailsPosition, columnWidth(DetailsPosition) + 20); + setColumnWidth(ReasonPosition, width - columnWidth(ResultPosition) - columnWidth(DetailsPosition)); } void ResultsView::resizeEvent(QResizeEvent *event) @@ -177,7 +175,7 @@ void ResultsView::addScreenshot(const QString &screenshot, const QString &testfu void ResultsView::updateScreenshots() { for (int row = 0; row < rowCount(); ++row) { - QTableWidgetItem *result = item(row, RESULT_POS); + QTableWidgetItem *result = item(row, ResultPosition); if (!result) continue; // If there is a screenshot for this result, put a link to it in the table. @@ -189,7 +187,7 @@ void ResultsView::updateScreenshots() QTableWidgetItem* shot = new QTableWidgetItem(QIcon(QPixmap(QLatin1String(":/testrun.png"))), QString()); shot->setData(ScreenshotLinkRole, screenshot); shot->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - setItem(row, SCREEN_POS, shot); + setItem(row, ScreenPosition, shot); } } @@ -214,16 +212,16 @@ void ResultsView::append(const QString &res, const QString &test, const QString QTableWidgetItem* result = new QTableWidgetItem(res); result->setTextAlignment(Qt::AlignCenter); if (res.startsWith(QLatin1String("PASS"))) { - result->setBackground(passBrush); + result->setBackground(m_passBrush); setRowHidden(row, !m_showPassing); } else if (res.startsWith(QLatin1String("FAIL"))) { - result->setBackground(failBrush); + result->setBackground(m_failBrush); } else if (res.startsWith(QLatin1String("QDEBUG"))) { setRowHidden(row, !m_showDebug); } else if (res.startsWith(QLatin1String("SKIP"))) { setRowHidden(row, !m_showSkipped); } else if (res.startsWith(QLatin1String("XFAIL")) || res.startsWith(QLatin1String("XPASS"))) { - result->setBackground(unexpectedBrush); + result->setBackground(m_unexpectedBrush); } if ((res.contains(QLatin1String("FAIL")) || res.startsWith(QLatin1String("XPASS"))) && !m_failedTests.contains(test)) @@ -235,14 +233,14 @@ void ResultsView::append(const QString &res, const QString &test, const QString QTableWidgetItem *testDetails = new QTableWidgetItem(formatTestDetails(test, dataTag)); testDetails->setToolTip(formatLocation(file, line)); - setItem(row, RESULT_POS, result); - setItem(row, DETAILS_POS, testDetails); - setItem(row, REASON_POS, new QTableWidgetItem(reason)); + setItem(row, ResultPosition, result); + setItem(row, DetailsPosition, testDetails); + setItem(row, ReasonPosition, new QTableWidgetItem(reason)); resize(width()); resizeRowToContents(row); if (currentRow() == -1) - scrollToItem(item(row, REASON_POS)); + scrollToItem(item(row, ReasonPosition)); m_resultsWindow->navigateStateChanged(); updateScreenshots(); @@ -302,7 +300,7 @@ QString ResultsView::result(int row) if (row >= rowCount()) return QString(); - return item(row, RESULT_POS)->text().simplified(); + return item(row, ResultPosition)->text().simplified(); } QString ResultsView::reason(int row) @@ -310,7 +308,7 @@ QString ResultsView::reason(int row) if (row >= rowCount()) return QString(); - QString txt = item(row, REASON_POS)->text(); + QString txt = item(row, ReasonPosition)->text(); const int pos = txt.indexOf(QLatin1Char('\n')); if (pos > 0) txt.truncate(pos); @@ -322,7 +320,7 @@ QString ResultsView::location(int row) if (row >= rowCount()) return QString(); - return item(row, DETAILS_POS)->toolTip(); + return item(row, DetailsPosition)->toolTip(); } QString ResultsView::file(int row) @@ -440,7 +438,7 @@ void ResultsView::showSkipped(bool show) void ResultsView::updateHidden(const QString &result, bool show) { for (int row = 0; row < rowCount(); ++row) { - QTableWidgetItem *resultItem = item(row, RESULT_POS); + QTableWidgetItem *resultItem = item(row, ResultPosition); if (resultItem && resultItem->text().startsWith(result)) setRowHidden(row, !show); } @@ -679,10 +677,10 @@ void ResultsView::copyResults() QString html = QLatin1String("<html><table>"); QString text; for (int row = 0; row < rowCount(); ++row) { - QString result = item(row, RESULT_POS)->text().trimmed(); - QString detail = item(row, DETAILS_POS)->text(); - QString location = item(row, DETAILS_POS)->toolTip(); - QString reason = item(row, REASON_POS)->text(); + QString result = item(row, ResultPosition)->text().trimmed(); + QString detail = item(row, DetailsPosition)->text(); + QString location = item(row, DetailsPosition)->toolTip(); + QString reason = item(row, ReasonPosition)->text(); html += QString::fromLatin1("<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>") .arg(result).arg(detail).arg(location).arg(htmlQuote(reason)); text += QString::fromLatin1("%1\n%2\n%3\n%4\n").arg(result).arg(detail).arg(location).arg(reason); diff --git a/src/plugins/qttest/resultsview.h b/src/plugins/qttest/resultsview.h index c00bbaf8a3017ee3e2a3959003bca52a4b509604..5cc6c89c651b46d0cad3808e8d552191a35f6538 100644 --- a/src/plugins/qttest/resultsview.h +++ b/src/plugins/qttest/resultsview.h @@ -37,7 +37,9 @@ #include "testsettings.h" #include <coreplugin/ioutputpane.h> + #include <QTableWidget> +#include <QBrush> class ResultsView; class TestResultsWindow; @@ -50,7 +52,7 @@ class ResultsView : public QTableWidget Q_OBJECT public: - ResultsView(QWidget *parent = 0, const char *name = 0); + explicit ResultsView(QWidget *parent = 0); virtual ~ResultsView(); QString result(int row); @@ -78,6 +80,14 @@ public slots: signals: void defectSelected(TestCaseRec rec); +private slots: + void onChanged(); + void emitCurSelection(); + void onItemClicked(QTableWidgetItem *); + void showPassing(bool); + void showDebugMessages(bool); + void showSkipped(bool); + private: QString formatTestDetails(const QString &test, const QString &dataTag); QString formatLocation(const QString &file, const QString &line); @@ -106,14 +116,9 @@ private: bool m_showSkipped; QStringList m_failedTests; TestSettings m_testSettings; - -private slots: - void onChanged(); - void emitCurSelection(); - void onItemClicked(QTableWidgetItem *); - void showPassing(bool); - void showDebugMessages(bool); - void showSkipped(bool); + const QBrush m_passBrush; + const QBrush m_failBrush; + const QBrush m_unexpectedBrush; }; class TestResultsWindow : public Core::IOutputPane diff --git a/src/plugins/qttest/testcode.cpp b/src/plugins/qttest/testcode.cpp index e367014f0ec7d338b497c9e2f6a78f9931cfce24..b18a5c086cd00b2e3bbd5c94642e3d262eea64ac 100644 --- a/src/plugins/qttest/testcode.cpp +++ b/src/plugins/qttest/testcode.cpp @@ -42,9 +42,16 @@ #include <coreplugin/editormanager/editormanager.h> #include <extensionsystem/pluginmanager.h> +#include <texteditor/basetexteditor.h> + +#include <coreplugin/icontext.h> + +#include <qmljs/qmljsmodelmanagerinterface.h> + #include <qmljs/parser/qmljsastvisitor_p.h> #include <qmljs/parser/qmljsast_p.h> + #include <AST.h> #include <ASTVisitor.h> #include <Literals.h> @@ -85,8 +92,8 @@ private: bool visit(QmlJS::AST::IdentifierExpression *identifier) { QString name = identifier->name->asString(); - m_foundTestCase = (name == "testcase"); - if (!m_foundTestCase && (name == "prompt" || name == "manualTest")) + m_foundTestCase = (name == QLatin1String("testcase")); + if (!m_foundTestCase && (name == QLatin1String("prompt") || name == QLatin1String("manualTest"))) m_testCode->setManualTest(identifier->identifierToken.offset); return true; } @@ -175,7 +182,7 @@ protected: if (symbol->name()) { const CPlusPlus::QualifiedNameId *qn = symbol->name()->asQualifiedNameId(); if (qn && qn->base()) { - QString name = QString("%1::%2").arg(qn->base()->identifier()->chars()) + QString name = QString::fromLatin1("%1::%2").arg(qn->base()->identifier()->chars()) .arg(qn->name()->identifier()->chars()); if (m_knownTestFunctions.contains(name)) m_testCode->processFunction(QString(symbol->name()->identifier()->chars()), @@ -197,7 +204,7 @@ protected: CPlusPlus::Symbol *member = *it; CPlusPlus::Function *fun = member->type()->asFunctionType(); if (fun && fun->isSlot() && member && member->name() && member->name()->identifier()) { - m_knownTestFunctions.append(className + "::" + m_knownTestFunctions.append(className + QLatin1String("::") + QString(member->name()->identifier()->chars())); m_testCode->processFunction(QString(member->name()->identifier()->chars()), fun->line(), fun->startOffset(), fun->endOffset()); @@ -259,11 +266,11 @@ TestFunctionInfo& TestFunctionInfo::operator=(const TestFunctionInfo &other) bool TestFunctionInfo::validFunctionName(const QString &funcName) { return (!funcName.isEmpty() - && funcName != "init" - && funcName != "initTestCase" - && funcName != "cleanup" - && funcName != "cleanupTestCase" - && !funcName.endsWith("_data")); + && funcName != QLatin1String("init") + && funcName != QLatin1String("initTestCase") + && funcName != QLatin1String("cleanup") + && funcName != QLatin1String("cleanupTestCase") + && !funcName.endsWith(QLatin1String("_data"))); } TestCode::TestCode(const QString &basePath, const QString &externalPath, const QString &fileName) : @@ -278,13 +285,13 @@ TestCode::TestCode(const QString &basePath, const QString &externalPath, const Q m_errored(false) { QString baseName = baseFileName(); - if (baseName.endsWith(".qtt")) + if (baseName.endsWith(QLatin1String(".qtt"))) m_testType = TypeSystemTest; - else if (baseName.startsWith("prf_")) + else if (baseName.startsWith(QLatin1String("prf_"))) m_testType = TypePerformanceTest; - else if (baseName.startsWith("int_")) + else if (baseName.startsWith(QLatin1String("int_"))) m_testType = TypeIntegrationTest; - else if (baseName.endsWith(".cpp")) + else if (baseName.endsWith(QLatin1String(".cpp"))) m_testType = TypeUnitTest; connect(&m_parseTimer, SIGNAL(timeout()), this, SLOT(parseDocument()), Qt::DirectConnection); @@ -297,17 +304,17 @@ TestCode::~TestCode() bool TestCode::parseComments(const QString &contents) { - static QRegExp componentRegEx("//TESTED_COMPONENT=(.*)"); - static QRegExp fileRegEx("//TESTED_FILE=(.*)"); - static QRegExp classRegEx("//TESTED_CLASS=(.*)"); - static QRegExp groupsRegEx("\\\\groups\\s+(.*)"); + static QRegExp componentRegEx(QLatin1String("//TESTED_COMPONENT=(.*)")); + static QRegExp fileRegEx(QLatin1String("//TESTED_FILE=(.*)")); + static QRegExp classRegEx(QLatin1String("//TESTED_CLASS=(.*)")); + static QRegExp groupsRegEx(QLatin1String("\\\\groups\\s+(.*)")); m_testedComponent.clear(); m_testedFile.clear(); m_testedClass.clear(); int offset = 0; - QStringList fileContents = contents.split("\n"); + QStringList fileContents = contents.split(QLatin1Char('\n')); foreach (const QString &line, fileContents) { if (m_testedComponent.isEmpty() && line.contains(componentRegEx)) { m_testedComponent = componentRegEx.cap(1); @@ -348,10 +355,10 @@ bool TestCode::openTestInEditor(const QString &testFunction) m_codeEditor = qobject_cast<TextEditor::BaseTextEditor*>(edit); if (m_codeEditor) { - if (m_fileName.endsWith(".qtt")) { + if (m_fileName.endsWith(QLatin1String(".qtt"))) { connect(edit, SIGNAL(contextHelpIdRequested(TextEditor::ITextEditor*,int)), this, SLOT(onContextHelpIdRequested(TextEditor::ITextEditor*,int))); - m_codeEditor->setContextHelpId("QtUiTest Manual"); + m_codeEditor->setContextHelpId(QLatin1String("QtUiTest Manual")); } } @@ -399,7 +406,7 @@ bool TestCode::testFunctionExists(QString funcName) QString TestCode::testedComponent() const { if (m_testedComponent.isEmpty()) - return "other"; + return QLatin1String("other"); return m_testedComponent; } @@ -506,19 +513,19 @@ QString TestCode::testTypeString() const QString ret; switch (m_testType) { case TypeUnitTest: - ret = "Unit"; + ret = QLatin1String("Unit"); break; case TypeIntegrationTest: - ret = "Integration"; + ret = QLatin1String("Integration"); break; case TypePerformanceTest: - ret = "Performance"; + ret = QLatin1String("Performance"); break; case TypeSystemTest: - ret = "System"; + ret = QLatin1String("System"); break; default: - ret = "Unknown"; + ret = QLatin1String("Unknown"); break; } return ret; @@ -574,7 +581,7 @@ void TestCode::parseDocument() m_testCase.clear(); if (m_testType == TypeSystemTest) { - static QRegExp fileNameReg(".*/(.*)/.*\\.qtt$"); + static QRegExp fileNameReg(QLatin1String(".*/(.*)/.*\\.qtt$")); if (fileNameReg.indexIn(QDir::fromNativeSeparators(m_qmlJSDoc->fileName())) >= 0) m_testCase = fileNameReg.cap(1); SystemTestCodeSync sync(this); @@ -584,10 +591,10 @@ void TestCode::parseDocument() m_errored = true; } else { // Determine the testcase class name - foreach (const CPlusPlus::Document::MacroUse macro, m_cppDoc->macroUses()) { + foreach (const CPlusPlus::Document::MacroUse ¯o, m_cppDoc->macroUses()) { QString macroName(macro.macro().name()); - if (macro.isFunctionLike() && ((macroName == "QTEST_MAIN") - || (macroName == "QTEST_APPLESS_MAIN") || (macroName == "QTEST_NOOP_MAIN"))) { + if (macro.isFunctionLike() && ((macroName == QLatin1String("QTEST_MAIN")) + || (macroName == QLatin1String("QTEST_APPLESS_MAIN")) || (macroName == QLatin1String("QTEST_NOOP_MAIN")))) { int pos = macro.arguments()[0].position(); int length = macro.arguments()[0].length(); m_testCase = contents.mid(pos, length); @@ -628,15 +635,15 @@ QString TestCode::projectFileName() // Figure out what the pro file is. QString srcPath = QDir::convertSeparators(m_fileInfo->absolutePath()); QDir D(srcPath); - QStringList files = D.entryList(QStringList("*.pro")); + QStringList files = D.entryList(QStringList(QLatin1String("*.pro"))); if (files.count() > 1) { - qDebug() << "CFAIL", "I am confused: Multiple .pro files (" + files.join(",") + qDebug() << "CFAIL", "I am confused: Multiple .pro files (" + files.join(QString(QLatin1Char(','))) + ") found in '" + srcPath + "'."; - return ""; + return QString(); } if (files.count() == 0) - return ""; + return QString(); return QString(srcPath + QDir::separator() + files[0]); } @@ -645,19 +652,19 @@ QString TestCode::execFileName() { QString proFile = projectFileName(); if (proFile.isEmpty()) - return ""; + return QString(); QFile F(proFile); if (F.open(QFile::ReadOnly)) { QTextStream S(&F); while (!S.atEnd()) { QString line = S.readLine(); - if (line.contains("TARGET")) { - line = line.mid(line.indexOf("=") + 1); + if (line.contains(QLatin1String("TARGET"))) { + line = line.mid(line.indexOf(QLatin1Char('=')) + 1); line = line.simplified(); - if (line.contains("$$TARGET")) { + if (line.contains(QLatin1String("$$TARGET"))) { QFileInfo inf(proFile); - line.replace("$$TARGET",inf.baseName()); + line.replace(QLatin1String("$$TARGET"),inf.baseName()); } return line; } @@ -670,7 +677,7 @@ QString TestCode::execFileName() return fInfo.baseName(); } - return ""; + return QString(); } @@ -755,7 +762,7 @@ bool TestCollection_p::isUnitTestCase(const CPlusPlus::Document::Ptr &doc, { // If a source file #includes QtTest/QTest, assume it is a testcase foreach (const CPlusPlus::Document::Include &i, doc->includes()) { - if (i.fileName().contains("QtTest") || i.fileName().contains("QTest")) + if (i.fileName().contains(QLatin1String("QtTest")) || i.fileName().contains(QLatin1String("QTest"))) return true; if (visited.contains(i.fileName())) @@ -833,7 +840,7 @@ void TestCollection_p::scanTests(const QString &suitePath) if (!D.exists()) return; - QFileInfoList qttTestFiles = D.entryInfoList(QStringList() << "*.qtt", QDir::Files); + QFileInfoList qttTestFiles = D.entryInfoList(QStringList(QLatin1String("*.qtt")), QDir::Files); QStringList qttTests; foreach (const QFileInfo &qttTestFile, qttTestFiles) { qttTests << qttTestFile.absoluteFilePath(); @@ -843,7 +850,7 @@ void TestCollection_p::scanTests(const QString &suitePath) if (!qttTests.isEmpty()) m_qmlJSModelManager->updateSourceFiles(qttTests, true); - QFileInfoList cppTestFiles = D.entryInfoList(QStringList() << "*.cpp", QDir::Files); + QFileInfoList cppTestFiles = D.entryInfoList(QStringList(QLatin1String("*.cpp")), QDir::Files); QStringList cppTests; const CPlusPlus::Snapshot snapshot = m_cppModelManager->snapshot(); foreach (const QFileInfo &cppTestFile, cppTestFiles) { @@ -860,11 +867,11 @@ void TestCollection_p::scanTests(const QString &suitePath) m_cppModelManager->updateSourceFiles(cppTests); QStringList potentialSubdirs = - D.entryList(QStringList() << "*", QDir::Dirs|QDir::NoDotAndDotDot); + D.entryList(QStringList(QString(QLatin1Char('*'))), QDir::Dirs|QDir::NoDotAndDotDot); foreach (const QString &dname, potentialSubdirs) { // stop scanning subdirs if we've ended up in a testdata subdir - if (dname != "testdata") + if (dname != QLatin1String("testdata")) scanTests(suitePath + QDir::separator() + dname); } } @@ -893,12 +900,12 @@ TestCode *TestCollection_p::findCode(const QString &fileName, const QString &bas QFileInfo inf(fileName); if (inf.exists() && inf.isFile()) { tmp = new TestCode(basePath, extraPath, fileName); - if (fileName.endsWith(".qtt")) { + if (fileName.endsWith(QLatin1String(".qtt"))) { m_qttDocumentMap[fileName] = tmp; - m_qmlJSModelManager->updateSourceFiles(QStringList() << fileName, true); + m_qmlJSModelManager->updateSourceFiles(QStringList(fileName), true); } else { m_cppDocumentMap[fileName] = tmp; - m_cppModelManager->updateSourceFiles(QStringList() << fileName); + m_cppModelManager->updateSourceFiles(QStringList(fileName)); } if (tmp) { m_codeList.append(tmp); @@ -969,8 +976,11 @@ QStringList TestCollection_p::manualTests(const QString &startPath, bool compone if (tmp && (startPath.isEmpty() || tmp->visualFileName(componentMode).startsWith(startPath))) { for (uint j = 0; j < tmp->testFunctionCount(); ++j) { TestFunctionInfo *inf = tmp->testFunction(j); - if (inf && inf->isManualTest()) - ret.append(QString("%1::%2").arg(tmp->testCase()).arg(inf->functionName())); + if (inf && inf->isManualTest()) { + ret.append(tmp->testCase()); + ret.append(QLatin1String("::")); + ret.append(inf->functionName()); + } } } } @@ -1116,8 +1126,8 @@ void TestCode::setManualTest(int offset) bool TestCode::validFunctionName(const QString &funcName) { - if (funcName.isEmpty() || funcName == "initTestCase" || funcName == "init" - || funcName == "cleanupTestCase" || funcName == "cleanup" || funcName.endsWith("_data")) { + if (funcName.isEmpty() || funcName == QLatin1String("initTestCase") || funcName == QLatin1String("init") + || funcName == QLatin1String("cleanupTestCase") || funcName == QLatin1String("cleanup") || funcName.endsWith(QLatin1String("_data"))) { return false; } return true; @@ -1166,7 +1176,7 @@ void TestCode::addTestFunction(const QString &newFuncName, const QString &newFun } QString insertString = - QString("\n\n %1_data:\n {\n },\n\n %1: function()\n {\n }") + QString::fromLatin1("\n\n %1_data:\n {\n },\n\n %1: function()\n {\n }") .arg(newFuncName); m_codeEditor->setCursorPosition(entryPoint); @@ -1175,10 +1185,10 @@ void TestCode::addTestFunction(const QString &newFuncName, const QString &newFun QString lineBefore = m_codeEditor->textAt(m_codeEditor->position(), lineLength).simplified(); m_codeEditor->setCursorPosition(m_codeEditor->position(TextEditor::ITextEditor::EndOfLine)); - if (!lineBefore.endsWith(",") && !m_testFunctions.isEmpty()) - insertString.prepend(","); + if (!lineBefore.endsWith(QLatin1Char(',')) && !m_testFunctions.isEmpty()) + insertString.prepend(QLatin1Char(',')); else - insertString.append(","); + insertString.append(QLatin1Char(',')); m_codeEditor->insert(insertString); } else { @@ -1228,7 +1238,7 @@ void TestCode::addTestFunction(const QString &newFuncName, const QString &newFun m_codeEditor->gotoLine(declLine); m_codeEditor->setCursorPosition(m_codeEditor->position(TextEditor::ITextEditor::StartOfLine)); - insertString = QString(" void %1_data();\n void %1();\n").arg(newFuncName); + insertString = QString::fromLatin1(" void %1_data();\n void %1();\n").arg(newFuncName); m_codeEditor->insert(insertString); m_codeEditor->gotoLine(entryLine + 2); } @@ -1260,18 +1270,18 @@ QString TestCode::actualBasePath() QString TestCode::fullVisualSuitePath(bool componentViewMode) const { if (m_fileName.isEmpty()) - return ""; + return QString(); if (componentViewMode) return QDir::convertSeparators(m_basePath + QDir::separator() + testedComponent()); - if (!m_fileName.endsWith(".cpp") && !m_fileName.endsWith(".qtt")) + if (!m_fileName.endsWith(QLatin1String(".cpp")) && !m_fileName.endsWith(QLatin1String(".qtt"))) return m_fileName; QString fn = m_fileName; if (!m_externalPath.isEmpty() && fn.startsWith(m_externalPath)) { fn.remove(m_externalPath); - fn = m_basePath + QDir::separator() + "tests" + QDir::separator() + "external" + fn; + fn = m_basePath + QDir::separator() + QLatin1String("tests") + QDir::separator() + QLatin1String("external") + fn; } QFileInfo inf(fn); @@ -1282,7 +1292,7 @@ QString TestCode::fullVisualSuitePath(bool componentViewMode) const fn = fn.left(fn.length() - (inf.baseName().length() + 1)); // remove '/tests" if that's on the end - QString eolstr = QString(QDir::separator()) + "tests"; + QString eolstr = QString(QDir::separator()) + QLatin1String("tests"); if (fn.endsWith(eolstr)) { int pos = fn.lastIndexOf(eolstr); if (pos) fn = fn.left(pos); @@ -1320,8 +1330,8 @@ QString TestCode::targetFileName(const QString &buildPath) const QString fn = m_fileName; if (!m_externalPath.isEmpty() && fn.startsWith(m_externalPath)) { fn.remove(m_externalPath); - fn = m_basePath + QDir::separator() + "tests" + QDir::separator() - + "external" + QDir::separator() + fn; + fn = m_basePath + QDir::separator() + QLatin1String("tests") + QDir::separator() + + QLatin1String("external") + QDir::separator() + fn; } fn.remove(m_basePath); @@ -1359,20 +1369,20 @@ void TestCode::onContextHelpIdRequested(TextEditor::ITextEditor *editor, int pos if (!qstSlots.contains(slot)) qstSlots << slot.left(slot.indexOf('(')); } - qstSlots << "compare" << "verify" << "waitFor" - << "expect" << "fail" << "tabBar" << "menuBar"; + qstSlots << QLatin1String("compare") << QLatin1String("verify") << QLatin1String("waitFor") + << QLatin1String("expect") << QLatin1String("fail") << QLatin1String("tabBar") << QLatin1String("menuBar"); } if (start < end) { QString function = text.mid(start, end - start); if (qstSlots.contains(function)) { - m_codeEditor->setContextHelpId(QString("QSystemTest::%1").arg(function)); + m_codeEditor->setContextHelpId(QString::fromLatin1("QSystemTest::%1").arg(function)); return; } } #endif - m_codeEditor->setContextHelpId("QtUiTest Manual"); + m_codeEditor->setContextHelpId(QLatin1String("QtUiTest Manual")); } bool TestCode::hasUnsavedChanges() const diff --git a/src/plugins/qttest/testcode.h b/src/plugins/qttest/testcode.h index d89e06ca8289819df9e49e4570e590d5dd11c850..a4a60d698b3123e26becb6a50e3f2bdc35cd4317 100644 --- a/src/plugins/qttest/testcode.h +++ b/src/plugins/qttest/testcode.h @@ -35,10 +35,7 @@ #include "testconfigurations.h" -#include <texteditor/basetexteditor.h> -#include <coreplugin/icontext.h> #include <qmljs/qmljsdocument.h> -#include <qmljs/qmljsmodelmanagerinterface.h> #include <cplusplus/CppDocument.h> #include <QStringList> @@ -53,6 +50,15 @@ namespace Core { class IEditor; } +namespace TextEditor { +class ITextEditor; +class BaseTextEditor; +} + +namespace QmlJS { +class ModelManagerInterface; +} + namespace CPlusPlus { class CppModelManagerInterface; } diff --git a/src/plugins/qttest/testconfigurations.cpp b/src/plugins/qttest/testconfigurations.cpp index fa58317fa33f2b2fb12fcaf71a8dc8adcfb8e5fa..c376faf70efa3b09b0768b6b16d21dfde17018fd 100644 --- a/src/plugins/qttest/testconfigurations.cpp +++ b/src/plugins/qttest/testconfigurations.cpp @@ -134,8 +134,8 @@ void TestConfigurations_p::clear() bool TestConfigurations_p::load() { - return load(QDir::homePath() + QDir::separator() + ".qttest" - + QDir::separator() + "saved_configurations"); + return load(QDir::homePath() + QDir::separator() + QLatin1String(".qttest") + + QDir::separator() + QLatin1String("saved_configurations")); } bool TestConfigurations_p::load(const QString &fileName) @@ -147,16 +147,16 @@ bool TestConfigurations_p::load(const QString &fileName) if (f.open(QIODevice::ReadOnly)) { QTextStream S(&f); QString tmpName = S.readLine(); - if (tmpName.startsWith("VERSION=")) { + if (tmpName.startsWith(QLatin1String("VERSION="))) { bool ok; tmpName = tmpName.mid(8).simplified(); version = tmpName.toUInt(&ok); if (!ok) { - qWarning("Couldn't read version in configurations file"); + qWarning("Could not read version in configurations file"); return false; } } else { - qWarning("Couldn't read configurations file"); + qWarning("Could not read configurations file"); return false; } @@ -178,9 +178,9 @@ bool TestConfigurations_p::load(const QString &fileName) bool TestConfigurations_p::save() { - QDir().mkpath(QDir::homePath() + QDir::separator() + ".qttest"); - return save(QDir::homePath() + QDir::separator() + ".qttest" - + QDir::separator() + "saved_configurations"); + QDir().mkpath(QDir::homePath() + QDir::separator() + QLatin1String(".qttest")); + return save(QDir::homePath() + QDir::separator() + QLatin1String(".qttest") + + QDir::separator() + QLatin1String("saved_configurations")); } bool TestConfigurations_p::save(const QString &fileName) @@ -189,7 +189,7 @@ bool TestConfigurations_p::save(const QString &fileName) QFile f(fileName); if (f.open(QIODevice::WriteOnly)) { QTextStream S(&f); - S << QString("VERSION=%1").arg(curVersion) << "\n"; + S << QString::fromLatin1("VERSION=%1").arg(curVersion) << '\n'; TestConfig *tmp; for (int i = 0; i < m_configList.count(); ++i) { tmp = m_configList.at(i); @@ -248,9 +248,9 @@ TestConfig *TestConfigurations_p::config(const QString &cfgName) cfg = new TestConfig(); cfg->setConfigName(cfgName); - cfg->setRunParams(""); - cfg->setRunScript(""); - cfg->setPostProcessScript(""); + cfg->setRunParams(QString()); + cfg->setRunScript(QString()); + cfg->setPostProcessScript(QString()); m_configList.append(cfg); return cfg; @@ -305,7 +305,7 @@ void TestConfigurations_p::setSelectedTests(const QStringList &list) QStringList tmpList; foreach (const QString &selection, list) { - QString tcname = selection.left(selection.indexOf("::")); + QString tcname = selection.left(selection.indexOf(QLatin1String("::"))); TestCode *tc = m_testCollection.findCodeByTestCaseName(tcname); if (tc) { foreach (const QString &srcPath, srcPaths) { @@ -336,7 +336,7 @@ QString TestConfigurations_p::currentTestCase() TestConfig *tmp = activeConfiguration(); if (tmp) return tmp->currentTestCase(); - return ""; + return QString(); } QString TestConfigurations_p::currentTestFunction() @@ -346,7 +346,7 @@ QString TestConfigurations_p::currentTestFunction() if (tmp && tmp->isActive()) return tmp->currentTestFunc(); } - return ""; + return QString(); } void TestConfigurations_p::rescan() @@ -410,7 +410,7 @@ void TestConfig::clear() m_branchDetected = false; m_autodetectPlatformConfiguration = true; m_platformDetected = false; - m_uploadMethod = "SCP"; + m_uploadMethod = QLatin1String("SCP"); m_buildEnvironment.clear(); m_uploadMode = UploadAuto; m_makeCommand.clear(); @@ -427,12 +427,12 @@ QString TestConfig::runScript() QString TestConfig::copyrightHeader() { - QString ret = srcPath() + QDir::separator() + "dist" + QDir::separator() - + "header-dual-license.txt"; + QString ret = srcPath() + QDir::separator() + QLatin1String("dist") + QDir::separator() + + QLatin1String("header-dual-license.txt"); QFileInfo inf(ret); if (inf.exists()) return ret; - return ""; + return QString(); } void TestConfig::setQMAKESPEC(const QString &newValue) @@ -450,7 +450,7 @@ QString TestConfig::QMAKESPEC() if (qtBuildConfig) return qtBuildConfig->qtVersion()->mkspec(); else - return QSystem::envKey(buildEnvironment(), "QMAKESPEC"); + return QSystem::envKey(buildEnvironment(), QLatin1String("QMAKESPEC")); } return m_qmakeMkspec; @@ -468,12 +468,12 @@ void TestConfig::setQMAKESPECSpecialization(const QString &newValue) QString TestConfig::PATH() { - return QSystem::envKey(buildEnvironment(), "PATH"); + return QSystem::envKey(buildEnvironment(), QLatin1String("PATH")); } QString TestConfig::QTDIR() { - return QSystem::envKey(buildEnvironment(), "QTDIR"); + return QSystem::envKey(buildEnvironment(), QLatin1String("QTDIR")); } QString TestConfig::runParams() @@ -493,12 +493,12 @@ QString TestConfig::postProcessScript() QString TestConfig::makeCommand() { if (m_makeCommand.isEmpty()) { - if (QMAKESPEC().contains("msvc")) - m_makeCommand = "nmake"; - else if (QMAKESPEC().contains("mingw")) - m_makeCommand = "mingw32-make"; + if (QMAKESPEC().contains(QLatin1String("msvc"))) + m_makeCommand = QLatin1String("nmake"); + else if (QMAKESPEC().contains(QLatin1String("mingw"))) + m_makeCommand = QLatin1String("mingw32-make"); else - m_makeCommand = "make"; + m_makeCommand = QLatin1String("make"); m_makeCommand = QSystem::which(PATH(), m_makeCommand); } return m_makeCommand; @@ -515,7 +515,7 @@ QString TestConfig::qmakeCommand(bool /*desktopQMakeRequested*/) } qWarning() << "Unable to detect qmake command, falling back to \"qmake\""; - return "qmake"; + return QLatin1String("qmake"); } void TestConfig::setUploadMode(UploadMode mode) @@ -534,9 +534,9 @@ bool TestConfig::uploadResults() return true; if (m_uploadMode == TestConfig::UploadNoThanks) return false; - if (QMessageBox::question(0,"Upload Test Results", - "You can positively influence the quality of " + configName() - + " by contributing test results.\n\nWould you like to upload your Test Results", + if (QMessageBox::question(0, tr("Upload Test Results"), + tr("You can positively influence the quality of %1" + " by contributing test results.\n\nWould you like to upload your Test Results").arg(configName()), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) return true; return false; @@ -548,39 +548,39 @@ bool TestConfig::isRemoteTarget(QString &deviceName, QString &testDeviceType, if (m_activeProject && m_activeProject->activeTarget()) { ProjectExplorer::RunConfiguration *r = m_activeProject->activeTarget()->activeRunConfiguration(); if (r) { - if (r->id() == "Qt4ProjectManager.MaemoRunConfiguration") { + if (r->id() == QLatin1String("Qt4ProjectManager.MaemoRunConfiguration")) { RemoteLinux::Internal::MaemoRunConfiguration *mr = static_cast<RemoteLinux::Internal::MaemoRunConfiguration*>(r); if (mr) { QSharedPointer<const RemoteLinux::LinuxDeviceConfiguration> mc = mr->deviceConfig(); if (mc){ deviceName = mc->name(); sshParameters = mc->sshParameters(); - testDeviceType = "Maemo";//Qt4Test::TestController::Maemo; + testDeviceType = QLatin1String("Maemo");//Qt4Test::TestController::Maemo; return true; }else{ qWarning() << "Invalid remote" << deviceName; } } - } else if (r->id() == "Qt4ProjectManager.Qt4RunConfiguration" - || r->id() == "ProjectExplorer.CustomExecutableRunConfiguration") { - deviceName = "Desktop"; - sshParameters.host = "127.0.0.1"; + } else if (r->id() == QLatin1String("Qt4ProjectManager.Qt4RunConfiguration") + || r->id() == QLatin1String("ProjectExplorer.CustomExecutableRunConfiguration")) { + deviceName = QLatin1String("Desktop"); + sshParameters.host = QLatin1String("127.0.0.1"); sshParameters.port = 5656; sshParameters.userName.clear(); sshParameters.password.clear(); sshParameters.privateKeyFile.clear(); - testDeviceType = "Desktop";//Qt4Test::TestController::Desktop; + testDeviceType = QLatin1String("Desktop");//Qt4Test::TestController::Desktop; return false; } } } - deviceName = "Unknown"; - sshParameters.host = "0.0.0.0"; + deviceName = QLatin1String("Unknown"); + sshParameters.host = QLatin1String("0.0.0.0"); sshParameters.port = 0; sshParameters.userName.clear(); sshParameters.password.clear(); sshParameters.privateKeyFile.clear(); - testDeviceType = "Desktop";//Qt4Test::TestController::Desktop; + testDeviceType = QLatin1String("Desktop"); //Qt4Test::TestController::Desktop; return false; } @@ -590,7 +590,7 @@ void TestConfig::loadLine(QTextStream *s, const QString &id, QString &value) Q_UNUSED(id); QString tmp = s->readLine(); - int pos = tmp.indexOf("="); + int pos = tmp.indexOf(QLatin1Char('=')); value = tmp.mid(pos + 1); } @@ -599,7 +599,7 @@ void TestConfig::loadLine(QTextStream *s, const QString &id, int &value) Q_UNUSED(id); QString tmp = s->readLine(); - int pos = tmp.indexOf("="); + int pos = tmp.indexOf(QLatin1Char('=')); value = tmp.mid(pos + 1).toInt(); } @@ -611,61 +611,61 @@ bool TestConfig::load(uint version, QTextStream *s) return false; QString tmp = s->readLine(); - if (tmp == "CONFIG-START") { - loadLine(s, "", m_configName); - loadLine(s, "", m_runParams); - loadLine(s, "", m_postprocessScript); - loadLine(s, "", m_runScript); - loadLine(s, "", m_lastTestcase); - loadLine(s, "", m_lastTestfunc); + if (tmp == QLatin1String("CONFIG-START")) { + loadLine(s, QString(), m_configName); + loadLine(s, QString(), m_runParams); + loadLine(s, QString(), m_postprocessScript); + loadLine(s, QString(), m_runScript); + loadLine(s, QString(), m_lastTestcase); + loadLine(s, QString(), m_lastTestfunc); QString tmp; - loadLine(s, "", tmp); - m_lastSelectedTests = tmp.split(",", QString::SkipEmptyParts); + loadLine(s, QString(), tmp); + m_lastSelectedTests = tmp.split(QLatin1Char(','), QString::SkipEmptyParts); if (version > 1) { - loadLine(s, "", m_uploadChange); - loadLine(s, "", m_uploadBranch); - loadLine(s, "", m_uploadPlatform); + loadLine(s, QString(), m_uploadChange); + loadLine(s, QString(), m_uploadBranch); + loadLine(s, QString(), m_uploadPlatform); if (version < 8) tmp = s->readLine(); } if (version > 2) { if (version < 8) tmp = s->readLine(); tmp = s->readLine(); - m_autodetectPlatformConfiguration = (tmp == "AUTO-PLATFORM=1"); - loadLine(s, "", m_uploadMethod); + m_autodetectPlatformConfiguration = (tmp == QLatin1String("AUTO-PLATFORM=1")); + loadLine(s, QString(), m_uploadMethod); } if (version > 3) { - loadLine(s, "", tmp); - m_extraTests = tmp.split(":", QString::SkipEmptyParts); + loadLine(s, QString(), tmp); + m_extraTests = tmp.split(QLatin1Char(':'), QString::SkipEmptyParts); } if (version > 4) { int tmp; - loadLine(s, "", tmp); + loadLine(s, QString(), tmp); m_uploadMode = static_cast<UploadMode>(tmp); } if (version > 5 && version < 7) { QString dummy; - loadLine(s, "", dummy); - loadLine(s, "", dummy); - loadLine(s, "", dummy); + loadLine(s, QString(), dummy); + loadLine(s, QString(), dummy); + loadLine(s, QString(), dummy); } if (version >= 9) { - loadLine(s, "", m_qmakeMkspec); - loadLine(s, "", m_uploadBranchSpecialization); - loadLine(s, "", m_qmakeMkspecSpecialization); + loadLine(s, QString(), m_qmakeMkspec); + loadLine(s, QString(), m_uploadBranchSpecialization); + loadLine(s, QString(), m_qmakeMkspecSpecialization); } //Add member here QString checkSum; - loadLine(s, "", checkSum); - return checkSum == "CONFIG-END"; + loadLine(s, QString(), checkSum); + return checkSum == QLatin1String("CONFIG-END"); } return false; } void TestConfig::saveLine(QTextStream *s, const QString &id, const QString &value) { - *s << id << "=" << value << "\n"; + *s << id << '=' << value << '\n'; } bool TestConfig::save(QTextStream *s) @@ -673,29 +673,29 @@ bool TestConfig::save(QTextStream *s) if (s == 0) return false; - QString checkSum = "CONFIG-START"; - *s << checkSum << "\n"; - saveLine(s, "NAME", m_configName); - saveLine(s, "RUN_PARAMS", m_runParams); - saveLine(s, "POSTPROCESS_SCRIPT", m_postprocessScript); - saveLine(s, "RUN_SCRIPT", m_runScript); - saveLine(s, "LAST_TESTCASE", m_lastTestcase); - saveLine(s, "LAST_TESTFUNC", m_lastTestfunc); - saveLine(s, "LAST_SELECTED_TESTS", m_lastSelectedTests.join(",")); - saveLine(s, "CHANGE", m_uploadChange); - saveLine(s, "BRANCH", m_uploadBranch); - saveLine(s, "PLATFORM", m_uploadPlatform); - saveLine(s, "AUTO-PLATFORM", QString("%1").arg(m_autodetectPlatformConfiguration)); - saveLine(s, "UPLOAD_METHOD", m_uploadMethod); - saveLine(s, "EXTRA_TESTS", m_extraTests.join(":")); - saveLine(s, "UPLOAD_MODE", QString("%1").arg(static_cast<int>(m_uploadMode))); - saveLine(s, "QMAKESPEC", m_qmakeMkspec); - saveLine(s, "BRANCH_SPECIALIZATION", m_uploadBranchSpecialization); - saveLine(s, "QMAKESPEC_SPECIALIZATION", m_qmakeMkspecSpecialization); + QString checkSum = QLatin1String("CONFIG-START"); + *s << checkSum << QLatin1Char('\n'); + saveLine(s, QLatin1String("NAME"), m_configName); + saveLine(s, QLatin1String("RUN_PARAMS"), m_runParams); + saveLine(s, QLatin1String("POSTPROCESS_SCRIPT"), m_postprocessScript); + saveLine(s, QLatin1String("RUN_SCRIPT"), m_runScript); + saveLine(s, QLatin1String("LAST_TESTCASE"), m_lastTestcase); + saveLine(s, QLatin1String("LAST_TESTFUNC"), m_lastTestfunc); + saveLine(s, QLatin1String("LAST_SELECTED_TESTS"), m_lastSelectedTests.join(QString(QLatin1Char(',')))); + saveLine(s, QLatin1String("CHANGE"), m_uploadChange); + saveLine(s, QLatin1String("BRANCH"), m_uploadBranch); + saveLine(s, QLatin1String("PLATFORM"), m_uploadPlatform); + saveLine(s, QLatin1String("AUTO-PLATFORM"), QString::fromLatin1("%1").arg(m_autodetectPlatformConfiguration)); + saveLine(s, QLatin1String("UPLOAD_METHOD"), m_uploadMethod); + saveLine(s, QLatin1String("EXTRA_TESTS"), m_extraTests.join(QString(QLatin1Char(':')))); + saveLine(s, QLatin1String("UPLOAD_MODE"), QString::number(static_cast<int>(m_uploadMode))); + saveLine(s, QLatin1String("QMAKESPEC"), m_qmakeMkspec); + saveLine(s, QLatin1String("BRANCH_SPECIALIZATION"), m_uploadBranchSpecialization); + saveLine(s, QLatin1String("QMAKESPEC_SPECIALIZATION"), m_qmakeMkspecSpecialization); //Add member here - checkSum = "CONFIG-END"; - *s << checkSum << "\n"; + checkSum = QLatin1String("CONFIG-END"); + *s << checkSum << '\n'; return true; } @@ -737,7 +737,7 @@ QString TestConfig::uploadChange() proc.setEnvironment(*buildEnvironment()); proc.setWorkingDirectory(srcPath()); - proc.start("git", QStringList() << "log" << "-1" << "--pretty=oneline"); + proc.start(QLatin1String("git"), QStringList() << QLatin1String("log") << QLatin1String("-1") << QLatin1String("--pretty=oneline")); bool ok = proc.waitForStarted(); if (ok) ok = proc.waitForFinished(); @@ -745,7 +745,7 @@ QString TestConfig::uploadChange() if (ok) { QString output = proc.readAllStandardOutput(); if (!output.isEmpty()) { - QStringList tmp = output.split(" "); + QStringList tmp = output.split(QLatin1Char(' ')); if (tmp.count() >= 2) { m_uploadChange = tmp[0]; m_changeDetected = true; @@ -768,7 +768,7 @@ QString TestConfig::uploadBranch() proc.setEnvironment(*buildEnvironment()); proc.setWorkingDirectory(srcPath()); - proc.start("git", QStringList() << "branch"); + proc.start(QLatin1String("git"), QStringList(QLatin1String("branch"))); bool ok = proc.waitForStarted(); if (ok) ok = proc.waitForFinished(); @@ -776,9 +776,9 @@ QString TestConfig::uploadBranch() if (ok) { QString output = proc.readAllStandardOutput(); if (!output.isEmpty()) { - QStringList tmp = output.split("\n"); - foreach (QString line, tmp) { - if (line.startsWith("*")) { + QStringList tmp = output.split(QLatin1Char('\n')); + foreach (const QString &line, tmp) { + if (line.startsWith(QLatin1Char('*'))) { m_uploadBranch = line.mid(2); m_branchDetected = true; } @@ -789,7 +789,7 @@ QString TestConfig::uploadBranch() if (m_branchDetected){ // prepend <Product>- to the branch name // this only supports remotes using git@... and git:// - proc.start("git", QStringList() << "remote" << "-v"); + proc.start(QLatin1String("git"), QStringList() << QLatin1String("remote") << QLatin1String("-v")); ok = proc.waitForStarted(); if (ok) ok = proc.waitForFinished(); @@ -799,16 +799,16 @@ QString TestConfig::uploadBranch() if (!output.isEmpty()) { QRegExp gitRemoteRegEx(QLatin1String("(\\w+\\s+\\w+@[^:]+):(\\w+)/\(.*)")); QRegExp gitReadonlyRemoteRegEx(QLatin1String("(\\w+\\s+\\w+://.+)/(\\w+)/(.*)")); - QStringList tmp = output.split("\n"); + QStringList tmp = output.split(QLatin1Char('\n')); foreach (const QString &line, tmp) { if (gitRemoteRegEx.exactMatch(line)) { m_uploadBranch = gitRemoteRegEx.capturedTexts()[2] - + "-" + m_uploadBranch; + + QLatin1Char('-') + m_uploadBranch; break; } if (gitReadonlyRemoteRegEx.exactMatch(line)) { m_uploadBranch = gitReadonlyRemoteRegEx.capturedTexts()[2] - + "-" + m_uploadBranch; + + QLatin1Char('-') + m_uploadBranch; break; } } @@ -872,20 +872,20 @@ void TestConfig::setAutoDetectPlatformConfiguration(bool doAutoDetect) bool TestConfig::uploadUsingScp() { - return m_uploadMethod == "SCP"; + return m_uploadMethod == QLatin1String("SCP"); } bool TestConfig::uploadUsingEMail() { - return m_uploadMethod != "SCP"; + return m_uploadMethod != QLatin1String("SCP"); } void TestConfig::setUploadMethod(bool useScp) { if (useScp) - m_uploadMethod = "SCP"; + m_uploadMethod = QLatin1String("SCP"); else - m_uploadMethod = "EMAIL"; + m_uploadMethod = QLatin1String("EMAIL"); } void TestConfig::deactivate() @@ -940,7 +940,7 @@ void TestConfig::onProjectSettingsChanged() Core::ICore *core = Core::ICore::instance(); Core::ModeManager *mgr = core->modeManager(); - if ((mgr && (mgr->currentMode()->id() != "Edit")) || TestConfigurations::instance().updatesDelayed()) { + if ((mgr && (mgr->currentMode()->id() != QLatin1String("Edit"))) || TestConfigurations::instance().updatesDelayed()) { // Try again later. emitConfigChanged(); return; @@ -985,13 +985,13 @@ QStringList *TestConfig::runEnvironment() ProjectExplorer::RunConfiguration *rc = m_activeProject->activeTarget()->activeRunConfiguration(); if (rc) { - if (rc->id() == "Qt4ProjectManager.Qt4RunConfiguration") { + if (rc->id() == QLatin1String("Qt4ProjectManager.Qt4RunConfiguration")) { m_runEnvironment = static_cast<Qt4ProjectManager::Internal::Qt4RunConfiguration*>(rc)->environment().toStringList(); - } else if (rc->id() == "ProjectExplorer.CustomExecutableRunConfiguration") { + } else if (rc->id() == QLatin1String("ProjectExplorer.CustomExecutableRunConfiguration")) { m_runEnvironment = static_cast<ProjectExplorer::CustomExecutableRunConfiguration*>(rc)->environment().toStringList(); - } else if (rc->id() == "Qt4ProjectManager.MaemoRunConfiguration") { + } else if (rc->id() == QLatin1String("Qt4ProjectManager.MaemoRunConfiguration")) { m_runEnvironment = static_cast<RemoteLinux::Internal::MaemoRunConfiguration*>(rc)->environment().toStringList(); } @@ -1003,18 +1003,18 @@ QStringList *TestConfig::runEnvironment() QString TestConfig::buildPath() { if (!m_activeProject) - return ""; + return QString(); ProjectExplorer::BuildConfiguration *b = m_activeProject->activeTarget()->activeBuildConfiguration(); if (!b) - return ""; + return QString(); return QDir::convertSeparators(b->buildDirectory()); } QString TestConfig::srcPath() { if (!m_activeProject) - return ""; + return QString(); return QDir::convertSeparators(m_activeProject->projectDirectory()); } diff --git a/src/plugins/qttest/testconfigurations.h b/src/plugins/qttest/testconfigurations.h index 4797a999a0e4736b59f555adbf108d5d4296636a..e3c732eb5289a3a65c9c2b1dab3abab0644ecd46 100644 --- a/src/plugins/qttest/testconfigurations.h +++ b/src/plugins/qttest/testconfigurations.h @@ -40,13 +40,14 @@ #include "projectexplorer/project.h" #include <../../libs/utils/ssh/sshconnection.h> -#include <QTextStream> -#include <QObject> -#include <QList> #include <QStringList> #include <QPointer> #include <QTimer> +QT_BEGIN_NAMESPACE +class QTextStream; +QT_END_NAMESPACE + class TestConfigurations_p; class TestConfig : public QObject diff --git a/src/plugins/qttest/testcontextmenu.cpp b/src/plugins/qttest/testcontextmenu.cpp index 9ce1fcaed270f04fa02aa35470464e8912d3a68c..ce2fae9c66ed8a5e934bc47100a9d3e470969f19 100644 --- a/src/plugins/qttest/testcontextmenu.cpp +++ b/src/plugins/qttest/testcontextmenu.cpp @@ -34,10 +34,15 @@ #include "testcode.h" #include "testsettings.h" #include "qsystem.h" +#include "testsuite.h" +#include "testexecuter.h" +#include "testcode.h" +#include "testoutputwindow.h" #include <coreplugin/icore.h> #include <coreplugin/inavigationwidgetfactory.h> #include <extensionsystem/iplugin.h> +#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/editormanager.h> TestContextMenu_p *TestContextMenu::m_instance = 0; @@ -104,19 +109,19 @@ TestContextMenu_p::TestContextMenu_p(QObject *widget) m_editorInsertTestFunctionAction->setEnabled(false); m_testRunAction = new QAction(widget); - m_testRunAction->setIcon(QIcon(QPixmap(":/testrun.png"))); + m_testRunAction->setIcon(QIcon(QPixmap(QLatin1String(":/testrun.png")))); m_testRunAsManualAction = new QAction(widget); - m_testRunAsManualAction->setIcon(QIcon(QPixmap(":/testrun.png"))); + m_testRunAsManualAction->setIcon(QIcon(QPixmap(QLatin1String(":/testrun.png")))); m_testDebugAction = new QAction(widget); - m_testDebugAction->setIcon(QIcon(QPixmap(":/testlearn.png"))); + m_testDebugAction->setIcon(QIcon(QPixmap(QLatin1String(":/testlearn.png")))); m_editorRunSingleTestAction = new QAction(widget); - m_editorRunSingleTestAction->setIcon(QIcon(QPixmap(":/testrun.png"))); + m_editorRunSingleTestAction->setIcon(QIcon(QPixmap(QLatin1String(":/testrun.png")))); m_editorRunSingleTestAction->setVisible(false); m_testStopTestingAction = new QAction(widget); - m_testStopTestingAction->setIcon(QIcon(QPixmap(":/teststop.png"))); + m_testStopTestingAction->setIcon(QIcon(QPixmap(QLatin1String(":/teststop.png")))); m_editorStopTestingAction = new QAction(widget); - m_editorStopTestingAction->setIcon(QIcon(QPixmap(":/teststop.png"))); + m_editorStopTestingAction->setIcon(QIcon(QPixmap(QLatin1String(":/teststop.png")))); m_testLearnAction = new QAction(widget); m_testLearnAction->setCheckable(true); @@ -246,7 +251,7 @@ void TestContextMenu_p::updateActions(bool testVisible, bool testBusy, bool test void TestContextMenu_p::enableIncludeFile(const QString &fileName) { m_includeFile = fileName; - m_testOpenIncludeFileAction->setText("Open: '" + fileName + "'"); + m_testOpenIncludeFileAction->setText(tr("Open: '%1'").arg(fileName)); m_testOpenIncludeFileAction->setVisible(!fileName.isEmpty()); } diff --git a/src/plugins/qttest/testcontextmenu.h b/src/plugins/qttest/testcontextmenu.h index 821efa995d9adac9a0a7ea0aa3750429620d1da6..843ab17b778ee8b20871133eccc95734ed39e301 100644 --- a/src/plugins/qttest/testcontextmenu.h +++ b/src/plugins/qttest/testcontextmenu.h @@ -33,19 +33,21 @@ #ifndef TESTCONTEXTMENU_H #define TESTCONTEXTMENU_H -#include "testsuite.h" -#include "testexecuter.h" -#include "testcode.h" -#include "testoutputwindow.h" #include "testsettings.h" #include "extensionsystem/iplugin.h" #include "projectexplorer/projectexplorer.h" #include <QString> -#include <QTreeWidget> -#include <QMenu> -#include <QAction> + +namespace Core { +class IEditor; +} + +QT_BEGIN_NAMESPACE +class QAction; +class QMenu; +QT_END_NAMESPACE class TestContextMenu_p; diff --git a/src/plugins/qttest/testexecuter.cpp b/src/plugins/qttest/testexecuter.cpp index 121dc28f5958c382c6fc504188137d1b7210791d..79722268d0be09ed8cd5e798c0c425b25ed1f578 100644 --- a/src/plugins/qttest/testexecuter.cpp +++ b/src/plugins/qttest/testexecuter.cpp @@ -43,6 +43,7 @@ #include <coreplugin/icore.h> #include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/futureprogress.h> +#include <texteditor/basetexteditor.h> #include <qt4projectmanager/qt4buildconfiguration.h> #include <qtsupport/qtversionmanager.h> #include <projectexplorer/target.h> @@ -89,14 +90,14 @@ TestExecuter::TestExecuter() : m_stopTesting = false; m_manualStop = false; m_killTestRequested = false; - m_testOutputFile = QString("$HOME%1.qttest%1last_test_output").arg(QDir::separator()); + m_testOutputFile = QString::fromLatin1("$HOME%1.qttest%1last_test_output").arg(QDir::separator()); m_pendingFailure = false; m_inBuildMode = false; m_recordingEvents = false; m_abortRecording = false; m_progressBar = 0; m_testResultsStream = 0; - m_peekedResult = ""; + m_peekedResult.clear(); m_executer.setReadChannelMode(QProcess::MergedChannels); m_executer.setReadChannel(QProcess::StandardOutput); @@ -177,7 +178,7 @@ void TestExecuter::runTests(bool singleTest, bool forceManual) m_selectedTests = TestConfigurations::instance().selectedTests(); } if (m_selectedTests.count() == 0) { - testOutputPane()->append("No test selected"); + testOutputPane()->append(tr("No test selected")); endTest(); return; } @@ -197,8 +198,8 @@ void TestExecuter::runSelectedTests(bool forceManual) bool hasSystemTestsSelected = false; int maxProgress = 0; - m_lastFinishedTest = QString(); - QString lastTc = ""; + m_lastFinishedTest.clear(); + QString lastTc; bool lastIsSystemTest = false; // pretend we executed these tests - so the progress bar keeps counting nicely. foreach (const QString &item, m_selectedTests) { @@ -219,22 +220,22 @@ void TestExecuter::runSelectedTests(bool forceManual) m_testCfg = TestConfigurations::instance().activeConfiguration(); if (!m_testCfg) { - testOutputPane()->append("No test configuration defined. This is unusual."); + testOutputPane()->append(tr("No test configuration defined. This is unusual.")); endTest(); return; } m_pendingInsertions.clear(); TestResultsWindow::instance()->clearContents(); - testOutputPane()->append("*********** Start testing *************"); + testOutputPane()->append(tr("*********** Start testing *************")); TestResultsWindow::instance()->popup(); m_curTestCode = 0; QString changeNo; - QString lastConfigName = ""; - QString lastPlatform = ""; - QString lastBranch = ""; + QString lastConfigName; + QString lastPlatform; + QString lastBranch; m_testCfg = 0; m_testFailedUnexpectedly = false; @@ -254,7 +255,7 @@ void TestExecuter::runSelectedTests(bool forceManual) m_progress = 0; m_progressBar->setProgressRange(0, maxProgress); m_progressBar->reportStarted(); - m_progressBar->setProgressValueAndText(0, "Just started"); + m_progressBar->setProgressValueAndText(0, tr("Just started")); m_progressFailCount = 0; m_progressPassCount = 0; @@ -267,15 +268,14 @@ void TestExecuter::runSelectedTests(bool forceManual) // Is this a valid test? if (!m_curTestCode) { - addTestResult("CFAIL", "", "Path '" + m_curTestCode->actualFileName() - + "'doesn't contain a valid testcase"); + addTestResult("CFAIL", QString(), "Path '" + m_curTestCode->actualFileName() + + "' does not contain a valid testcase"); continue; } m_testCfg = TestConfigurations::instance().findConfig(m_curTestCode->actualBasePath()); if (!m_testCfg) { - testOutputPane()->append("Test configuration for '" - + m_curTestCode->actualFileName() + "' not found. Skipping test."); + testOutputPane()->append(tr("Test configuration for '%1' not found. Skipping test.").arg(m_curTestCode->actualFileName())); continue; } @@ -286,7 +286,7 @@ void TestExecuter::runSelectedTests(bool forceManual) uploadResults = m_testCfg->uploadResults(); if (!uploadResults) - testOutputPane()->append("Test results will not be uploaded into the results database."); + testOutputPane()->append(tr("Test results will not be uploaded into the results database.")); QSystem::unsetEnvKey(m_testCfg->buildEnvironment(), "QTEST_COLORED"); QSystem::addEnvPath(m_testCfg->buildEnvironment(), "PATH", m_testCfg->buildPath() + QDir::separator() + "bin"); @@ -295,13 +295,13 @@ void TestExecuter::runSelectedTests(bool forceManual) QRegExp validBranchRegEx(QLatin1String("^(.+)-(.+)")); QRegExp validBranchSpecializationRegEx(QLatin1String(".*")); if (m_testCfg->uploadBranch().isEmpty() || !validBranchRegEx.exactMatch(m_testCfg->uploadBranch())) { - testOutputPane()->append(QString("-- ATTENTION: Uploading of test results failed. No branch specified or branch " + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results failed. No branch specified or branch " "name \"%1\" is not in form: \n\t<Product>-<Version>\n. Check \"Branch\" value in Test Settings.") .arg(m_testCfg->uploadBranch())); uploadResults = false; } else { if (!m_testCfg->uploadBranchSpecialization().isEmpty() && !validBranchSpecializationRegEx.exactMatch(m_testCfg->uploadBranchSpecialization())) { - testOutputPane()->append(QString("-- ATTENTION: Uploading of test results failed. " + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results failed. " "Optional Branch specialization value \"%1\" is not in form: \n\t<Specialization>\n. " "Check \"Branch\" \"Specialization\" value in Test Settings.") .arg(m_testCfg->uploadBranchSpecialization())); @@ -310,21 +310,21 @@ void TestExecuter::runSelectedTests(bool forceManual) lastBranch = m_testCfg->uploadBranch(); if (!m_testCfg->uploadBranchSpecialization().isEmpty()) lastBranch += QLatin1String("-") + m_testCfg->uploadBranchSpecialization(); - testOutputPane()->append("Tested branch: " + lastBranch); + testOutputPane()->append(tr("Tested branch: %1").arg(lastBranch)); } } lastPlatform = m_testCfg->QMAKESPEC(); if (lastPlatform.isEmpty()) { - testOutputPane()->append("-- ATTENTION: Uploading of test results failed. " + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results failed. " "No QMAKESPEC specified. Set QMAKESPEC in project's build environment " - "or set a custom \"QMakespec\" value in Test Settings."); + "or set a custom \"QMakespec\" value in Test Settings.")); uploadResults = false; } else { QRegExp validQmakespecSpecializationRegEx(QLatin1String(".*")); QString lastPlatformSpecialization = m_testCfg->QMAKESPECSpecialization(); if (!lastPlatformSpecialization.isEmpty() && !validQmakespecSpecializationRegEx.exactMatch(lastPlatformSpecialization)) { - testOutputPane()->append(QString("-- ATTENTION: Uploading of test results failed. " + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results failed. " "QMAKESPEC \"Specialization\" \"%1\" not in form: \n\t <Specialization>\n. " "Set the QMAKESPEC specialization value in Test Settings or clear its current value.") .arg(lastPlatformSpecialization)); @@ -332,26 +332,26 @@ void TestExecuter::runSelectedTests(bool forceManual) } else { if (!lastPlatformSpecialization.isEmpty()) lastPlatform += QLatin1String("_") + lastPlatformSpecialization; - testOutputPane()->append("Tested platform: " + lastPlatform); + testOutputPane()->append(tr("Tested platform: %1").arg(lastPlatform)); } } changeNo = m_testCfg->uploadChange(); if (changeNo.isEmpty()) { - testOutputPane()->append("-- ATTENTION: Uploading of test results failed. " - "No changeNumber specified. Set a custom \"Change\" value in Test Settings."); + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results failed. " + "No changeNumber specified. Set a custom \"Change\" value in Test Settings.")); uploadResults = false; } else { - testOutputPane()->append("Testing change: " + changeNo); + testOutputPane()->append(tr("Testing change: %1").arg(changeNo)); } - testOutputPane()->append("Tester: " + QSystem::userName()); - testOutputPane()->append("Host machine: " + sanitizedForFilename(QSystem::hostName())); + testOutputPane()->append(tr("Tester: %1").arg(QSystem::userName())); + testOutputPane()->append(tr("Host machine: ").arg(sanitizedForFilename(QSystem::hostName()))); } } lastConfigName = m_testCfg->configName(); - testOutputPane()->append(""); + testOutputPane()->append(QString()); bool ok = buildTestCase(); if (ok && !m_manualStop) ok = runTestCase(forceManual); @@ -361,7 +361,7 @@ void TestExecuter::runSelectedTests(bool forceManual) m_progressBar->setProgressValue(m_progress); if (testStopped()) { - testOutputPane()->append("-- Testing halted by user"); + testOutputPane()->append(tr("-- Testing halted by user")); } else { m_progressLabel->setText(tr("%1 failed\n%2 passed") .arg(m_progressFailCount).arg(m_progressPassCount)); @@ -372,8 +372,8 @@ void TestExecuter::runSelectedTests(bool forceManual) } } - testOutputPane()->append(""); - testOutputPane()->append("******** All testing finished **********"); + testOutputPane()->append(QString()); + testOutputPane()->append(tr("******** All testing finished **********")); TestResultsWindow::instance()->popup(); @@ -399,10 +399,10 @@ void TestExecuter::endTest() bool TestExecuter::buildTestCase() { - m_syntaxError = ""; + m_syntaxError.clear(); if (!m_testCfg) { - testOutputPane()->append("No test configuration defined: building test case aborted"); + testOutputPane()->append(tr("No test configuration defined: building test case aborted")); return false; } @@ -413,11 +413,11 @@ bool TestExecuter::buildTestCase() QString tgtPath = QDir::convertSeparators(tgtInf.absolutePath()); QDir().mkpath(tgtPath); - testOutputPane()->append("********** Build " + tgtInf.baseName() + " **********"); + testOutputPane()->append(tr("********** Build %1 **********").arg(tgtInf.baseName())); QString proFile = m_curTestCode->projectFileName(); if (proFile.isEmpty()) { - addTestResult("CFAIL", "", "No .pro file found."); + addTestResult("CFAIL", QString(), "No .pro file found."); return false; } m_inBuildMode = true; @@ -426,8 +426,8 @@ bool TestExecuter::buildTestCase() if (ok && m_curTestCode->testType() != TestCode::TypeSystemTest) { if (m_testCfg->makeCommand().isEmpty()) { - testOutputPane()->append("-- No 'make' or 'nmake' instance found in PATH (" - + QSystem::envKey(m_testCfg->buildEnvironment(), "PATH") + ")."); + const QString path = QSystem::envKey(m_testCfg->buildEnvironment(), "PATH"); + testOutputPane()->append(tr("-- No 'make' or 'nmake' instance found in PATH (%1).").arg(path)); return false; } @@ -441,7 +441,7 @@ bool TestExecuter::buildTestCase() bool TestExecuter::postProcess() { if (!m_testCfg) { - testOutputPane()->append("No test configuration defined: post processing results aborted"); + testOutputPane()->append(tr("No test configuration defined: post processing results aborted")); return false; } @@ -455,9 +455,8 @@ bool TestExecuter::postProcess() if (exec(cmd,QStringList())) return true; - addTestResult("FAIL", "", - QString("Could not run postprocess script on Test Case '" - + m_curTestCode->actualFileName() + "'")); + addTestResult("FAIL", QString(), + QString::fromLatin1("Could not run postprocess script on Test Case '%1'").arg(m_curTestCode->actualFileName())); return false; } @@ -465,7 +464,7 @@ bool xmlLineStartsWith(QString &line, const QString &expression, QString &variab { if (line.startsWith(expression)) { variable = line.mid(expression.length()); - variable = variable.left(variable.indexOf("\"")); + variable = variable.left(variable.indexOf(QLatin1Char('"'))); variable = variable.left(variable.indexOf("</")); return !variable.isEmpty(); } @@ -490,7 +489,7 @@ void xmlLineVariable(QString &line, const QString &expression, QString &variable int pos = line.indexOf(expression); if (pos > 0) { variable = line.mid(pos+expression.length()+1); - variable = variable.left(variable.indexOf("\"")); + variable = variable.left(variable.indexOf(QLatin1Char('"'))); } } @@ -510,7 +509,7 @@ QString TestExecuter::readLine() if (m_testResultsStream) { if (!m_peekedResult.isEmpty()) { QString tmp = m_peekedResult; - m_peekedResult = ""; + m_peekedResult.clear(); return tmp; } return m_testResultsStream->readLine(); @@ -525,25 +524,25 @@ QStringList TestExecuter::peek() QStringList tmp; if (!m_peekedResult.isEmpty()) { tmp.append(m_peekedResult); - m_peekedResult = ""; + m_peekedResult.clear(); } while (!m_testResultsStream->atEnd()) { QString line = m_testResultsStream->readLine(); - if (line.startsWith(" ")) { + if (line.startsWith(QLatin1Char(' '))) { tmp.append(line); } else { m_peekedResult = line; return tmp; } } - m_peekedResult = ""; + m_peekedResult.clear(); return tmp; } else { QByteArray data = m_executer.peek(1024); QStringList tmp; - QStringList lines = QString(data).split("\n"); + QStringList lines = QString(data).split(QLatin1Char('\n')); for (int i = 0; i < lines.size(); ++i) { - if (lines[i].startsWith(" ")) + if (lines[i].startsWith(QLatin1Char(' '))) tmp.append(lines[i]); else return tmp; @@ -555,7 +554,7 @@ QStringList TestExecuter::peek() void TestExecuter::parseOutput() { if (!m_testCfg) { - testOutputPane()->append("No test configuration defined: parsing output aborted"); + testOutputPane()->append(tr("No test configuration defined: parsing output aborted")); return; } @@ -570,21 +569,21 @@ void TestExecuter::parseOutput() if (m_inBuildMode) { // Parse build output if (line.contains(" error: ")) { - QString file = line.section(':', 0, 0); + QString file = line.section(QLatin1Char(':'), 0, 0); - int lineNum = line.section(':', 1, 1).toInt(); + int lineNum = line.section(QLatin1Char(':'), 1, 1).toInt(); // The error string will continue across multiple lines so need to peek - QString errorStr = line.section(':', 3); - errorStr.remove('\n'); + QString errorStr = line.section(QLatin1Char(':'), 3); + errorStr.remove(QLatin1Char('\n')); QStringList lines = peek(); for (int i = 0; i < lines.size(); ++i) - errorStr.append(" " + lines[i].trimmed()); + errorStr.append(QLatin1Char(' ') + lines[i].trimmed()); - addTestResult("CFAIL", "", errorStr, file, lineNum); + addTestResult("CFAIL", QString(), errorStr, file, lineNum); } else { if (!m_testSettings.showVerbose()) { - QStringList tmp = line.split(" "); + QStringList tmp = line.split(QLatin1Char(' ')); if (tmp.count() > 0) { QString cmd = tmp[0]; if (cmd.contains("moc")) { @@ -596,7 +595,7 @@ void TestExecuter::parseOutput() } else if (tmp.contains("-o")) { int pos = tmp.indexOf("-o"); if (pos > 0 && (pos < tmp.count()-2)) { - line = cmd + " " + tmp[pos+1].split(QDir::separator()).last(); + line = cmd + QLatin1Char(' ') + tmp[pos+1].split(QDir::separator()).last(); } } } @@ -606,15 +605,15 @@ void TestExecuter::parseOutput() } else { if (m_xmlMode) { if (line.startsWith("<?xml version")) { - m_xmlTestfunction = ""; - m_xmlTestcase = ""; - m_xmlDatatag = ""; - m_xmlFile = ""; + m_xmlTestfunction.clear(); + m_xmlTestcase.clear(); + m_xmlDatatag.clear(); + m_xmlFile.clear(); m_xmlLine = "-1"; - m_xmlResult = ""; - m_xmlDescription = ""; - m_xmlQtVersion = ""; - m_xmlQtestVersion = ""; + m_xmlResult.clear(); + m_xmlDescription.clear(); + m_xmlQtVersion.clear(); + m_xmlQtestVersion.clear(); m_xmlLog.clear(); continue; } @@ -626,32 +625,32 @@ void TestExecuter::parseOutput() line = m_xmlResult.toUpper(); if (line == "FAIL") - line += "!"; + line += QLatin1Char('!'); while (line.length() < 7) - line += " "; + line += QLatin1Char(' '); QString testDescriptor = m_xmlTestcase + "::" - + m_xmlTestfunction + "("+m_xmlDatatag+")"; + + m_xmlTestfunction + QLatin1Char('(')+m_xmlDatatag+QLatin1Char(')'); line += ": " + testDescriptor + m_xmlDescription; if (!m_xmlFile.isEmpty()) - line += "\nLoc: [" + m_xmlFile + "(" + m_xmlLine + ")]"; + line += "\nLoc: [" + m_xmlFile + QLatin1Char('(') + m_xmlLine + ")]"; if (m_curTestCode->testType() != TestCode::TypeSystemTest) { if (m_xmlResult.contains("fail") || m_xmlResult.contains("pass")) { - addTestResult(m_xmlResult.toUpper(), "", + addTestResult(m_xmlResult.toUpper(), QString(), testDescriptor + m_xmlDescription, m_xmlFile, m_xmlLine.toInt(), m_xmlDatatag); } } } - m_xmlResult = ""; - m_xmlDescription = ""; + m_xmlResult.clear(); + m_xmlDescription.clear(); } else if (xmlLineCData(line, "<Description>", m_xmlDescription)) { if (!m_xmlDescription.isEmpty()) - m_xmlDescription = "\n" + m_xmlDescription; + m_xmlDescription = QLatin1Char('\n') + m_xmlDescription; continue; } else if (xmlLineCData(line, "<DataTag>", m_xmlDatatag)) { @@ -677,30 +676,30 @@ void TestExecuter::parseOutput() if (line.endsWith("/>")) { line = m_xmlResult.toUpper(); while (line.length() < 7) - line += " "; + line += QLatin1Char(' '); QString testDescriptor = m_xmlTestcase + "::" - + m_xmlTestfunction + "("+m_xmlDatatag+")"; + + m_xmlTestfunction + QLatin1Char('(')+m_xmlDatatag+QLatin1Char(')'); line += ": " + testDescriptor + m_xmlDescription; if (!m_xmlFile.isEmpty()) - line += "\nLoc: [" + m_xmlFile + "(" + m_xmlLine + ")]"; + line += "\nLoc: [" + m_xmlFile + QLatin1Char('(') + m_xmlLine + ")]"; if (m_curTestCode->testType() != TestCode::TypeSystemTest) { if (m_xmlResult.contains("fail") || m_xmlResult.contains("pass")) { - addTestResult(m_xmlResult.toUpper(), "", testDescriptor + addTestResult(m_xmlResult.toUpper(), QString(), testDescriptor + m_xmlDescription, m_xmlFile, m_xmlLine.toInt(), m_xmlDatatag); } } } } else if (line == "</TestFunction>") { - m_xmlTestfunction = ""; - m_xmlDatatag = ""; + m_xmlTestfunction.clear(); + m_xmlDatatag.clear(); continue; } else if (line == "</TestCase>") { line = "********* Finished testing of " + m_xmlTestcase + " *********"; - m_xmlTestcase = ""; + m_xmlTestcase.clear(); // In case the testcase hangs at the end, we need a mechanism // to terminate the process. So set a timer that will kill the // executer if we haven't heard anything for 1.5 seconds. @@ -723,12 +722,12 @@ void TestExecuter::parseOutput() continue; } else if (line.startsWith("<anonymous>()@")) { - m_xmlFile = line.mid(line.indexOf("@")+1); - m_xmlLine = m_xmlFile.mid(m_xmlFile.indexOf(":")+1); - m_xmlFile = m_xmlFile.left(m_xmlFile.indexOf(":")); + m_xmlFile = line.mid(line.indexOf(QLatin1Char('@'))+1); + m_xmlLine = m_xmlFile.mid(m_xmlFile.indexOf(QLatin1Char(':'))+1); + m_xmlFile = m_xmlFile.left(m_xmlFile.indexOf(QLatin1Char(':'))); if (!m_syntaxError.isEmpty()) { - addTestResult("CFAIL", "", m_syntaxError, m_xmlFile, m_xmlLine.toInt()); - m_syntaxError = ""; + addTestResult("CFAIL", QString(), m_syntaxError, m_xmlFile, m_xmlLine.toInt()); + m_syntaxError.clear(); } } } @@ -749,7 +748,7 @@ void TestExecuter::parseOutput() int i = 0; while (i < filter.count()) { if (line.contains(filter[i])) { - line = ""; + line.clear(); break; } ++i; @@ -769,7 +768,7 @@ void TestExecuter::onKillTestRequested() bool TestExecuter::exec(const QString &cmd, const QStringList &arguments, const QString &workDir, int timeout) { if (!m_testCfg) { - testOutputPane()->append("No test configuration defined: exec aborted"); + testOutputPane()->append(tr("No test configuration defined: exec aborted")); return false; } @@ -780,7 +779,7 @@ bool TestExecuter::exec(const QString &cmd, const QStringList &arguments, const } Q_ASSERT(m_executer.state() == QProcess::NotRunning); - if ((workDir != "") && (m_executer.workingDirectory() != workDir)) { + if ((!workDir.isEmpty()) && (m_executer.workingDirectory() != workDir)) { if (m_inBuildMode) testOutputPane()->append("cd " + workDir); m_executer.setWorkingDirectory(workDir); @@ -788,7 +787,7 @@ bool TestExecuter::exec(const QString &cmd, const QStringList &arguments, const m_executer.setEnvironment(*m_testCfg->buildEnvironment()); if (m_inBuildMode) - testOutputPane()->append(cmd + " " + arguments.join(" ")); + testOutputPane()->append(cmd + QLatin1Char(' ') + arguments.join(QString(QLatin1Char(' ')))); m_executerFinished = false; if (arguments.count() > 0) { @@ -799,8 +798,8 @@ bool TestExecuter::exec(const QString &cmd, const QStringList &arguments, const realCmd = cmd; if (realCmd.isEmpty()) { - testOutputPane()->append("-- No '" + cmd + "' instance found in PATH (" - + QSystem::envKey(m_testCfg->buildEnvironment(), "PATH") + ")."); + const QString path = QSystem::envKey(m_testCfg->buildEnvironment(), "PATH"); + testOutputPane()->append(tr("-- No '%1' instance found in PATH (%2) + ).").arg(cmd, path)); return false; } m_executer.start(realCmd, arguments); @@ -821,7 +820,7 @@ bool TestExecuter::exec(const QString &cmd, const QStringList &arguments, const return m_executer.exitCode() == 0; } else { testOutputPane()->append(QString(tr("-- %1 failed: %2, time elapsed: %3")) - .arg(cmd).arg(m_executer.errorString()).arg(time.elapsed())); + .arg(cmd, m_executer.errorString()).arg(time.elapsed())); return false; } } @@ -834,7 +833,7 @@ void TestExecuter::onExecuterFinished() bool TestExecuter::runTestCase(bool forceManual) { if (!m_testCfg) { - testOutputPane()->append("No test configuration defined: running test case aborted"); + testOutputPane()->append(tr("No test configuration defined: running test case aborted")); return false; } @@ -845,21 +844,21 @@ bool TestExecuter::runTestCase(bool forceManual) uint timeout = 30000; if (m_curTestCode->testType() == TestCode::TypeSystemTest) { - QString m_testPlatform = ""; - if (m_testCfg->uploadPlatform().toLower().contains("windows")) - m_testPlatform = "win"; - else if (m_testCfg->uploadPlatform().toLower().contains("mac")) - m_testPlatform = "mac"; - else if (m_testCfg->uploadPlatform().toLower().contains("linux")) - m_testPlatform = "linux"; + QString m_testPlatform; + if (m_testCfg->uploadPlatform().toLower().contains(QLatin1String("windows"))) + m_testPlatform = QLatin1String("win"); + else if (m_testCfg->uploadPlatform().toLower().contains(QLatin1String("mac"))) + m_testPlatform = QLatin1String("mac"); + else if (m_testCfg->uploadPlatform().toLower().contains(QLatin1String("linux"))) + m_testPlatform = QLatin1String("linux"); else - m_testPlatform = "symbian"; + m_testPlatform = QLatin1String("symbian"); - QSystem::setEnvKey(&env, "TESTPLATFORM", m_testPlatform); - args << "-env TESTPLATFORM=" + m_testPlatform; + QSystem::setEnvKey(&env, QLatin1String("TESTPLATFORM"), m_testPlatform); + args << QLatin1String("-env TESTPLATFORM=") + m_testPlatform; if (forceManual) - args << "-force-manual"; + args << QLatin1String("-force-manual"); QString deviceName; QString deviceType; @@ -867,31 +866,31 @@ bool TestExecuter::runTestCase(bool forceManual) m_testCfg->isRemoteTarget(deviceName, deviceType, sshParam); QVariantMap connectionParam; - connectionParam["host"] = sshParam.host; - connectionParam["username"] = sshParam.userName; - connectionParam["sshPort"] = sshParam.port; - connectionParam["sshTimeout"] = sshParam.timeout; + connectionParam[QLatin1String("host")] = sshParam.host; + connectionParam[QLatin1String("username")] = sshParam.userName; + connectionParam[QLatin1String("sshPort")] = sshParam.port; + connectionParam[QLatin1String("sshTimeout")] = sshParam.timeout; if (sshParam.authenticationType == Utils::SshConnectionParameters::AuthenticationByPassword) { - connectionParam["password"] = sshParam.password; + connectionParam[QLatin1String("password")] = sshParam.password; } else { - connectionParam["privateKeyFile"] = sshParam.privateKeyFile; + connectionParam[QLatin1String("privateKeyFile")] = sshParam.privateKeyFile; } #ifndef QTTEST_PLUGIN_LEAN m_qscriptSystemTest.setConnectionParameters(deviceType, sshParam); #else - args << "-authost" << sshParam.host; - args << "-username" << sshParam.userName; + args << QLatin1String("-authost") << sshParam.host; + args << QLatin1String("-username") << sshParam.userName; if (sshParam.authenticationType == Utils::SshConnectionParameters::AuthenticationByPassword) { - args << "-pwd" << sshParam.password; + args << QLatin1String("-pwd") << sshParam.password; } else { - args << "-private-key" << sshParam.privateKeyFile; + args << QLatin1String("-private-key") << sshParam.privateKeyFile; } #endif timeout = 600000; // 10 minutes to run a manual test should be sufficient? - cmd = "qtuitestrunner"; + cmd = QLatin1String("qtuitestrunner"); } else { QFileInfo tmp(m_curTestCode->actualFileName()); QString testRelPath = QDir::convertSeparators(tmp.absolutePath()); @@ -899,10 +898,9 @@ bool TestExecuter::runTestCase(bool forceManual) QString exePath; QString exeFile = m_curTestCode->execFileName(); if (exeFile.isEmpty()) { - testOutputPane()->append("Unknown executable name for Test Case '" - + m_curTestCode->testCase() + "'"); - addTestResult("FAIL", "", - QString("Unknown executable name for Test Case '" + m_curTestCode->testCase() + "'")); + testOutputPane()->append(tr("Unknown executable name for Test Case '%1'").arg(m_curTestCode->testCase())); + addTestResult(QLatin1String("FAIL"), QString(), + QString("Unknown executable name for Test Case '" + m_curTestCode->testCase() + QLatin1Char('\''))); return false; } @@ -910,55 +908,55 @@ bool TestExecuter::runTestCase(bool forceManual) exePath1 += testRelPath; #ifdef Q_OS_MAC - exePath1 += "/" + tmp.baseName() + ".app/Contents/MacOS"; + exePath1 += QLatin1Char('/') + tmp.baseName() + QLatin1String(".app/Contents/MacOS"); #endif exePath = QSystem::which(exePath1, exeFile); QString exePath2, exePath3, exePath4; if (exePath.isEmpty()) { exePath3 = m_testCfg->buildPath(); - exePath3 += QString("%1bin").arg(QDir::separator()); + exePath3 += QDir::separator() + QLatin1String("bin"); exePath = QSystem::which(exePath3, exeFile); if (exePath.isEmpty()) { exePath4 = m_testCfg->buildPath(); - exePath4 += QString("%1build%1tests%1bin").arg(QDir::separator()); + exePath4 += QString::fromLatin1("%1build%1tests%1bin").arg(QDir::separator()); exePath = QSystem::which(exePath4, exeFile); if (exePath.isEmpty()) { - exePath2 = QString("%1%2debug").arg(exePath1).arg(QDir::separator()); + exePath2 = QString::fromLatin1("%1%2debug").arg(exePath1).arg(QDir::separator()); exePath = QSystem::which(exePath2, exeFile); } } } if (exePath.isEmpty()) { - testOutputPane()->append("Test Case '" + exeFile + "' not found"); - addTestResult("FAIL", "", - QString("Test Case '" + exeFile + "' not found in:\n - '" + exePath1 - + "' or \n - '" + exePath2 + "' or \n - '" + exePath3 - + "' or \n - '" + exePath4 + "'.")); + testOutputPane()->append(tr("Test Case '%1' not found").arg(exeFile)); + addTestResult(QLatin1String("FAIL"), QString(), + QLatin1String("Test Case '") + exeFile + QLatin1String("' not found in:\n - '") + exePath1 + + QLatin1String("' or \n - '") + exePath2 + QLatin1String("' or \n - '") + exePath3 + + QLatin1String("' or \n - '") + exePath4 + QLatin1String("'.")); return false; } cmd = exePath; } - args << "-xml"; + args << QLatin1String("-xml"); if (m_testSettings.learnMode() == 1) - args << "-learn"; + args << QLatin1String("-learn"); else if (m_testSettings.learnMode() == 2) - args << "-learn-all"; + args << QLatin1String("-learn-all"); // Grab a list of all the functions we want to execute bool hasTests = false; foreach (const QString &item, m_selectedTests) { - if (item.startsWith(m_curTestCode->testCase() + "::")) { - QString func = item.mid(item.indexOf("::")+2); - if ((func != "init") && (func != "initTestCase") && (func != "cleanup") - && (func != "cleanupTestCase") && !func.endsWith("_data")) { + if (item.startsWith(m_curTestCode->testCase() + QLatin1String("::"))) { + QString func = item.mid(item.indexOf(QLatin1String("::"))+2); + if ((func != QLatin1String("init")) && (func != QLatin1String("initTestCase")) && (func != QLatin1String("cleanup")) + && (func != QLatin1String("cleanupTestCase")) && !func.endsWith(QLatin1String("_data"))) { args << func; hasTests = true; } @@ -971,16 +969,16 @@ bool TestExecuter::runTestCase(bool forceManual) // If we have a postprocessing step, pipe output to a file if (!m_testCfg->postProcessScript().isEmpty()) - cmd.append(" | tee " + m_testOutputFile); + cmd.append(QLatin1String(" | tee ") + m_testOutputFile); #ifndef Q_OS_WIN - QString libPath = QSystem::envKey(m_testCfg->buildEnvironment(), "QTDIR"); + QString libPath = QSystem::envKey(m_testCfg->buildEnvironment(), QLatin1String("QTDIR")); if (!libPath.isEmpty()) { - libPath = libPath + QDir::separator() + "lib"; + libPath = libPath + QDir::separator() + QLatin1String("lib"); # ifdef Q_OS_MAC - QSystem::addEnvPath(m_testCfg->buildEnvironment(), "DYLD_LIBRARY_PATH", libPath); + QSystem::addEnvPath(m_testCfg->buildEnvironment(), QLatin1String("DYLD_LIBRARY_PATH"), libPath); # else - QSystem::addEnvPath(m_testCfg->buildEnvironment(), "LD_LIBRARY_PATH", libPath); + QSystem::addEnvPath(m_testCfg->buildEnvironment(), QLatin1String("LD_LIBRARY_PATH"), libPath); # endif } #endif @@ -990,10 +988,10 @@ bool TestExecuter::runTestCase(bool forceManual) if (m_curTestCode->hasUnsavedChanges()) { QMessageBox msgBox; msgBox.setText(tr("Unsaved Changes")); - msgBox.setInformativeText(QString(tr("File '%1' has unsaved changes.\nThe file must be saved before proceeding.")) + msgBox.setInformativeText(tr("File '%1' has unsaved changes.\nThe file must be saved before proceeding.") .arg(m_curTestCode->baseFileName())); if (QMessageBox::warning(0, tr("Unsaved Changes"), - QString("File \"%1\" has unsaved changes.\n" + tr("File \"%1\" has unsaved changes.\n" "The file must be saved before proceeding.").arg(m_curTestCode->baseFileName()), QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Save) == QMessageBox::Save) { m_curTestCode->save(); @@ -1003,34 +1001,34 @@ bool TestExecuter::runTestCase(bool forceManual) } if (!cancel) { QString testOutput; - testOutputPane()->append(QString("********* Start testing of %1 *********") + testOutputPane()->append(tr("********* Start testing of %1 *********") .arg(m_curTestCode->baseFileName())); args.prepend(m_curTestCode->actualFileName()); - testOutputPane()->append(QString("%1 %2").arg(cmd).arg(args.join(" "))); + testOutputPane()->append(QString::fromLatin1("%1 %2").arg(cmd).arg(args.join(QString(QLatin1Char(' '))))); if (exec(cmd, args, m_testCfg->buildPath(), timeout)) return true; - testOutputPane()->append(QString("********* Finished testing of %1 *********") + testOutputPane()->append(tr("********* Finished testing of %1 *********") .arg(m_curTestCode->baseFileName())); #ifndef QTTEST_PLUGIN_LEAN m_qscriptSystemTest.runTest(m_curTestCode->actualFileName(), args, env, &testOutput); if (qscript_system_test.isAborted()) { - testOutputPane()->append(QString("********* Aborted testing of %1 *********") + testOutputPane()->append(tr("********* Aborted testing of %1 *********") .arg(m_curTestCode->baseFileName())); if (!m_manualStop) manualStop(); } else { - testOutputPane()->append(QString("********* Finished testing of %1 *********") + testOutputPane()->append(tr("********* Finished testing of %1 *********") .arg(m_curTestCode->baseFileName())); } #endif - m_xmlLog = testOutput.split("\n"); + m_xmlLog = testOutput.split(QLatin1Char('\n')); m_xmlLog.removeAll(QString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>")); } else { addTestResult("FAIL", m_curTestCode->testCase(), - QString("Execution cancelled for Test Case '%1'").arg(m_curTestCode->testCase())); + QString::fromLatin1("Execution cancelled for Test Case '%1'").arg(m_curTestCode->testCase())); return false; } } else { @@ -1044,9 +1042,9 @@ bool TestExecuter::runTestCase(bool forceManual) if (m_executer.exitCode() >= 0) return true; - addTestResult("FAIL", m_curTestCode->testCase(), - QString("Execution failed for Test Case '%1' with exit code '%2': %3") - .arg(m_curTestCode->testCase() + "'") + addTestResult(QLatin1String("FAIL"), m_curTestCode->testCase(), + QString::fromLatin1("Execution failed for Test Case '%1' with exit code '%2': %3") + .arg(m_curTestCode->testCase() + QLatin1Char('\'')) .arg(m_executer.exitCode()) .arg(m_executer.errorString())); return false; @@ -1060,12 +1058,12 @@ bool TestExecuter::testFailedUnexpectedly() void TestExecuter::addTestResult(const QString &result, const QString &test, const QString &reason, const QString &file, int line, const QString &dataTag) { - if (result.contains("FAIL")) { - if (!result.contains("XFAIL")) + if (result.contains(QLatin1String("FAIL"))) { + if (!result.contains(QLatin1String("XFAIL"))) m_testFailedUnexpectedly = true; ++m_progressFailCount; - } else if (result.contains("PASS")) { - if (reason.contains("::initTestCase()") || reason.contains("::cleanupTestCase()")) + } else if (result.contains(QLatin1String("PASS"))) { + if (reason.contains(QLatin1String("::initTestCase()")) || reason.contains(QLatin1String("::cleanupTestCase()"))) return; ++m_progressPassCount; } @@ -1086,13 +1084,13 @@ void TestExecuter::addTestResult(const QString &result, const QString &test, con bool TestExecuter::getNextTest() { - QString curTestName = ""; + QString curTestName; if (m_curTestCode) curTestName = m_curTestCode->testCase(); if (m_selectedTests.count() > 0) { if (curTestName.isEmpty()) { - curTestName = m_selectedTests[0].left(m_selectedTests[0].indexOf("::")); + curTestName = m_selectedTests[0].left(m_selectedTests[0].indexOf(QLatin1String("::"))); if (!curTestName.isEmpty()) { m_curTestCode = m_testCollection.findCodeByTestCaseName(curTestName); return (m_curTestCode != 0); @@ -1100,14 +1098,14 @@ bool TestExecuter::getNextTest() } bool tcFound = false; - QString tcName = curTestName + "::"; + QString tcName = curTestName + QLatin1String("::"); foreach (const QString &item, m_selectedTests) { if (!tcFound) { if (item.startsWith(tcName)) tcFound = true; } else { if (!item.startsWith(tcName)) { - curTestName = item.left(item.indexOf("::")); + curTestName = item.left(item.indexOf(QLatin1String("::"))); if (!curTestName.isEmpty()) { m_curTestCode = m_testCollection.findCodeByTestCaseName(curTestName); return m_curTestCode != 0; @@ -1126,18 +1124,18 @@ bool TestExecuter::testBusy() const QString TestExecuter::saveResults(const QString &changeNo, const QString &platform, const QString &branch) { - QString fname = QDir::homePath() + QDir::separator() + ".qttest" - + QDir::separator() + "pending_test_results"; + QString fname = QDir::homePath() + QDir::separator() + QLatin1String(".qttest") + + QDir::separator() + QLatin1String("pending_test_results"); QDir().mkpath(fname); fname += QDir::separator(); - fname += "creator_upload_USER_"; + fname += QLatin1String("creator_upload_USER_"); fname += sanitizedForFilename(QSystem::userName()); - fname += "_HOST_"; + fname += QLatin1String("_HOST_"); fname += sanitizedForFilename(QSystem::hostName()); - fname += "_ON_"; + fname += QLatin1String("_ON_"); fname += sanitizedForFilename(QDateTime::currentDateTime().toString()); - fname += ".xml"; + fname += QLatin1String(".xml"); QFile xmlFile(fname); xmlFile.remove(); @@ -1146,23 +1144,23 @@ QString TestExecuter::saveResults(const QString &changeNo, const QString &platfo if (xmlFile.open(QIODevice::WriteOnly | QIODevice::Append)) { QTextStream xml_stream(&xmlFile); xml_stream << testrHeader(changeNo, platform, branch); - xml_stream << "\n"; + xml_stream << '\n'; xml_stream << QString("\n<!-- file 1 of 1: filename -->\n"); - xml_stream << m_xmlLog.join("\n"); - xml_stream << "\n"; + xml_stream << m_xmlLog.join(QString(QLatin1Char('\n'))); + xml_stream << '\n'; xml_stream << testrFooter(); xmlFile.close(); return fname; } } - return ""; + return QString(); } QString TestExecuter::sanitizedForFilename(const QString &in) const { QString out = in; - static const QRegExp replaceRx("[^a-zA-Z0-9\\-_\\.]"); - out.replace(replaceRx, "_"); + static const QRegExp replaceRx(QLatin1String("[^a-zA-Z0-9\\-_\\.]")); + out.replace(replaceRx, QString(QLatin1Char('_'))); return out; } @@ -1223,8 +1221,7 @@ void TestExecuter::syntaxError(const QString &msg, const QString &file, int line tmp->gotoLine(line); } QFileInfo fi(file); - QString message(QString(tr("Syntax error in %1, near line %2.\n%3")) - .arg(fi.fileName()).arg(line).arg(msg)); + const QString message = tr("Syntax error in %1, near line %2.\n%3").arg(fi.fileName()).arg(line).arg(msg); QMessageBox::critical(0, tr("System Test Failure"), message); } @@ -1316,9 +1313,9 @@ void TestExecuter::applyPendingInsertions() if (editable) { QString insertCode = "//BEGIN Recorded Events"; int column = editable->currentColumn(); - QStringList recordedLines = recordedCode.split('\n'); + QStringList recordedLines = recordedCode.split(QLatin1Char('\n')); QString indent(QString(' ').repeated(column-1)); - indent.prepend("\n"); + indent.prepend(QLatin1Char('\n')); foreach (const QString &line, recordedLines) { insertCode.append(indent); insertCode.append(line); diff --git a/src/plugins/qttest/testexecuter.h b/src/plugins/qttest/testexecuter.h index 169f7cb0ccff9cadd8d7a0b4e6fdda3350c7878d..8b891d02058a35b85be881e1e3fcc8a5a0a95b6c 100644 --- a/src/plugins/qttest/testexecuter.h +++ b/src/plugins/qttest/testexecuter.h @@ -46,10 +46,7 @@ #endif #include <QtCore/QFutureWatcher> -#include <QObject> -#include <QTimer> #include <QProcess> -#include <QLabel> #define NO_X_SERVER_AVAILABLE "No X-server available for testing" #define COMPILE_ERROR "Compile error" @@ -58,6 +55,11 @@ #define COMPILE_UP_TO_DATE "Not recompiled, binary is up-to-date" #define SELF_TEST "self-test" +QT_BEGIN_NAMESPACE +class QTextEdit; +class QLabel; +QT_END_NAMESPACE + class TestExecuter : public QObject { Q_OBJECT diff --git a/src/plugins/qttest/testgenerator.cpp b/src/plugins/qttest/testgenerator.cpp index c2987b2032b32924226408992548d047dde104c2..e3d34423eacae798d2b1595f7b10b2783e1a6e3e 100644 --- a/src/plugins/qttest/testgenerator.cpp +++ b/src/plugins/qttest/testgenerator.cpp @@ -45,7 +45,6 @@ TestGenerator::TestGenerator() { - m_generatedFilename = ""; m_initialized = false; m_enableComponentNamedTest = true; } @@ -65,7 +64,7 @@ bool TestGenerator::generateProFile() if (m_genMode != SystemTest) { src << "load(testcase)\n"; - src << "TARGET = " << m_testCase.toLower() << "\n"; + src << "TARGET = " << m_testCase.toLower() << '\n'; src << "QT += testlib\n"; src << "SOURCES = " << m_testCase.toLower() << ".cpp\n"; } else if (m_genMode == SystemTest) { @@ -143,80 +142,80 @@ void TestGenerator::initSrc(QTextStream *s) *s << crfileStream.readAll(); } - *s << "\n"; - *s << "//TESTED_COMPONENT=" << m_testedComponent << "\n"; - *s << "//TESTED_CLASS=" << m_testedClass << "\n"; - *s << "//TESTED_FILE=" << m_includeFile << "\n"; - *s << "\n"; + *s << '\n'; + *s << "//TESTED_COMPONENT=" << m_testedComponent << '\n'; + *s << "//TESTED_CLASS=" << m_testedClass << '\n'; + *s << "//TESTED_FILE=" << m_includeFile << '\n'; + *s << '\n'; *s << "#include <QtTest/QtTest>\n"; - if (m_includeFile != "") + if (!m_includeFile.isEmpty()) *s << "#include \"" << m_includeFile << "\"\n"; - *s << "\n"; + *s << '\n'; *s << "/*!\n"; *s << " \\internal\n"; - *s << "\n"; - *s << " \\class " << m_testCase << "\n"; + *s << '\n'; + *s << " \\class " << m_testCase << '\n'; *s << " \\brief <put brief description here>\n"; - *s << "\n"; + *s << '\n'; *s << " <put extended description here>\n"; - *s << "\n"; + *s << '\n'; if (m_testedClass.isEmpty()) *s << " \\sa " << "<tested class name>\n"; else - *s << " \\sa " << m_testedClass << "\n"; + *s << " \\sa " << m_testedClass << '\n'; *s << "*/\n"; *s << "class " << m_testCase << " : public QObject\n"; *s << "{\n"; *s << " Q_OBJECT\n"; - *s << "\n"; + *s << '\n'; *s << "public:\n"; *s << " " << m_testCase << "();\n"; *s << " virtual ~" << m_testCase << "();\n"; - *s << "\n"; + *s << '\n'; *s << "private slots:\n"; *s << " virtual void initTestCase();\n"; *s << " virtual void init();\n"; *s << " virtual void cleanup();\n"; *s << " virtual void cleanupTestCase();\n"; *s << "};\n"; - *s << "\n"; + *s << '\n'; *s << "QTEST_MAIN(" << m_testCase << ")\n"; - *s << "#include " << '"' << m_testCase.toLower() << ".moc" << '"' << "\n"; - *s << "\n"; - *s << "\n"; + *s << "#include " << '"' << m_testCase.toLower() << ".moc" << '"' << '\n'; + *s << '\n'; + *s << '\n'; *s << m_testCase << "::" << m_testCase << "()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; + *s << '\n'; *s << m_testCase << "::~" << m_testCase << "()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; + *s << '\n'; *s << "void " << m_testCase << "::initTestCase()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; + *s << '\n'; *s << "void " << m_testCase << "::init()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; + *s << '\n'; *s << "void " << m_testCase << "::cleanup()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; + *s << '\n'; *s << "void " << m_testCase << "::cleanupTestCase()\n"; *s << "{\n"; *s << "}\n"; - *s << "\n"; - *s << "\n"; + *s << '\n'; + *s << '\n'; } void TestGenerator::initScript(QTextStream *s) @@ -234,29 +233,29 @@ void TestGenerator::initScript(QTextStream *s) *s << crfileStream.readAll(); } - *s << "\n"; - *s << "//TESTED_COMPONENT=" << m_testedComponent << "\n"; - *s << "\n"; + *s << '\n'; + *s << "//TESTED_COMPONENT=" << m_testedComponent << '\n'; + *s << '\n'; *s << "testcase = {\n"; *s << " initTestCase: function()\n"; *s << " {\n"; *s << " },\n"; - *s << "\n"; + *s << '\n'; *s << " init: function()\n"; *s << " {\n"; *s << " },\n"; - *s << "\n"; + *s << '\n'; *s << " cleanup: function()\n"; *s << " {\n"; *s << " },\n"; - *s << "\n"; + *s << '\n'; *s << " cleanupTestCase: function()\n"; *s << " {\n"; *s << " },\n"; - *s << "\n"; - *s << "\n"; + *s << '\n'; + *s << '\n'; *s << "} // end of testcase\n"; - *s << "\n"; + *s << '\n'; } void TestGenerator::setTestCase(GenMode mode, const QString &rootDir, const QString &testDir, @@ -265,12 +264,12 @@ void TestGenerator::setTestCase(GenMode mode, const QString &rootDir, const QStr { Q_UNUSED(testedClassFile); QString testCaseNameSuffix; - m_generatedFilename = ""; + m_generatedFilename.clear(); m_genMode = mode; m_testedClass = testedClassName; m_testedComponent = testedComponent; - m_includeFile = ""; + m_includeFile.clear(); m_testCase = testCase; m_rootDir = rootDir; diff --git a/src/plugins/qttest/testgenerator.h b/src/plugins/qttest/testgenerator.h index 0895a57f4b62624d3535b907a47f44f6a5cb285f..c18427b68b5abdc0eff55e9315bc26f4f7e4908b 100644 --- a/src/plugins/qttest/testgenerator.h +++ b/src/plugins/qttest/testgenerator.h @@ -34,8 +34,8 @@ #define TESTGENERATOR_H #include <QString> -#include <QTextStream> -#include <QStringList> + +QT_FORWARD_DECLARE_CLASS(QTextStream) class TestGenerator { diff --git a/src/plugins/qttest/testoutputwindow.cpp b/src/plugins/qttest/testoutputwindow.cpp index 2e29e57d76094de143a82bee301008fa35ab416f..f089b1a645710d633990c55f0de4d75adff008ff 100644 --- a/src/plugins/qttest/testoutputwindow.cpp +++ b/src/plugins/qttest/testoutputwindow.cpp @@ -44,9 +44,8 @@ QTextEdit *testOutputPane() return 0; } -TestOutputWindow::TestOutputWindow() +TestOutputWindow::TestOutputWindow() : m_widget(new QTextEdit) { - m_widget = new QTextEdit; m_widget->setReadOnly(true); m_widget->setFrameStyle(QFrame::NoFrame); m_instance = this; diff --git a/src/plugins/qttest/testoutputwindow.h b/src/plugins/qttest/testoutputwindow.h index 8aae8a73913500374ef29ad474171a8ba5a42118..e988fdfb74deea8536b4f5d5f21a146fe4c65c14 100644 --- a/src/plugins/qttest/testoutputwindow.h +++ b/src/plugins/qttest/testoutputwindow.h @@ -34,7 +34,8 @@ #define TESTOUTPUTWINDOW_H #include <coreplugin/ioutputpane.h> -#include <QTextEdit> + +QT_FORWARD_DECLARE_CLASS(QTextEdit) QTextEdit *testOutputPane(); diff --git a/src/plugins/qttest/testresultuploader.cpp b/src/plugins/qttest/testresultuploader.cpp index 0bcb909121df614d388a89de478c19a743388648..2d335c2989bcd256548c052c59832bbd4dd9e809 100644 --- a/src/plugins/qttest/testresultuploader.cpp +++ b/src/plugins/qttest/testresultuploader.cpp @@ -32,8 +32,10 @@ #include "testresultuploader.h" #include "testoutputwindow.h" +#include "qsystem.h" #include <QFileInfo> +#include <QTextEdit> TestResultUploader::TestResultUploader(QObject *parent) : QObject(parent) @@ -66,19 +68,19 @@ void TestResultUploader::uploadResultsToDatabase(const QString &fname, TestConfi m_srcFname = fname; if (!fname.isEmpty()) { - m_logFile.setFileName(QDir::homePath() + QDir::separator() + ".qttest" - + QDir::separator() + "test_result_upload.log"); + m_logFile.setFileName(QDir::homePath() + QDir::separator() + QLatin1String(".qttest") + + QDir::separator() + QLatin1String("test_result_upload.log")); m_logFile.open(QFile::WriteOnly); if (m_testSettings.uploadServer().isEmpty()) { - testOutputPane()->append("-- ATTENTION: Uploading of test results to the database aborted. " - "Please specify an upload server in the Upload Test Results Settings dialog."); + testOutputPane()->append(tr("-- ATTENTION: Uploading of test results to the database aborted. " + "Please specify an upload server in the Upload Test Results Settings dialog.")); return; } m_uploadServerName = m_testSettings.uploadServer(); - int pos = m_uploadServerName.indexOf(":"); + int pos = m_uploadServerName.indexOf(QLatin1Char(':')); if (pos) m_uploadServerName = m_uploadServerName.left(pos); @@ -87,10 +89,10 @@ void TestResultUploader::uploadResultsToDatabase(const QString &fname, TestConfi return; m_tgtFname = inf.fileName(); - QString cmd1 = QSystem::which(m_testCfg->PATH(), "scp"); + QString cmd1 = QSystem::which(m_testCfg->PATH(), QLatin1String("scp")); QStringList args1; - args1 << fname << QString("%1:/tmp/%2").arg(m_uploadServerName).arg(m_tgtFname); - if (exec(cmd1, QStringList() << "-q" << "-v" << "-C" << args1, "", 60000)) + args1 << fname << QString::fromLatin1("%1:/tmp/%2").arg(m_uploadServerName, m_tgtFname); + if (exec(cmd1, QStringList() << QLatin1String("-q") << QLatin1String("-v") << QLatin1String("-C") << args1, QString(), 60000)) m_uploadState = UploadScp; } } @@ -109,7 +111,7 @@ bool TestResultUploader::exec(const QString &cmd, const QStringList &arguments, Q_ASSERT(m_executer.state() == QProcess::NotRunning); - if ((workDir != "") && (m_executer.workingDirectory() != workDir)) + if ((!workDir.isEmpty()) && (m_executer.workingDirectory() != workDir)) m_executer.setWorkingDirectory(workDir); m_executer.setEnvironment(*m_testCfg->buildEnvironment()); @@ -122,8 +124,8 @@ bool TestResultUploader::exec(const QString &cmd, const QStringList &arguments, realCmd = cmd; if (realCmd.isEmpty()) { - testOutputPane()->append("-- No '" + cmd + "' instance found in PATH (" - + QSystem::envKey(m_testCfg->buildEnvironment(), "PATH") + ")."); + const QString path = QSystem::envKey(m_testCfg->buildEnvironment(), "PATH"); + testOutputPane()->append(tr("-- No '%1' instance found in PATH (%2).").arg(cmd, path)); return false; } m_executer.start(realCmd,arguments); @@ -135,7 +137,7 @@ bool TestResultUploader::exec(const QString &cmd, const QStringList &arguments, if (m_logFile.isOpen()) { m_logFile.write("exec: "); m_logFile.write(cmd.toLatin1()); - m_logFile.write(arguments.join(" ").toLatin1()); + m_logFile.write(arguments.join(QString(QLatin1Char(' '))).toLatin1()); m_logFile.write("\n"); } return m_executer.waitForStarted(30000); @@ -149,17 +151,17 @@ void TestResultUploader::execFinished(int exitValue, QProcess::ExitStatus) m_logFile.write("Upload FAILED!"); m_logFile.close(); - QString errFname = QDir::homePath() + QDir::separator() + ".qttest" - + QDir::separator() + "last_test_result_upload_failure.log"; + QString errFname = QDir::homePath() + QDir::separator() + QLatin1String(".qttest") + + QDir::separator() + QLatin1String("last_test_result_upload_failure.log"); QFile::remove(errFname); m_logFile.rename(m_logFile.fileName(), errFname); QFile errorFile(errFname); QString lastErrorMessage; if (errorFile.open(QIODevice::ReadOnly)){ - lastErrorMessage = QString("Upload FAILED: %1").arg(QString(errorFile.readAll())); + lastErrorMessage = tr("Upload FAILED: %1").arg(QString::fromLocal8Bit(errorFile.readAll())); errorFile.close(); } else { - lastErrorMessage = QString("Upload FAILED, look at the log file %1").arg(errFname); + lastErrorMessage = tr("Upload FAILED, look at the log file %1").arg(errFname); } testOutputPane()->append(lastErrorMessage); } @@ -173,16 +175,14 @@ void TestResultUploader::execFinished(int exitValue, QProcess::ExitStatus) QString cmd2 = QSystem::which(m_testCfg->PATH(), "ssh"); QStringList args2; args2 << m_uploadServerName - << "mv" - << "-f" - << QString("/tmp/%1").arg(m_tgtFname) - << QString("results/%3").arg(m_tgtFname); - exec(cmd2, QStringList() << "-q" << "-v" << args2); + << QLatin1String("mv") + << QLatin1String("-f") + << QLatin1String("/tmp/") + m_tgtFname + << QLatin1String("results/") + m_tgtFname; + exec(cmd2, QStringList() << QLatin1String("-q") << QLatin1String("-v") << args2); } else if (m_uploadState == UploadMv) { m_uploadState = UploadIdle; - testOutputPane()->append("\nTest results have been uploaded into the results database.\nThank you for supporting " - + m_testCfg->configName()); - + testOutputPane()->append(tr("\nTest results have been uploaded into the results database.\nThank you for supporting %1").arg(m_testCfg->configName())); QFile::remove(m_srcFname); m_logFile.close(); m_logFile.remove(); diff --git a/src/plugins/qttest/testresultuploader.h b/src/plugins/qttest/testresultuploader.h index d354ef24943dfd72d85b70c490a55742a1ac0cf9..b76671f99f11a8789c83985afa3fdd389cee94b8 100644 --- a/src/plugins/qttest/testresultuploader.h +++ b/src/plugins/qttest/testresultuploader.h @@ -38,7 +38,6 @@ #include <QObject> #include <QProcess> -#include <QDebug> class TestResultUploader : public QObject { diff --git a/src/plugins/qttest/testselector.cpp b/src/plugins/qttest/testselector.cpp index 1ca4f80ec29a460fcfadd13dbf684ea3df9151b4..228d74e2bb14b075d3d146989db999ae1f84aeba 100644 --- a/src/plugins/qttest/testselector.cpp +++ b/src/plugins/qttest/testselector.cpp @@ -38,6 +38,8 @@ #include "testgenerator.h" #include "dialogs.h" #include "testconfigurations.h" +#include "testexecuter.h" +#include "testcontextmenu.h" #include <projectexplorer/session.h> #include <projectexplorer/project.h> @@ -221,7 +223,7 @@ QString TestViewItem::suiteName() if (m_parent != 0) ret = m_parent->suiteName(); if (m_isTestSuite) { - if (!ret.isEmpty()) ret += "/"; + if (!ret.isEmpty()) ret += QLatin1Char('/'); ret += m_name; } return QDir::convertSeparators(ret); @@ -231,7 +233,7 @@ QString TestViewItem::fullName() { QString ret = suiteName(); if (!m_isTestSuite) { - ret += "/"+ m_name; + ret += QLatin1Char('/')+ m_name; } return QDir::convertSeparators(ret); } @@ -413,7 +415,7 @@ bool splitSuiteName(const QString &fullName, QString &first, QString &rest) return false; first = L[0]; - rest = ""; + rest.clear(); if (L.count() > 1) { for (int i = 1; i < L.count(); ++i) { if (!rest.isEmpty()) @@ -564,7 +566,7 @@ QString TestFunctionItem::key(int column, bool /*ascending*/) const int TestSelector::m_refCount = 0; -TestSelector::TestSelector(QWidget *parent, const char *name) : +TestSelector::TestSelector(QWidget *parent) : QTreeWidget(parent) { TestSettings testSettings; @@ -577,14 +579,12 @@ TestSelector::TestSelector(QWidget *parent, const char *name) : connect(TestExecuter::instance(), SIGNAL(testFinished()), this, SLOT(updateActions()), Qt::DirectConnection); - Q_UNUSED(name); - setColumnCount(1); setSortingEnabled(false); setRootIsDecorated(true); setSelectionMode(QAbstractItemView::SingleSelection); - m_curTest.m_testFunction = ""; + m_curTest.m_testFunction.clear();; m_curTest.m_line = -1; m_curTest.m_code = 0; @@ -796,14 +796,14 @@ void TestSelector::onSelectionChanged() m_testCollection.setCurrentEditedTest(0); m_curTest.m_code = 0; - m_curTest.m_basePath = ""; + m_curTest.m_basePath.clear(); checkSuite(0, selected, multiSelection); if (!selected || multiSelection) { // no function and no class selected m_curTest.m_code = 0; - m_curTest.m_testFunction = ""; + m_curTest.m_testFunction.clear(); m_curTest.m_line = -1; - m_testContextMenu->updateSingleTestAction(""); + m_testContextMenu->updateSingleTestAction(QString()); } if (m_curTest.m_code) { @@ -855,9 +855,9 @@ void TestSelector::selectGroup() if (inf && (inf->testStartLine() >= 0)) { if (!inf->testGroups().isEmpty()) { dlg.addSelectableItems(inf->testGroups() - .split(",", QString::SkipEmptyParts)); + .split(QLatin1Char(','), QString::SkipEmptyParts)); groupsList.append(tc->testCase() + "::" + inf->functionName() - + "@" + inf->testGroups().split(",", QString::SkipEmptyParts).join("@")); + + QLatin1Char('@') + inf->testGroups().split(QLatin1Char(','), QString::SkipEmptyParts).join(QString(QLatin1Char('@')))); } } } @@ -871,7 +871,7 @@ void TestSelector::selectGroup() while (current < groupsList.count()) { bool containsAGroup = false; for (int i = 0; i < selectedGroups.count(); ++i) { - if (groupsList[current].contains(QString("@" + selectedGroups[i]))) { + if (groupsList[current].contains(QString(QLatin1Char('@') + selectedGroups[i]))) { containsAGroup = true; break; } @@ -879,7 +879,7 @@ void TestSelector::selectGroup() if (!containsAGroup) { groupsList.removeAt(current); } else { - groupsList[current] = groupsList[current].left(groupsList[current].indexOf("@")); + groupsList[current] = groupsList[current].left(groupsList[current].indexOf(QLatin1Char('@'))); ++current; } } @@ -890,7 +890,7 @@ void TestSelector::selectGroup() QString TestSelector::curTestSuite(bool fullPath) { if ((m_curTest.m_code == 0) || m_curTest.m_code->actualFileName().isEmpty()) - return ""; + return QString(); if (fullPath) return m_curTest.m_code->fullVisualSuitePath(m_testSettings.componentViewMode()); return m_curTest.m_code->visualBasePath(); @@ -921,7 +921,7 @@ void TestSelector::checkSuite(TestSuiteItem *base, bool &selected, bool &multiSe multiSelection = true; selected = true; if (!multiSelection) { - m_curTest.m_testFunction = ""; + m_curTest.m_testFunction.clear(); m_curTest.m_line = -1; if (!m_curTest.m_code || (m_curTest.m_code->visualFileName(m_testSettings.componentViewMode()) != T->fullName())) { @@ -943,7 +943,7 @@ void TestSelector::checkSuite(TestSuiteItem *base, bool &selected, bool &multiSe multiSelection = true; selected = true; if (!multiSelection) { - m_curTest.m_testFunction = ""; + m_curTest.m_testFunction.clear(); m_curTest.m_line = -1; if (!m_curTest.m_code || (m_curTest.m_code->visualFileName(m_testSettings.componentViewMode()) != testCase->fullName())) { @@ -1190,7 +1190,7 @@ void TestSelector::select(TestCode *tc, const QString &funcName) QString tcFileName = tc->visualFileName(m_testSettings.componentViewMode()); TestCaseItem *testCase = findCase(tcFileName); if (testCase) { - if (funcName != "") { + if (!funcName.isEmpty()) { TestFunctionItem *testFunction; if (testCase->findFunction(funcName, testFunction)) { expandItem(testFunction); @@ -1480,7 +1480,7 @@ void TestSelector::testInsertUnitOrSystemTest() gen.enableComponentInTestName(dlg.componentInName()); gen.setTestCase(dlg.mode(), dlg.location(), - "", // use automatic "subdir" selection + QString(), // use automatic "subdir" selection dlg.testCaseName(), dlg.testedComponent(), dlg.testedClassName(), diff --git a/src/plugins/qttest/testselector.h b/src/plugins/qttest/testselector.h index dcc9f01c1d07a946243e38f339a3160b2178ef44..799f1d85094c9d8440fe9dceb9bb9ffb48f1eb8a 100644 --- a/src/plugins/qttest/testselector.h +++ b/src/plugins/qttest/testselector.h @@ -34,22 +34,21 @@ #define TESTSELECTOR_H #include "testsuite.h" -#include "testexecuter.h" -#include "testcode.h" #include "testsettings.h" -#include "testcontextmenu.h" - -#include <extensionsystem/iplugin.h> -#include <projectexplorer/projectexplorer.h> #include <QString> #include <QTreeWidget> -#include <QMenu> -#include <QAction> + +QT_BEGIN_NAMESPACE +class QMenu; +class QAction; +QT_END_NAMESPACE class TestSuiteItem; class TestCaseItem; class TestFunctionItem; +class TestContextMenu; +class TestCode; class TestViewItem : public QTreeWidgetItem { @@ -112,7 +111,7 @@ class TestSelector : public QTreeWidget Q_OBJECT public: - TestSelector(QWidget *parent = 0, const char *name = 0); + explicit TestSelector(QWidget *parent = 0); virtual ~TestSelector(); void setContextMenu(TestContextMenu *contextMenu); diff --git a/src/plugins/qttest/testsettings.cpp b/src/plugins/qttest/testsettings.cpp index a747fa12fa46e46cf68d518fce978ff78adeb2e0..5ef4b4f455c0865474f4130c57bee92230fdc2e5 100644 --- a/src/plugins/qttest/testsettings.cpp +++ b/src/plugins/qttest/testsettings.cpp @@ -83,7 +83,7 @@ TestIniFile::TestIniFile(const QString &fileName) QString S; while (!ds.atEnd()) { S = ds.readLine().trimmed(); - if (S != "" && !S.startsWith("#")) + if (!S.isEmpty() && !S.startsWith(QLatin1Char('#'))) m_settings.append(S); } } @@ -101,7 +101,7 @@ bool TestIniFile::find(const QString &key, QString &line) { foreach (const QString &S, m_settings) { if (S.startsWith(key)) { - int pos = S.indexOf("="); + int pos = S.indexOf(QLatin1Char('=')); if (pos > 0) { line = S.mid(pos+1).trimmed(); return true; @@ -176,8 +176,8 @@ bool TestIniFile::initSaving(const QString &comment) } } - foreach (const QString &S, comment.split("\n")) { - if (!S.startsWith("#")) + foreach (const QString &S, comment.split(QLatin1Char('\n'))) { + if (!S.startsWith(QLatin1Char('#'))) *m_outStream << "# "; *m_outStream << S << "\n"; } @@ -189,7 +189,7 @@ bool TestIniFile::write(const QString &comment, const QString &key, const QStrin { if (!initSaving(comment)) return false; - *m_outStream << key << "="; + *m_outStream << key << '='; if (!value.isEmpty()) *m_outStream << value; *m_outStream << "\n\n"; @@ -200,7 +200,7 @@ bool TestIniFile::write(const QString &comment, const QString &key, int value) { if (!initSaving(comment)) return false; - *m_outStream << key << "=" << QString("%1").arg(value) << "\n\n"; + *m_outStream << key << '=' << QString::number(value) << "\n\n"; return true; } @@ -208,7 +208,7 @@ bool TestIniFile::write(const QString &comment, const QString &key, uint value) { if (!initSaving(comment)) return false; - *m_outStream << key << "=" << QString("%1").arg(value) << "\n\n"; + *m_outStream << key << '=' << QString::number(value) << "\n\n"; return true; } @@ -216,9 +216,9 @@ bool TestIniFile::write(const QString &comment, const QString &key, QDateTime va { if (!initSaving(comment)) return false; - *m_outStream << key << "="; + *m_outStream << key << '='; if (value.isValid()) - *m_outStream << QString("%1").arg(value.toString(Qt::ISODate)); + *m_outStream << value.toString(Qt::ISODate); *m_outStream << "\n\n"; return true; } diff --git a/src/plugins/qttest/testsettings.h b/src/plugins/qttest/testsettings.h index 38d3b81f7d71e1698512ccea5170cff9ac918437..1400bacca1dff4ade1ec7205bf11056dcf0d3012 100644 --- a/src/plugins/qttest/testsettings.h +++ b/src/plugins/qttest/testsettings.h @@ -33,10 +33,8 @@ #ifndef TESTSETTINGS_H #define TESTSETTINGS_H -#include "qsystem.h" - +#include <QObject> #include <QString> -#include <QStringList> // class TestSettings_p; class TestSettings_p : public QObject diff --git a/src/plugins/qttest/testsettingspropertiespage.cpp b/src/plugins/qttest/testsettingspropertiespage.cpp index 19d2495ccbd08086a811b4aea71ef0a9b76bcece..fc49d7cbff5e4febadcb3aeb26c70ee6fec03e70 100644 --- a/src/plugins/qttest/testsettingspropertiespage.cpp +++ b/src/plugins/qttest/testsettingspropertiespage.cpp @@ -31,6 +31,7 @@ **************************************************************************/ #include "testsettingspropertiespage.h" +#include "testconfigurations.h" #include <projectexplorer/project.h> @@ -249,13 +250,13 @@ void TestSettingsWidget::onChanged() // to be used when uploading test results if (!m_ui.upload_branch_Specialization->text().trimmed().isEmpty()) m_ui.effectiveBranchName->setText(m_ui.upload_branch->text().trimmed() - + "-" + m_ui.upload_branch_Specialization->text().trimmed()); + + QLatin1Char('-') + m_ui.upload_branch_Specialization->text().trimmed()); else m_ui.effectiveBranchName->setText(m_ui.upload_branch->text().trimmed()); if (!m_ui.qmakespecSpecialization->text().trimmed().isEmpty()) m_ui.effectiveQMakespec->setText(m_ui.qmakespec->text().trimmed() - + "_" + m_ui.qmakespecSpecialization->text().trimmed()); + + QLatin1Char('_') + m_ui.qmakespecSpecialization->text().trimmed()); else m_ui.effectiveQMakespec->setText(m_ui.qmakespec->text().trimmed()); diff --git a/src/plugins/qttest/testsettingspropertiespage.h b/src/plugins/qttest/testsettingspropertiespage.h index 5cced6504076f8ada69512c69dd54f77873aab3f..8c41a82fd3f6bb218a1e43aaa0e08a94bac0cf18 100644 --- a/src/plugins/qttest/testsettingspropertiespage.h +++ b/src/plugins/qttest/testsettingspropertiespage.h @@ -33,15 +33,15 @@ #ifndef TESTSETTINGSPROPERTIESPAGE_H #define TESTSETTINGSPROPERTIESPAGE_H -#include "testconfigurations.h" #include "testsettings.h" #include <projectexplorer/iprojectproperties.h> -#include <projectexplorer/iprojectmanager.h> #include <ui_testsettingspropertiespage.h> #include <QStringList> +class TestConfig; + namespace QtTest { namespace Internal {