Commit f9c87824 authored by Roman Gilg's avatar Roman Gilg

[libcolorcorrect] Fix Night Color tests

parent b99cbb7b
......@@ -53,63 +53,80 @@ QHash<QString, QVariant> kwin_dbus::nightColorInfo()
QHash<QString, QVariant> kwin_dbus::getData()
{
QHash<QString, QVariant> ret;
ret["Available"] = nightColorAvailable;
return QHash<QString, QVariant> {
{ QStringLiteral("Available"), nightColorAvailable },
ret["ActiveEnabled"] = activeEnabled;
ret["Active"] = active;
{ QStringLiteral("ActiveEnabled"), activeEnabled },
{ QStringLiteral("Active"), active },
ret["ModeEnabled"] = modeEnabled;
ret["Mode"] = mode;
{ QStringLiteral("ModeEnabled"), modeEnabled },
{ QStringLiteral("Mode"), mode },
ret["NightTemperatureEnabled"] = nightTemperatureEnabled;
ret["NightTemperature"] = nightTemperature;
{ QStringLiteral("NightTemperatureEnabled"), nightTemperatureEnabled },
{ QStringLiteral("NightTemperature"), nightTemperature },
ret["Running"] = running;
ret["CurrentColorTemperature"] = currentColorTemperature;
{ QStringLiteral("Running"), running },
{ QStringLiteral("CurrentColorTemperature"), currentColorTemperature },
ret["LatitudeAuto"] = latitudeAuto;
ret["LongitudeAuto"] = longitudeAuto;
{ QStringLiteral("LatitudeAuto"), latitudeAuto },
{ QStringLiteral("LongitudeAuto"), longitudeAuto },
ret["LocationEnabled"] = locationEnabled;
ret["LatitudeFixed"] = latitudeFixed;
ret["LongitudeFixed"] = longitudeFixed;
{ QStringLiteral("LocationEnabled"), locationEnabled },
{ QStringLiteral("LatitudeFixed"), latitudeFixed },
{ QStringLiteral("LongitudeFixed"), longitudeFixed },
ret["TimingsEnabled"] = timingsEnabled;
ret["MorningBeginFixed"] = morningBeginFixed.toString(Qt::ISODate);
ret["EveningBeginFixed"] = eveningBeginFixed.toString(Qt::ISODate);
ret["TransitionTime"] = transitionTime;
return ret;
{ QStringLiteral("TimingsEnabled"), timingsEnabled },
{ QStringLiteral("MorningBeginFixed"), morningBeginFixed.toString(Qt::ISODate) },
{ QStringLiteral("EveningBeginFixed"), eveningBeginFixed.toString(Qt::ISODate) },
{ QStringLiteral("TransitionTime"), transitionTime },
};
}
bool kwin_dbus::nightColorConfigChange(QHash<QString, QVariant> data)
bool kwin_dbus::setNightColorConfig(QHash<QString, QVariant> data)
{
if (!configChangeExpectSuccess) {
return false;
}
bool hasChanged = false;
if (data.contains("Active")) {
active = data["Active"].toBool();
auto val = data["Active"].toBool();
hasChanged |= active != val;
active = val;
}
if (data.contains("Mode")) {
mode = data["Mode"].toInt();
auto val = data["Mode"].toInt();
hasChanged |= mode != val;
mode = val;
}
if (data.contains("NightTemperature")) {
nightTemperature = data["NightTemperature"].toInt();
auto val = data["NightTemperature"].toInt();
hasChanged |= nightTemperature != val;
nightTemperature = val;
}
if (data.contains("LatitudeFixed")) {
latitudeFixed = data["LatitudeFixed"].toDouble();
longitudeFixed = data["LongitudeFixed"].toDouble();
auto valLat = data["LatitudeFixed"].toDouble();
auto valLng = data["LongitudeFixed"].toDouble();
hasChanged |= latitudeFixed != valLat || longitudeFixed != valLng;
latitudeFixed = valLat;
longitudeFixed = valLng;
}
if (data.contains("MorningBeginFixed")) {
morningBeginFixed = QTime::fromString(data["MorningBeginFixed"].toString(), Qt::ISODate);
eveningBeginFixed = QTime::fromString(data["EveningBeginFixed"].toString(), Qt::ISODate);
transitionTime = data["TransitionTime"].toInt();
auto valMbf = QTime::fromString(data["MorningBeginFixed"].toString(), Qt::ISODate);
auto valEbf = QTime::fromString(data["EveningBeginFixed"].toString(), Qt::ISODate);
auto valTrT = data["TransitionTime"].toInt();
hasChanged |= morningBeginFixed != valMbf || eveningBeginFixed != valEbf
|| transitionTime != valTrT;
morningBeginFixed = valMbf;
eveningBeginFixed = valEbf;
transitionTime = valTrT;
}
running = active;
emit nightColorConfigChangeSignal(getData());
if (hasChanged) {
emit nightColorConfigChanged(getData());
}
return true;
}
......@@ -118,5 +135,5 @@ void kwin_dbus::nightColorAutoLocationUpdate(double latitude, double longitude)
latitudeAuto = latitude;
longitudeAuto = longitude;
emit nightColorConfigChangeSignal(getData());
emit nightColorConfigChanged(getData());
}
......@@ -67,11 +67,11 @@ public:
public Q_SLOTS:
QHash<QString, QVariant> nightColorInfo();
bool nightColorConfigChange(QHash<QString, QVariant> data);
bool setNightColorConfig(QHash<QString, QVariant> data);
void nightColorAutoLocationUpdate(double latitude, double longitude);
Q_SIGNALS:
void nightColorConfigChangeSignal(QHash<QString, QVariant> data);
void nightColorConfigChanged(QHash<QString, QVariant> data);
private:
QHash<QString, QVariant> getData();
......
......@@ -104,16 +104,16 @@ void TestNightColor::testStageData_data()
QTest::addColumn<int>("transitionTime");
QTest::addColumn<bool>("isChange");
QTest::addColumn<bool>("isChangeAll");
QTest::addColumn<bool>("changeExpectFailure");
QTest::addColumn<bool>("expectChangeSuccess");
QTest::newRow("noChange") << true << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << false << false << false;
QTest::newRow("wrongChange") << true << 0 << 9001 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true;
QTest::newRow("temperature") << true << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false;
QTest::newRow("deactivate+temperature") << false << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false;
QTest::newRow("location+differentMode") << true << 2 << 0 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false;
QTest::newRow("time+defaultMode") << true << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << false << true << false;
QTest::newRow("location+mode") << true << 1 << DEFAULT_NIGHT_TEMPERATURE << 50. << -20. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false;
QTest::newRow("time+mode") << false << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << true << true << false;
QTest::newRow("wrongChange") << true << 0 << 9001 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << false;
QTest::newRow("temperature") << true << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true;
QTest::newRow("deactivate+temperature") << false << 0 << 1000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true;
QTest::newRow("location+differentMode") << true << 2 << 0 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true;
QTest::newRow("time+defaultMode") << true << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << false << true << true;
QTest::newRow("location+mode") << true << 1 << DEFAULT_NIGHT_TEMPERATURE << 50. << -20. << QTime(6,0,0) << QTime(18,0,0) << FALLBACK_SLOW_UPDATE_TIME << true << true << true;
QTest::newRow("time+mode") << false << 0 << DEFAULT_NIGHT_TEMPERATURE << 0. << 0. << QTime(10,0,0) << QTime(20,0,0) << 1 << true << true << true;
}
void TestNightColor::testStageData()
......@@ -128,17 +128,15 @@ void TestNightColor::testStageData()
QFETCH(int, transitionTime);
QFETCH(bool, isChange);
QFETCH(bool, isChangeAll);
QFETCH(bool, changeExpectFailure);
QFETCH(bool, expectChangeSuccess);
setCompBackToDefault();
m_comp->configChangeExpectSuccess = !changeExpectFailure;
m_comp->configChangeExpectSuccess = expectChangeSuccess;
CompositorAdaptor *aptr = new CompositorAdaptor(this);
QSignalSpy *dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated()));
QVERIFY(dataUpdateSpy->isValid());
QCOMPARE(aptr->checkStaged(), false);
QCOMPARE(aptr->checkStagedAll(), false);
QVERIFY(!aptr->checkStaged());
QVERIFY(!aptr->checkStagedAll());
auto setAdaptorStaged = [&aptr,
&active, &mode, &nightTemperature,
......@@ -157,12 +155,15 @@ void TestNightColor::testStageData()
QCOMPARE(aptr->checkStaged(), isChange);
QCOMPARE(aptr->checkStagedAll(), isChangeAll);
QSignalSpy *dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated()));
QVERIFY(dataUpdateSpy->isValid());
// send config relative to active and mode state
aptr->sendConfiguration();
// give dbus communication time
QTest::qWait(300);
QCOMPARE(dataUpdateSpy->isEmpty(), changeExpectFailure);
QCOMPARE(aptr->checkStaged(), changeExpectFailure);
QCOMPARE(dataUpdateSpy->isEmpty(), !expectChangeSuccess || !isChange);
QCOMPARE(aptr->checkStaged(), !expectChangeSuccess && isChange);
// reset compositor and adaptor - now send all data at once
setCompBackToDefault();
......@@ -171,8 +172,8 @@ void TestNightColor::testStageData()
dataUpdateSpy = new QSignalSpy(aptr, SIGNAL(dataUpdated()));
QVERIFY(dataUpdateSpy->isValid());
QCOMPARE(aptr->checkStaged(), false);
QCOMPARE(aptr->checkStagedAll(), false);
QVERIFY(!aptr->checkStaged());
QVERIFY(!aptr->checkStagedAll());
setAdaptorStaged();
QCOMPARE(aptr->checkStaged(), isChange);
......@@ -181,9 +182,9 @@ void TestNightColor::testStageData()
aptr->sendConfigurationAll();
// give dbus communication time
QTest::qWait(300);
QCOMPARE(dataUpdateSpy->isEmpty(), changeExpectFailure);
QCOMPARE(aptr->checkStaged(), changeExpectFailure);
QCOMPARE(aptr->checkStagedAll(), changeExpectFailure);
QCOMPARE(dataUpdateSpy->isEmpty(), !expectChangeSuccess || !isChangeAll);
QCOMPARE(aptr->checkStaged(), !expectChangeSuccess && isChange);
QCOMPARE(aptr->checkStagedAll(), !expectChangeSuccess && isChangeAll);
}
void TestNightColor::testAutoLocationUpdate()
......
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