forked from qt-creator/qt-creator
CMake: Fix progress calculation in server-mode
Add unit test to make sure this stays fixed. Task-number: QTCREATORBUG-18624 Change-Id: Ieeb41982418481223d9ebf8f5c6ec4b3b78bfe00 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -61,6 +61,9 @@ private slots:
|
|||||||
|
|
||||||
void testCMakeProjectImporterToolChain_data();
|
void testCMakeProjectImporterToolChain_data();
|
||||||
void testCMakeProjectImporterToolChain();
|
void testCMakeProjectImporterToolChain();
|
||||||
|
|
||||||
|
void testServerModeReaderProgress_data();
|
||||||
|
void testServerModeReaderProgress();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -406,8 +406,7 @@ void ServerModeReader::handleProgress(int min, int cur, int max, const QString &
|
|||||||
|
|
||||||
if (!m_future)
|
if (!m_future)
|
||||||
return;
|
return;
|
||||||
int progress = m_progressStepMinimum
|
const int progress = calculateProgress(m_progressStepMinimum, min, cur, max, m_progressStepMaximum);
|
||||||
+ (((max - min) / (cur - min)) * (m_progressStepMaximum - m_progressStepMinimum));
|
|
||||||
m_future->setProgressValue(progress);
|
m_future->setProgressValue(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,6 +418,14 @@ void ServerModeReader::handleSignal(const QString &signal, const QVariantMap &da
|
|||||||
emit dirty();
|
emit dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ServerModeReader::calculateProgress(const int minRange, const int min, const int cur, const int max, const int maxRange)
|
||||||
|
{
|
||||||
|
if (minRange == maxRange || min == max)
|
||||||
|
return minRange;
|
||||||
|
const int clampedCur = std::min(std::max(cur, min), max);
|
||||||
|
return minRange + ((clampedCur - min) / (max - min)) * (maxRange - minRange);
|
||||||
|
}
|
||||||
|
|
||||||
void ServerModeReader::extractCodeModelData(const QVariantMap &data)
|
void ServerModeReader::extractCodeModelData(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
const QVariantList configs = data.value("configurations").toList();
|
const QVariantList configs = data.value("configurations").toList();
|
||||||
@@ -771,3 +778,59 @@ void ServerModeReader::addHeaderNodes(ProjectNode *root, const QList<FileNode *>
|
|||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CMakeProjectManager
|
} // namespace CMakeProjectManager
|
||||||
|
|
||||||
|
#if defined(WITH_TESTS)
|
||||||
|
|
||||||
|
#include "cmakeprojectplugin.h"
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
namespace CMakeProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
void CMakeProjectPlugin::testServerModeReaderProgress_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<int>("minRange");
|
||||||
|
QTest::addColumn<int>("min");
|
||||||
|
QTest::addColumn<int>("cur");
|
||||||
|
QTest::addColumn<int>("max");
|
||||||
|
QTest::addColumn<int>("maxRange");
|
||||||
|
QTest::addColumn<int>("expected");
|
||||||
|
|
||||||
|
QTest::newRow("empty range") << 100 << 10 << 11 << 20 << 100 << 100;
|
||||||
|
QTest::newRow("one range (low)") << 0 << 10 << 11 << 20 << 1 << 0;
|
||||||
|
QTest::newRow("one range (high)") << 20 << 10 << 19 << 20 << 20 << 20;
|
||||||
|
QTest::newRow("large range") << 30 << 10 << 11 << 20 << 100000 << 30;
|
||||||
|
|
||||||
|
QTest::newRow("empty progress") << -5 << 10 << 10 << 10 << 99995 << -5;
|
||||||
|
QTest::newRow("one progress (low)") << 42 << 10 << 10 << 11 << 100042 << 42;
|
||||||
|
QTest::newRow("one progress (high)") << 0 << 10 << 11 << 11 << 100000 << 100000;
|
||||||
|
QTest::newRow("large progress") << 0 << 10 << 10 << 11 << 100000 << 0;
|
||||||
|
|
||||||
|
QTest::newRow("cur too low") << 0 << 10 << 9 << 100 << 100000 << 0;
|
||||||
|
QTest::newRow("cur too high") << 0 << 10 << 101 << 100 << 100000 << 100000;
|
||||||
|
QTest::newRow("cur much too low") << 0 << 10 << -1000 << 100 << 100000 << 0;
|
||||||
|
QTest::newRow("cur much too high") << 0 << 10 << 1110000 << 100 << 100000 << 100000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeProjectPlugin::testServerModeReaderProgress()
|
||||||
|
{
|
||||||
|
QFETCH(int, minRange);
|
||||||
|
QFETCH(int, min);
|
||||||
|
QFETCH(int, cur);
|
||||||
|
QFETCH(int, max);
|
||||||
|
QFETCH(int, maxRange);
|
||||||
|
QFETCH(int, expected);
|
||||||
|
|
||||||
|
ServerModeReader reader;
|
||||||
|
const int r = reader.calculateProgress(minRange, min, cur, max, maxRange);
|
||||||
|
|
||||||
|
QCOMPARE(r, expected);
|
||||||
|
|
||||||
|
QVERIFY(r <= maxRange);
|
||||||
|
QVERIFY(r >= minRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace CMakeProjectManager
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@@ -67,6 +67,10 @@ private:
|
|||||||
void handleProgress(int min, int cur, int max, const QString &inReplyTo);
|
void handleProgress(int min, int cur, int max, const QString &inReplyTo);
|
||||||
void handleSignal(const QString &signal, const QVariantMap &data);
|
void handleSignal(const QString &signal, const QVariantMap &data);
|
||||||
|
|
||||||
|
int calculateProgress(const int minRange, const int min,
|
||||||
|
const int cur,
|
||||||
|
const int max, const int maxRange);
|
||||||
|
|
||||||
struct Target;
|
struct Target;
|
||||||
struct Project;
|
struct Project;
|
||||||
|
|
||||||
@@ -151,6 +155,10 @@ private:
|
|||||||
QList<FileGroup *> m_fileGroups;
|
QList<FileGroup *> m_fileGroups;
|
||||||
|
|
||||||
CMakeParser m_parser;
|
CMakeParser m_parser;
|
||||||
|
|
||||||
|
#if defined(WITH_TESTS)
|
||||||
|
friend class CMakeProjectPlugin;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user