Commit 92f0214c authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplatform/tests: use Q_DECLARE_PRIVATE/Q_D to forward constness to d

parent cc8b71d8
......@@ -49,21 +49,25 @@ QByteArray preprocess(QByteArray json)
}
DeclarationValidator::DeclarationValidator()
: d(new DeclarationValidatorPrivate)
: d_ptr(new DeclarationValidatorPrivate)
{
}
DeclarationValidator::~DeclarationValidator()
{
}
bool DeclarationValidator::testsPassed()
bool DeclarationValidator::testsPassed() const
{
Q_D(const DeclarationValidator);
return d->testsPassed;
}
void DeclarationValidator::visit(DUContext*) { }
void DeclarationValidator::visit(Declaration* declaration)
{
Q_D(DeclarationValidator);
QJsonParseError error;
const auto json = preprocess(declaration->comment());
QJsonDocument doc = QJsonDocument::fromJson(json, &error);
......
......@@ -24,6 +24,8 @@
#include "language/duchain/ducontext.h"
namespace KDevelop {
class DeclarationValidatorPrivate;
class KDEVPLATFORMTESTS_EXPORT DeclarationValidator
: public DUChainVisitor
{
......@@ -31,13 +33,14 @@ public:
DeclarationValidator();
~DeclarationValidator() override;
virtual bool testsPassed();
virtual bool testsPassed() const;
void visit(DUContext*) override;
void visit(Declaration* declaration) override;
private:
Q_DISABLE_COPY(DeclarationValidator)
const QScopedPointer<class DeclarationValidatorPrivate> d;
const QScopedPointer<class DeclarationValidatorPrivate> d_ptr;
Q_DECLARE_PRIVATE(DeclarationValidator)
};
}
#endif //KDEVPLATFORM_DECLARATIONVALIDATOR_H
......@@ -41,17 +41,17 @@ public:
DelayedOutput::Delay::Delay(DelayedOutput* output)
{
m_output = output;
++m_output->d->delayDepth;
++m_output->d_func()->delayDepth;
}
DelayedOutput::Delay::~Delay()
{
--m_output->d->delayDepth;
if (!m_output->d->delayDepth)
m_output->d->flushOutput();
--m_output->d_func()->delayDepth;
if (!m_output->d_func()->delayDepth)
m_output->d_func()->flushOutput();
}
DelayedOutput::DelayedOutput()
: d(new DelayedOutputPrivate())
: d_ptr(new DelayedOutputPrivate())
{
}
DelayedOutput::~DelayedOutput()
......@@ -64,6 +64,8 @@ DelayedOutput& DelayedOutput::self()
}
void DelayedOutput::push(const QString& output)
{
Q_D(DelayedOutput);
d->output.push(DepthedOutput(output, d->delayDepth));
}
}
......@@ -24,6 +24,8 @@
#include <QScopedPointer>
namespace KDevelop {
class DelayedOutputPrivate;
///Used to invert and visually nest error output generated by nested/recursive functions
///Used in TestSuite.h, use only at your own, singleton educated risk
class KDEVPLATFORMTESTS_EXPORT DelayedOutput
......@@ -45,7 +47,8 @@ private:
private:
DelayedOutput();
Q_DISABLE_COPY(DelayedOutput)
const QScopedPointer<class DelayedOutputPrivate> d;
const QScopedPointer<class DelayedOutputPrivate> d_ptr;
Q_DECLARE_PRIVATE(DelayedOutput)
};
}
......
......@@ -90,8 +90,10 @@ public:
TestFile::TestFile(const QString& contents, const QString& fileExtension,
TestProject* project, const QString& dir)
: d(new TestFilePrivate())
: d_ptr(new TestFilePrivate())
{
Q_D(TestFile);
d->suffix = QLatin1Char('.') + fileExtension;
QTemporaryFile file((!dir.isEmpty() ? dir : QDir::tempPath()) + QLatin1String("/testfile_XXXXXX") + d->suffix);
......@@ -103,18 +105,22 @@ TestFile::TestFile(const QString& contents, const QString& fileExtension,
}
TestFile::TestFile(const QString& contents, const QString& fileExtension, const TestFile* base)
: d(new TestFilePrivate)
: d_ptr(new TestFilePrivate)
{
QString fileName = base->d->file.mid(0, base->d->file.length() - base->d->suffix.length());
Q_D(TestFile);
QString fileName = base->d_func()->file.mid(0, base->d_func()->file.length() - base->d_func()->suffix.length());
d->suffix = QLatin1Char('.') + fileExtension;
fileName += d->suffix;
d->init(fileName, contents, base->d->project);
d->init(fileName, contents, base->d_func()->project);
}
TestFile::TestFile(const QString& contents, const QString& fileExtension, const QString& fileName,
KDevelop::TestProject* project, const QString& dir)
: d(new TestFilePrivate)
: d_ptr(new TestFilePrivate)
{
Q_D(TestFile);
d->suffix = QLatin1Char('.') + fileExtension;
const QString file = (!dir.isEmpty() ? dir : QDir::tempPath())
+ QLatin1Char('/') + fileName + d->suffix;
......@@ -124,6 +130,8 @@ TestFile::TestFile(const QString& contents, const QString& fileExtension, const
TestFile::~TestFile()
{
Q_D(TestFile);
if (auto* document = ICore::self()->documentController()->documentForUrl(d->url.toUrl())) {
document->close(KDevelop::IDocument::Discard);
}
......@@ -141,11 +149,15 @@ TestFile::~TestFile()
IndexedString TestFile::url() const
{
Q_D(const TestFile);
return d->url;
}
void TestFile::parse(TopDUContext::Features features, int priority)
{
Q_D(TestFile);
d->ready = false;
DUChain::self()->updateContextForUrl(d->url, features, this, priority);
}
......@@ -158,6 +170,8 @@ bool TestFile::parseAndWait(TopDUContext::Features features, int priority, int t
bool TestFile::waitForParsed(int timeout)
{
Q_D(TestFile);
if (!d->ready) {
// optimize: we don't want to wait the usual timeout before parsing documents here
ICore::self()->languageController()->backgroundParser()->parseDocuments();
......@@ -172,22 +186,30 @@ bool TestFile::waitForParsed(int timeout)
bool TestFile::isReady() const
{
Q_D(const TestFile);
return d->ready;
}
ReferencedTopDUContext TestFile::topContext()
{
Q_D(TestFile);
waitForParsed();
return d->topContext;
}
void TestFile::setFileContents(const QString& contents)
{
Q_D(TestFile);
d->setFileContents(contents);
}
QString TestFile::fileContents() const
{
Q_D(const TestFile);
QFile file(d->file);
file.open(QIODevice::ReadOnly);
Q_ASSERT(file.isOpen());
......@@ -197,11 +219,15 @@ QString TestFile::fileContents() const
void TestFile::setKeepDUChainData(bool keep)
{
Q_D(TestFile);
d->keepDUChainData = keep;
}
bool TestFile::keepDUChainData()
bool TestFile::keepDUChainData() const
{
Q_D(const TestFile);
return d->keepDUChainData;
}
......
......@@ -29,6 +29,7 @@
namespace KDevelop {
class TestProject;
class TestFilePrivate;
/**
* Helper file to parse a file using the full KDevelop architecture.
......@@ -170,12 +171,13 @@ public:
* By default the DUChain data is removed on destruction of the TestFile.
*/
void setKeepDUChainData(bool keep);
bool keepDUChainData();
bool keepDUChainData() const;
private:
const QScopedPointer<class TestFilePrivate> d;
const QScopedPointer<class TestFilePrivate> d_ptr;
Q_DECLARE_PRIVATE(TestFile)
Q_PRIVATE_SLOT(d, void updateReady(const KDevelop::IndexedString& url, KDevelop::ReferencedTopDUContext topContext))
Q_PRIVATE_SLOT(d_func(), void updateReady(const KDevelop::IndexedString& url, KDevelop::ReferencedTopDUContext topContext))
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment