qttest: Fix issues reported by Krazy

Change-Id: I7bce3cd862b7f680f1b8f42249ae0df4c12e10d9
Reviewed-on: http://codereview.qt-project.org/4299
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
Shane Bradley
2011-09-07 10:19:21 +10:00
committed by Bill King
parent 942973faf4
commit c1e32ad604
7 changed files with 52 additions and 47 deletions

View File

@@ -53,7 +53,7 @@
# include <time.h> # include <time.h>
#endif #endif
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN
# include <windows.h> # include <windows.h>
# include <stdlib.h> # include <stdlib.h>
#endif #endif
@@ -89,14 +89,16 @@ QString QSystem::userName()
#if defined Q_OS_TEMP #if defined Q_OS_TEMP
userName = QLatin1String("WinCE"); userName = QLatin1String("WinCE");
#elif defined Q_OS_WIN32 #elif defined Q_OS_WIN
userName = QString::fromLocal8Bit(qgetenv("USERNAME")); userName = QString::fromLocal8Bit(qgetenv("USERNAME"));
#elif defined Q_OS_UNIX #elif defined Q_OS_UNIX
userName = QString::fromLocal8Bit(qgetenv("USER")); userName = QString::fromLocal8Bit(qgetenv("USER"));
if (userName.isEmpty()) if (userName.isEmpty())
userName = QString::fromLocal8Bit(qgetenv("LOGNAME")); userName = QString::fromLocal8Bit(qgetenv("LOGNAME"));
#elif defined Q_OS_MAC #elif defined Q_OS_MAC
userName = getenv(); // TODO? userName = QString::fromLocal8Bit(qgetenv("USER"));
if (userName.isEmpty())
userName = QString::fromLocal8Bit(qgetenv("LOGNAME"));
#endif #endif
return userName.toLower(); return userName.toLower();

View File

@@ -48,7 +48,6 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/modemanager.h> #include <coreplugin/modemanager.h>
#include <coreplugin/id.h> #include <coreplugin/id.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -306,11 +305,9 @@ void QtTestPlugin::insertTestFunction()
if (currentTest) { if (currentTest) {
QString prompt = QLatin1String("<b>") + currentTest->testTypeString() QString prompt = QLatin1String("<b>") + currentTest->testTypeString()
+ QLatin1String(" Test: </b>") + currentTest->testCase(); + QLatin1String(" Test: </b>") + currentTest->testCase();
NewTestFunctionDlg dlg(prompt); QPointer<NewTestFunctionDlg> dlg = new NewTestFunctionDlg(prompt);
dlg.exec(); if (dlg->exec() == QDialog::Accepted) {
QString testFunc = dlg->testFunctionName->text();
if (dlg.result() == QDialog::Accepted) {
QString testFunc = dlg.testFunctionName->text();
// check for duplicate // check for duplicate
if (TestFunctionInfo *functionInfo = currentTest->findFunction(testFunc)) { if (TestFunctionInfo *functionInfo = currentTest->findFunction(testFunc)) {
QMessageBox::critical(0, tr("Error"), QMessageBox::critical(0, tr("Error"),
@@ -318,8 +315,9 @@ void QtTestPlugin::insertTestFunction()
currentTest->gotoLine(functionInfo->testStartLine()); currentTest->gotoLine(functionInfo->testStartLine());
return; return;
} }
currentTest->addTestFunction(testFunc, QString(), dlg.insertAtCursor->isChecked()); currentTest->addTestFunction(testFunc, QString(), dlg->insertAtCursor->isChecked());
} }
delete dlg;
} }
} }

7
src/plugins/qttest/testcontextmenu.cpp Executable file → Normal file
View File

@@ -36,7 +36,6 @@
#include "qsystem.h" #include "qsystem.h"
#include "testsuite.h" #include "testsuite.h"
#include "testexecuter.h" #include "testexecuter.h"
#include "testcode.h"
#include "testoutputwindow.h" #include "testoutputwindow.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
@@ -316,9 +315,9 @@ void TestContextMenuPrivate::editorChanged(Core::IEditor *iface)
if (iface) { if (iface) {
QString fname = iface->displayName(); QString fname = iface->displayName();
isTestcase = ((fname.endsWith(".qtt") || fname.endsWith(".cpp")) isTestcase = ((fname.endsWith(QLatin1String(".qtt")) || fname.endsWith(QLatin1String(".cpp")))
&& (fname.startsWith("tst_") || fname.startsWith("sys_") && (fname.startsWith(QLatin1String("tst_")) || fname.startsWith(QLatin1String("sys_"))
|| fname.startsWith("int_") || fname.startsWith("prf_"))); || fname.startsWith(QLatin1String("int_")) || fname.startsWith(QLatin1String("prf_"))));
} }
if (isTestcase) { if (isTestcase) {

View File

@@ -601,7 +601,7 @@ void TestExecuter::parseOutput()
} }
} else { } else {
if (m_xmlMode) { if (m_xmlMode) {
if (line.startsWith("<?xml version")) { if (line.startsWith(QLatin1String("<?xml version"))) {
m_xmlTestfunction.clear(); m_xmlTestfunction.clear();
m_xmlTestcase.clear(); m_xmlTestcase.clear();
m_xmlDatatag.clear(); m_xmlDatatag.clear();
@@ -670,7 +670,7 @@ void TestExecuter::parseOutput()
xmlLineVariable(line,"line=",m_xmlLine); xmlLineVariable(line,"line=",m_xmlLine);
if (line.endsWith("/>")) { if (line.endsWith(QLatin1String("/>"))) {
line = m_xmlResult.toUpper(); line = m_xmlResult.toUpper();
while (line.length() < 7) while (line.length() < 7)
line += QLatin1Char(' '); line += QLatin1Char(' ');
@@ -703,14 +703,14 @@ void TestExecuter::parseOutput()
m_killTestRequested = true; m_killTestRequested = true;
QTimer::singleShot(1500, this, SLOT(onKillTestRequested())); QTimer::singleShot(1500, this, SLOT(onKillTestRequested()));
} else if (line.startsWith("</Environment>")) { } else if (line.startsWith(QLatin1String("</Environment>"))) {
line = "Config: Using QTest library " + m_xmlQtestVersion line = "Config: Using QTest library " + m_xmlQtestVersion
+ ", Qt " + m_xmlQtVersion; + ", Qt " + m_xmlQtVersion;
} else if (xmlLineStartsWith(line, "<TestCase name=\"", m_xmlTestcase)) { } else if (xmlLineStartsWith(line, "<TestCase name=\"", m_xmlTestcase)) {
line = "********* Start testing of " + m_xmlTestcase + " *********"; line = "********* Start testing of " + m_xmlTestcase + " *********";
} else if (line.startsWith("<Environment>")) { } else if (line.startsWith(QLatin1String("<Environment>"))) {
continue; continue;
} else if (xmlLineStartsWith(line, "<TestFunction name=\"", m_xmlTestfunction) } else if (xmlLineStartsWith(line, "<TestFunction name=\"", m_xmlTestfunction)
@@ -718,7 +718,7 @@ void TestExecuter::parseOutput()
|| xmlLineStartsWith(line,"<QTestVersion>",m_xmlQtestVersion)) { || xmlLineStartsWith(line,"<QTestVersion>",m_xmlQtestVersion)) {
continue; continue;
} else if (line.startsWith("<anonymous>()@")) { } else if (line.startsWith(QLatin1String("<anonymous>()@"))) {
m_xmlFile = line.mid(line.indexOf(QLatin1Char('@'))+1); m_xmlFile = line.mid(line.indexOf(QLatin1Char('@'))+1);
m_xmlLine = m_xmlFile.mid(m_xmlFile.indexOf(QLatin1Char(':'))+1); m_xmlLine = m_xmlFile.mid(m_xmlFile.indexOf(QLatin1Char(':'))+1);
m_xmlFile = m_xmlFile.left(m_xmlFile.indexOf(QLatin1Char(':'))); m_xmlFile = m_xmlFile.left(m_xmlFile.indexOf(QLatin1Char(':')));
@@ -1261,10 +1261,9 @@ void TestExecuter::eventRecordingStarted(const QString &file, int line, const QS
tmp->openTestInEditor(QString()); tmp->openTestInEditor(QString());
tmp->gotoLine(line); tmp->gotoLine(line);
} }
QPointer<QDialog> recordWindow = new QDialog;
QDialog recordWindow;
Ui::RecordDialog ui; Ui::RecordDialog ui;
ui.setupUi(&recordWindow); ui.setupUi(recordWindow);
if (!manualSteps.isEmpty()) { if (!manualSteps.isEmpty()) {
ui.steps_view->setPlainText(manualSteps); ui.steps_view->setPlainText(manualSteps);
@@ -1277,12 +1276,13 @@ void TestExecuter::eventRecordingStarted(const QString &file, int line, const QS
"or 'Abort' to abandon recording."); "or 'Abort' to abandon recording.");
m_recordedEventsEdit = ui.codeEdit; m_recordedEventsEdit = ui.codeEdit;
connect(ui.abort_button, SIGNAL(clicked()), &recordWindow, SLOT(close())); connect(ui.abort_button, SIGNAL(clicked()), recordWindow, SLOT(close()));
connect(ui.abort_button, SIGNAL(clicked()), this, SLOT(abortRecording())); connect(ui.abort_button, SIGNAL(clicked()), this, SLOT(abortRecording()));
m_abortRecording = false; m_abortRecording = false;
m_recordingEvents = true; m_recordingEvents = true;
recordWindow.exec(); recordWindow->exec();
delete recordWindow;
m_recordingEvents = false; m_recordingEvents = false;
if (m_abortRecording) if (m_abortRecording)
return; return;

View File

@@ -176,6 +176,11 @@ public:
int m_startLine; int m_startLine;
}; };
const QPixmap TestViewItem::m_selectpxm(selected_xpm);
const QPixmap TestViewItem::m_unselectpxm(unselected_xpm);
const QPixmap TestViewItem::m_parentAssignpxm(parentAssigned_xpm);
const QPixmap TestViewItem::m_childAssignpxm(childAssigned_xpm);
TestViewItem::TestViewItem(TestViewItem *parent, const QString &name, bool testSuite, int type) : TestViewItem::TestViewItem(TestViewItem *parent, const QString &name, bool testSuite, int type) :
QTreeWidgetItem(parent, QStringList() << name, type), QTreeWidgetItem(parent, QStringList() << name, type),
m_errored(false) m_errored(false)
@@ -356,22 +361,17 @@ TestViewItem *TestSelector::recastItem(QTreeWidgetItem *item)
void TestViewItem::updatePixmap() void TestViewItem::updatePixmap()
{ {
static QPixmap selectpxm = QPixmap(selected_xpm);
static QPixmap unselectpxm = QPixmap(unselected_xpm);
static QPixmap parentAssignpxm = QPixmap(parentAssigned_xpm);
static QPixmap childAssignpxm = QPixmap(childAssigned_xpm);
if (m_errored) if (m_errored)
return; return;
if (m_assigned) if (m_assigned)
setIcon(0, QIcon(selectpxm)); setIcon(0, QIcon(m_selectpxm));
else if (m_parentAssigned > 0) else if (m_parentAssigned > 0)
setIcon(0, QIcon(parentAssignpxm)); setIcon(0, QIcon(m_parentAssignpxm));
else if (m_childAssigned > 0) else if (m_childAssigned > 0)
setIcon(0, QIcon(childAssignpxm)); setIcon(0, QIcon(m_childAssignpxm));
else else
setIcon(0, QIcon(unselectpxm)); setIcon(0, QIcon(m_unselectpxm));
} }
void TestViewItem::removeAllChildren() void TestViewItem::removeAllChildren()
@@ -840,7 +840,7 @@ void TestSelector::updateActions()
void TestSelector::selectGroup() void TestSelector::selectGroup()
{ {
SelectDlg dlg("Select a group", QPointer<SelectDlg> dlg = new SelectDlg("Select a group",
"Please select the groups that you'd want to test", "Please select the groups that you'd want to test",
QAbstractItemView::MultiSelection, QAbstractItemView::MultiSelection,
300, 400, QStringList() << "Groups", QByteArray(), this); 300, 400, QStringList() << "Groups", QByteArray(), this);
@@ -853,7 +853,7 @@ void TestSelector::selectGroup()
TestFunctionInfo *inf = tc->testFunction(j); TestFunctionInfo *inf = tc->testFunction(j);
if (inf && (inf->testStartLine() >= 0)) { if (inf && (inf->testStartLine() >= 0)) {
if (!inf->testGroups().isEmpty()) { if (!inf->testGroups().isEmpty()) {
dlg.addSelectableItems(inf->testGroups() dlg->addSelectableItems(inf->testGroups()
.split(QLatin1Char(','), QString::SkipEmptyParts)); .split(QLatin1Char(','), QString::SkipEmptyParts));
groupsList.append(tc->testCase() + "::" + inf->functionName() groupsList.append(tc->testCase() + "::" + inf->functionName()
+ QLatin1Char('@') + inf->testGroups().split(QLatin1Char(','), QString::SkipEmptyParts).join(QString(QLatin1Char('@')))); + QLatin1Char('@') + inf->testGroups().split(QLatin1Char(','), QString::SkipEmptyParts).join(QString(QLatin1Char('@'))));
@@ -863,8 +863,8 @@ void TestSelector::selectGroup()
} }
} }
if (dlg.exec()) { if (dlg->exec()) {
QStringList selectedGroups = dlg.selectedItems(); QStringList selectedGroups = dlg->selectedItems();
unassignAll(); unassignAll();
int current = 0; int current = 0;
while (current < groupsList.count()) { while (current < groupsList.count()) {
@@ -884,6 +884,7 @@ void TestSelector::selectGroup()
} }
setSelectedTests(true, groupsList); setSelectedTests(true, groupsList);
} }
delete dlg;
} }
QString TestSelector::curTestSuite(bool fullPath) QString TestSelector::curTestSuite(bool fullPath)
@@ -1462,19 +1463,18 @@ void TestSelector::testInsertUnitOrSystemTest()
if (cfg) if (cfg)
basePath = cfg->srcPath(); basePath = cfg->srcPath();
} }
QPointer<NewTestCaseDlg> dlg = new NewTestCaseDlg(basePath, this);
NewTestCaseDlg dlg(basePath, this); if (dlg->exec() == QDialog::Accepted) {
if (dlg.exec() == QDialog::Accepted) {
TestGenerator gen; TestGenerator gen;
QString classFile; QString classFile;
gen.enableComponentInTestName(dlg.componentInName()); gen.enableComponentInTestName(dlg->componentInName());
gen.setTestCase(dlg.mode(), gen.setTestCase(dlg->mode(),
dlg.location(), dlg->location(),
QString(), // use automatic "subdir" selection QString(), // use automatic "subdir" selection
dlg.testCaseName(), dlg->testCaseName(),
dlg.testedComponent(), dlg->testedComponent(),
dlg.testedClassName(), dlg->testedClassName(),
classFile); classFile);
if (gen.generateTest()) { if (gen.generateTest()) {
@@ -1486,4 +1486,5 @@ void TestSelector::testInsertUnitOrSystemTest()
} }
} }
} }
delete dlg;
} }

View File

@@ -104,6 +104,11 @@ private:
uint m_parentAssigned; uint m_parentAssigned;
bool m_assigned; bool m_assigned;
bool m_isTestSuite; bool m_isTestSuite;
static const QPixmap m_selectpxm;
static const QPixmap m_unselectpxm;
static const QPixmap m_parentAssignpxm;
static const QPixmap m_childAssignpxm;
}; };
class TestSelector : public QTreeWidget class TestSelector : public QTreeWidget

View File

@@ -295,7 +295,7 @@
<item> <item>
<widget class="QLineEdit" name="qmakespec"> <widget class="QLineEdit" name="qmakespec">
<property name="toolTip"> <property name="toolTip">
<string>The reference for the plaform under test, e.g: &lt;MkSpec&gt;</string> <string>The reference for the platform under test, e.g: &lt;MkSpec&gt;</string>
</property> </property>
</widget> </widget>
</item> </item>