Commit 41127e0f authored by Eike Ziller's avatar Eike Ziller

Merge remote-tracking branch 'origin/4.3' into 4.4

Change-Id: I4e14ef31dc6cdcc0606d39be90195e30c1ee9b25
parents 3881ff94 336f54de
......@@ -61,6 +61,9 @@ private slots:
void testCMakeProjectImporterToolChain_data();
void testCMakeProjectImporterToolChain();
void testServerModeReaderProgress_data();
void testServerModeReaderProgress();
#endif
private:
......
......@@ -414,8 +414,7 @@ void ServerModeReader::handleProgress(int min, int cur, int max, const QString &
if (!m_future)
return;
int progress = m_progressStepMinimum
+ (((max - min) / (cur - min)) * (m_progressStepMaximum - m_progressStepMinimum));
const int progress = calculateProgress(m_progressStepMinimum, min, cur, max, m_progressStepMaximum);
m_future->setProgressValue(progress);
}
......@@ -427,6 +426,14 @@ void ServerModeReader::handleSignal(const QString &signal, const QVariantMap &da
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)
{
const QVariantList configs = data.value("configurations").toList();
......@@ -779,3 +786,59 @@ void ServerModeReader::addHeaderNodes(ProjectNode *root, const QList<FileNode *>
} // namespace Internal
} // 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 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 Project;
......@@ -151,6 +155,10 @@ private:
QList<FileGroup *> m_fileGroups;
CMakeParser m_parser;
#if defined(WITH_TESTS)
friend class CMakeProjectPlugin;
#endif
};
} // namespace Internal
......
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