Commit 5b0bf616 authored by hjk's avatar hjk Committed by hjk

qtcassert: move actual printing to separate function and enforce style

This also allows simple setting of breakpoints on failed asserts.

Change-Id: I6dd84cbfaf659d57e39f3447386cebc0221b2b84
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 37e38530
......@@ -84,12 +84,11 @@ QWizard *WebPageWizard::createWizardDialog(QWidget *parent,
}
Core::GeneratedFiles
WebPageWizard::generateFiles(const QWizard *w,
QString *) const
WebPageWizard::generateFiles(const QWizard *w, QString *) const
{
Core::GeneratedFiles files;
const WebContentWizardDialog *dialog = qobject_cast<const WebContentWizardDialog*>(w);
QTC_ASSERT(dialog, return files; )
QTC_ASSERT(dialog, return files);
const QString fileName = Core::BaseFileWizard::buildFileName(dialog->path(), dialog->fileName(), QLatin1String("html"));
......
......@@ -33,6 +33,7 @@
#include "fileinprojectfinder.h"
#include <utils/qtcassert.h>
#include <QDebug>
#include <QFileInfo>
#include <QUrl>
......
......@@ -36,6 +36,7 @@
#include "qtcassert.h"
#include <QDir>
#include <QDebug>
#include <QFileInfo>
#include <QTemporaryFile>
#include <QDateTime>
......@@ -208,19 +209,18 @@ QString FileUtils::resolveSymlinks(const QString &path)
return f.filePath();
}
QByteArray FileReader::fetchQrc(const QString &fileName)
{
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray())
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray());
QFile file(fileName);
bool ok = file.open(QIODevice::ReadOnly);
QTC_ASSERT(ok, qWarning() << fileName << "not there!"; return QByteArray())
QTC_ASSERT(ok, qWarning() << fileName << "not there!"; return QByteArray());
return file.readAll();
}
bool FileReader::fetch(const QString &fileName, QIODevice::OpenMode mode)
{
QTC_ASSERT(!(mode & ~(QIODevice::ReadOnly | QIODevice::Text)), return false)
QTC_ASSERT(!(mode & ~(QIODevice::ReadOnly | QIODevice::Text)), return false);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | mode)) {
......
......@@ -131,7 +131,7 @@ bool BinaryVersionToolTipEventFilter::eventFilter(QObject *o, QEvent *e)
if (e->type() != QEvent::ToolTip)
return false;
QLineEdit *le = qobject_cast<QLineEdit *>(o);
QTC_ASSERT(le, return false; )
QTC_ASSERT(le, return false);
const QString binary = le->text();
if (!binary.isEmpty()) {
......
......@@ -130,7 +130,7 @@ struct ParseValueStackEntry
ParseValueStackEntry::ParseValueStackEntry(const QVariant &aSimpleValue, const QString &k) :
type(aSimpleValue.type()), key(k), simpleValue(aSimpleValue)
{
QTC_ASSERT(simpleValue.isValid(), return ; )
QTC_ASSERT(simpleValue.isValid(), return);
}
QVariant ParseValueStackEntry::value() const
......@@ -250,10 +250,10 @@ bool ParseContext::handleEndElement(const QStringRef &name)
{
const Element e = element(name);
if (ParseContext::isValueElement(e)) {
QTC_ASSERT(!m_valueStack.isEmpty(), return true; )
QTC_ASSERT(!m_valueStack.isEmpty(), return true);
const ParseValueStackEntry top = m_valueStack.pop();
if (m_valueStack.isEmpty()) { // Last element? -> Done with that variable.
QTC_ASSERT(!m_currentVariableName.isEmpty(), return true; )
QTC_ASSERT(!m_currentVariableName.isEmpty(), return true);
m_result.insert(m_currentVariableName, top.value());
m_currentVariableName.clear();
return false;
......@@ -286,7 +286,7 @@ QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttr
const QString type = attributes.value(typeAttribute).toString();
const QString text = r.readElementText();
if (type == QLatin1String("QChar")) { // Workaround: QTBUG-12345
QTC_ASSERT(text.size() == 1, return QVariant(); )
QTC_ASSERT(text.size() == 1, return QVariant());
return QVariant(QChar(text.at(0)));
}
QVariant value;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "qtcassert.h"
namespace Utils {
void writeAssertLocation(const char *msg)
{
qDebug("SOFT ASSERT: %s", msg);
}
} // namespace Utils
......@@ -33,19 +33,20 @@
#ifndef QTC_ASSERT_H
#define QTC_ASSERT_H
#include <QDebug>
#include "utils_global.h"
#define QTC_ASSERT_STRINGIFY_INTERNAL(x) #x
#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_INTERNAL(x)
namespace Utils { QTCREATOR_UTILS_EXPORT void writeAssertLocation(const char *msg); }
// we do not use the 'do {...} while (0)' idiom here to be able to use
// 'break' and 'continue' as 'actions'.
#define QTC_ASSERT_STRINGIFY_HELPER(x) #x
#define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
#define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(\
"\"" cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__))
#define QTC_ASSERT(cond, action) \
if(cond){}else{qDebug()<<"SOFT ASSERT: \""#cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__);action;}
// The 'do {...} while (0)' idiom is not used for the main block here to be
// able to use 'break' and 'continue' as 'actions'.
#define QTC_CHECK(cond) \
if(cond){}else{qDebug()<<"SOFT ASSERT: \""#cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__);}
#define QTC_ASSERT(cond, action) if (cond) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
#define QTC_CHECK(cond) if (cond) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)
#endif // QTC_ASSERT_H
......@@ -553,7 +553,7 @@ bool SynchronousProcess::readDataFromProcess(QProcess &p, int timeOutMS,
return false;
}
QTC_ASSERT(p.readChannel() == QProcess::StandardOutput, return false)
QTC_ASSERT(p.readChannel() == QProcess::StandardOutput, return false);
// Keep the process running until it has no longer has data
bool finished = false;
......
......@@ -32,9 +32,11 @@
#include "tcpportsgatherer.h"
#include "qtcassert.h"
#include <QDebug>
#include <QFile>
#include <QStringList>
#include <QProcess>
#include <QStringList>
#ifdef Q_OS_WIN
#include <QLibrary>
......
......@@ -150,7 +150,7 @@ bool decodeTextFileContent(const QByteArray &dataBA,
Target *target,
void (Target::*appendFunction)(const QString &))
{
QTC_ASSERT(format.codec, return false; )
QTC_ASSERT(format.codec, return false);
QTextCodec::ConverterState state;
bool hasDecodingError = false;
......@@ -283,7 +283,7 @@ TextFileFormat::ReadResult
bool TextFileFormat::writeFile(const QString &fileName, QString plainText, QString *errorString) const
{
QTC_ASSERT(codec, return false;)
QTC_ASSERT(codec, return false);
// Does the user want CRLF? If that is native,
// let QFile do the work, else manually add.
......
......@@ -98,7 +98,8 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/portlist.cpp \
$$PWD/tcpportsgatherer.cpp \
$$PWD/appmainwindow.cpp \
$$PWD/basetreeview.cpp
$$PWD/basetreeview.cpp \
$$PWD/qtcassert.cpp
win32 {
SOURCES += \
......
......@@ -107,6 +107,7 @@ QtcLibrary {
"projectnamevalidatinglineedit.h",
"proxyaction.h",
"qtcassert.h",
"qtcassert.cpp",
"qtcolorbutton.cpp",
"qtcolorbutton.h",
"qtcprocess.h",
......
......@@ -195,7 +195,7 @@ QTCREATOR_UTILS_EXPORT bool winIs64BitSystem()
QTCREATOR_UTILS_EXPORT bool winIs64BitBinary(const QString &binaryIn)
{
QTC_ASSERT(!binaryIn.isEmpty(), return false; )
QTC_ASSERT(!binaryIn.isEmpty(), return false);
#ifdef Q_OS_WIN32
# ifdef __GNUC__ // MinGW lacking some definitions/winbase.h
# define SCS_64BIT_BINARY 6
......
......@@ -99,7 +99,7 @@ CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
const CPlusPlus::Snapshot &snapshot = CPlusPlus::CppModelManagerInterface::instance()->snapshot();
CPlusPlus::Document::Ptr doc = snapshot.document(editor->document()->fileName());
QTC_ASSERT(doc, return 0)
QTC_ASSERT(doc, return 0);
// fetch the expression's code
CPlusPlus::ExpressionUnderCursor expressionUnderCursor;
......
......@@ -1586,7 +1586,7 @@ void BinEditor::asFloat(int offset, float &value, bool old) const
{
value = 0;
const QByteArray data = dataMid(offset, sizeof(float), old);
QTC_ASSERT(data.size() == sizeof(float), return )
QTC_ASSERT(data.size() == sizeof(float), return);
const float *f = reinterpret_cast<const float *>(data.constData());
value = *f;
}
......@@ -1595,7 +1595,7 @@ void BinEditor::asDouble(int offset, double &value, bool old) const
{
value = 0;
const QByteArray data = dataMid(offset, sizeof(double), old);
QTC_ASSERT(data.size() == sizeof(double), return )
QTC_ASSERT(data.size() == sizeof(double), return);
const double *f = reinterpret_cast<const double *>(data.constData());
value = *f;
}
......
......@@ -87,7 +87,7 @@ static inline bool isFormWindowEditor(const QObject *o)
static inline QString formWindowEditorContents(const QObject *editor)
{
const QVariant contentV = editor->property("contents");
QTC_ASSERT(contentV.isValid(), return QString(); )
QTC_ASSERT(contentV.isValid(), return QString());
return contentV.toString();
}
......
......@@ -110,7 +110,7 @@ QMap<QString, QKeySequence> CommandsFile::importCommands() const
if (name == ctx.shortCutElement) {
currentId = r.attributes().value(ctx.idAttribute).toString();
} else if (name == ctx.keyElement) {
QTC_ASSERT(!currentId.isEmpty(), return result; )
QTC_ASSERT(!currentId.isEmpty(), return result);
const QXmlStreamAttributes attributes = r.attributes();
if (attributes.hasAttribute(ctx.valueAttribute)) {
const QString keyString = attributes.value(ctx.valueAttribute).toString();
......
......@@ -742,7 +742,7 @@ BaseFileWizard::OverwriteResult BaseFileWizard::promptOverwrite(GeneratedFiles *
// Set 'keep' attribute in files
foreach (const QString &keepFile, existingFilesToKeep) {
const int i = indexOfFile(*files, keepFile);
QTC_ASSERT(i != -1, return OverwriteCanceled; )
QTC_ASSERT(i != -1, return OverwriteCanceled);
GeneratedFile &file = (*files)[i];
file.setAttributes(file.attributes() | GeneratedFile::KeepExistingFileAttribute);
}
......
......@@ -208,7 +208,7 @@ void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenE
if (hi.document.isNull() || documentsDone.contains(hi.document))
continue;
QString title = model->displayNameForDocument(hi.document);
QTC_ASSERT(!title.isEmpty(), continue;)
QTC_ASSERT(!title.isEmpty(), continue);
documentsDone.insert(hi.document.data());
QTreeWidgetItem *item = new QTreeWidgetItem();
if (hi.document->isModified())
......
......@@ -218,7 +218,7 @@ EditorToolBar::~EditorToolBar()
void EditorToolBar::removeToolbarForEditor(IEditor *editor)
{
QTC_ASSERT(editor, return)
QTC_ASSERT(editor, return);
disconnect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
QWidget *toolBar = editor->toolBar();
......@@ -259,7 +259,7 @@ void EditorToolBar::closeEditor()
void EditorToolBar::addEditor(IEditor *editor)
{
QTC_ASSERT(editor, return)
QTC_ASSERT(editor, return);
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
QWidget *toolBar = editor->toolBar();
......@@ -271,7 +271,7 @@ void EditorToolBar::addEditor(IEditor *editor)
void EditorToolBar::addCenterToolBar(QWidget *toolBar)
{
QTC_ASSERT(toolBar, return)
QTC_ASSERT(toolBar, return);
toolBar->setVisible(false); // will be made visible in setCurrentEditor
d->m_toolBarPlaceholder->layout()->addWidget(toolBar);
......@@ -305,7 +305,7 @@ void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
void EditorToolBar::setCurrentEditor(IEditor *editor)
{
QTC_ASSERT(editor, return)
QTC_ASSERT(editor, return);
d->m_editorList->setCurrentIndex(d->m_editorsListModel->indexOf(editor).row());
// If we never added the toolbar from the editor, we will never change
......
......@@ -176,7 +176,7 @@ void FileIconProvider::registerIconOverlayForSuffix(const QIcon &icon,
if (debug)
qDebug() << "FileIconProvider::registerIconOverlayForSuffix" << suffix;
QTC_ASSERT(!icon.isNull() && !suffix.isEmpty(), return)
QTC_ASSERT(!icon.isNull() && !suffix.isEmpty(), return);
const QPixmap fileIconPixmap = overlayIcon(QStyle::SP_FileIcon, icon, QSize(16, 16));
// replace old icon, if it exists
......
......@@ -1122,7 +1122,7 @@ bool BaseMimeTypeParser::parse(QIODevice *dev, const QString &fileName, QString
}
break;
case ParseMagicMatchRule:
QTC_ASSERT(!ruleMatcher.isNull(), return false)
QTC_ASSERT(!ruleMatcher.isNull(), return false);
if (!addMagicMatchRule(atts, ruleMatcher, errorMessage))
return false;
break;
......@@ -1142,7 +1142,7 @@ bool BaseMimeTypeParser::parse(QIODevice *dev, const QString &fileName, QString
} else {
// Finished a match sequence
if (reader.name() == QLatin1String(magicTagC)) {
QTC_ASSERT(!ruleMatcher.isNull(), return false)
QTC_ASSERT(!ruleMatcher.isNull(), return false);
data.magicMatchers.push_back(ruleMatcher);
ruleMatcher = MagicRuleMatcherPtr();
}
......
......@@ -306,7 +306,7 @@ QString VcsManager::repositoryUrl(const QString &directory)
bool VcsManager::promptToDelete(IVersionControl *vc, const QString &fileName)
{
QTC_ASSERT(vc, return true)
QTC_ASSERT(vc, return true);
if (!vc->supportsOperation(IVersionControl::DeleteOperation))
return true;
const QString title = tr("Version Control");
......
......@@ -99,7 +99,7 @@ bool CodePasterProtocol::checkConfiguration(QString *errorMessage)
void CodePasterProtocol::fetch(const QString &id)
{
QTC_ASSERT(!m_fetchReply, return; )
QTC_ASSERT(!m_fetchReply, return);
QString hostName = m_page->hostName();
const QString httpPrefix = QLatin1String("http://");
......@@ -124,7 +124,7 @@ void CodePasterProtocol::fetch(const QString &id)
void CodePasterProtocol::list()
{
QTC_ASSERT(!m_listReply, return; )
QTC_ASSERT(!m_listReply, return);
QString hostName = m_page->hostName();
QString link = QLatin1String("http://");
......@@ -140,7 +140,7 @@ void CodePasterProtocol::paste(const QString &text,
const QString &comment,
const QString &description)
{
QTC_ASSERT(!m_pasteReply, return; )
QTC_ASSERT(!m_pasteReply, return);
const QString hostName = m_page->hostName();
QByteArray data = "command=processcreate&submit=submit&highlight_type=0&description=";
......
......@@ -88,19 +88,19 @@ CodePasterService::CodePasterService(QObject *parent) :
void CodePasterService::postText(const QString &text, const QString &mimeType)
{
QTC_ASSERT(CodepasterPlugin::instance(), return; )
QTC_ASSERT(CodepasterPlugin::instance(), return);
CodepasterPlugin::instance()->post(text, mimeType);
}
void CodePasterService::postCurrentEditor()
{
QTC_ASSERT(CodepasterPlugin::instance(), return; )
QTC_ASSERT(CodepasterPlugin::instance(), return);
CodepasterPlugin::instance()->postEditor();
}
void CodePasterService::postClipboard()
{
QTC_ASSERT(CodepasterPlugin::instance(), return; )
QTC_ASSERT(CodepasterPlugin::instance(), return);
CodepasterPlugin::instance()->postClipboard();
}
......@@ -366,7 +366,7 @@ void CodepasterPlugin::finishFetch(const QString &titleDescription,
m_fetchedSnippets.push_back(fileName);
// Open editor with title.
Core::IEditor* editor = EditorManager::instance()->openEditor(fileName, Core::Id(), EditorManager::ModeSwitch);
QTC_ASSERT(editor, return)
QTC_ASSERT(editor, return);
editor->setDisplayName(titleDescription);
}
......
......@@ -108,7 +108,7 @@ void KdePasteProtocol::paste(const QString &text,
{
Q_UNUSED(comment);
Q_UNUSED(description);
QTC_ASSERT(!m_pasteReply, return;)
QTC_ASSERT(!m_pasteReply, return);
// Format body
QByteArray pasteData = "api_submit=true&mode=xml";
......@@ -162,7 +162,7 @@ void KdePasteProtocol::pasteFinished()
void KdePasteProtocol::fetch(const QString &id)
{
QTC_ASSERT(!m_fetchReply, return;)
QTC_ASSERT(!m_fetchReply, return);
// Did we get a complete URL or just an id?
m_fetchId = id;
......
......@@ -58,7 +58,7 @@ unsigned PasteBinDotCaProtocol::capabilities() const
void PasteBinDotCaProtocol::fetch(const QString &id)
{
QTC_ASSERT(!m_fetchReply, return)
QTC_ASSERT(!m_fetchReply, return);
const QString url = QLatin1String(urlC);
const QString rawPostFix = QLatin1String("raw/");
// Create link as ""http://pastebin.ca/raw/[id]"
......
......@@ -84,7 +84,7 @@ QSharedPointer<VcsBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QLi
// Collect parameters for the checkout command.
// CVS does not allow for checking out into a different directory.
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return QSharedPointer<VcsBase::AbstractCheckoutJob>())
QTC_ASSERT(cwp, return QSharedPointer<VcsBase::AbstractCheckoutJob>());
const CvsSettings settings = CvsPlugin::instance()->settings();
const QString binary = settings.cvsCommand;
QStringList args;
......
......@@ -620,7 +620,7 @@ void CvsPlugin::cvsDiff(const CvsDiffParameters &p)
VcsBaseEditorWidget::tagEditor(editor, tag);
setDiffBaseDirectory(editor, p.workingDir);
CvsEditor *diffEditorWidget = qobject_cast<CvsEditor*>(editor->widget());
QTC_ASSERT(diffEditorWidget, return ; )
QTC_ASSERT(diffEditorWidget, return);
// Wire up the parameter widget to trigger a re-run on
// parameter change and 'revert' from inside the diff editor.
......@@ -684,14 +684,14 @@ void CvsPlugin::updateActions(VcsBasePlugin::ActionState as)
void CvsPlugin::addCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QTC_ASSERT(state.hasFile(), return);
vcsAdd(state.currentFileTopLevel(), state.relativeCurrentFile());
}
void CvsPlugin::revertAll()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
QTC_ASSERT(state.hasTopLevel(), return);
const QString title = tr("Revert repository");
if (!messageBoxQuestion(title, tr("Revert all pending changes to the repository?")))
return;
......@@ -710,7 +710,7 @@ void CvsPlugin::revertAll()
void CvsPlugin::revertCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QTC_ASSERT(state.hasFile(), return);
QStringList args;
args << QLatin1String("diff") << state.relativeCurrentFile();
const CvsResponse diffResponse =
......@@ -746,28 +746,28 @@ void CvsPlugin::revertCurrentFile()
void CvsPlugin::diffProject()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
QTC_ASSERT(state.hasProject(), return);
cvsDiff(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
void CvsPlugin::diffCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QTC_ASSERT(state.hasFile(), return);
cvsDiff(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CvsPlugin::startCommitCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QTC_ASSERT(state.hasFile(), return);
startCommit(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()));
}
void CvsPlugin::startCommitAll()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return)
QTC_ASSERT(state.hasTopLevel(), return);
startCommit(state.topLevel());
}
......@@ -843,21 +843,21 @@ bool CvsPlugin::commit(const QString &messageFile,
void CvsPlugin::filelogCurrentFile()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return)
QTC_ASSERT(state.hasFile(), return);
filelog(state.currentFileTopLevel(), QStringList(state.relativeCurrentFile()), true);
}
void CvsPlugin::logProject()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasProject(), return)
QTC_ASSERT(state.hasProject(), return);
filelog(state.currentProjectTopLevel(), state.relativeCurrentProject());
}
void CvsPlugin::logRepository()