Test dealing with arbitrary config

This commit is contained in:
Martchus 2018-04-30 21:30:35 +02:00
parent 082eaa29b6
commit 819d37eeee
1 changed files with 34 additions and 0 deletions

View File

@ -77,6 +77,7 @@ public:
void testDisconnecting();
void testConnectingWithSettings();
void testRequestingRescan();
void testDealingWithArbitraryConfig();
void setUp();
void tearDown();
@ -228,6 +229,7 @@ void ConnectionTests::testConnection()
testDisconnecting();
testConnectingWithSettings();
testRequestingRescan();
testDealingWithArbitraryConfig();
}
void ConnectionTests::testErrorCases()
@ -573,3 +575,35 @@ void ConnectionTests::testRequestingRescan()
waitForSignals(bind(&SyncthingConnection::rescan, &m_connection, QStringLiteral("non-existing-dir"), QStringLiteral("sub/path")), 5000,
connectionSignal(&SyncthingConnection::error, errorHandler, &errorOccured));
}
void ConnectionTests::testDealingWithArbitraryConfig()
{
cerr << "\n - Changing arbitrary config ..." << endl;
// read some value, eg. options.relayReconnectIntervalM
auto rawConfig(m_connection.rawConfig());
auto optionsIterator(rawConfig.find(QLatin1String("options")));
CPPUNIT_ASSERT(optionsIterator != rawConfig.end());
auto optionsRef(optionsIterator.value());
CPPUNIT_ASSERT_EQUAL(QJsonValue::Object, optionsRef.type());
auto options(optionsRef.toObject());
CPPUNIT_ASSERT_EQUAL(10, options.value(QLatin1String("relayReconnectIntervalM")).toInt());
// change a value
options.insert(QLatin1String("relayReconnectIntervalM"), 75);
optionsRef = options;
// expect the change via newConfig() signal
bool hasNewConfig = false;
function<void(const QJsonObject &newConfig)> handleNewConfig([&hasNewConfig](const QJsonObject &newConfig) {
const auto newIntervall(newConfig.value(QLatin1String("options")).toObject().value(QLatin1String("relayReconnectIntervalM")).toInt());
if (newIntervall == 75) {
hasNewConfig = true;
}
});
// post new config
waitForSignalsOrFail(bind(&SyncthingConnection::postConfigFromJsonObject, &m_connection, ref(rawConfig)), 5000,
connectionSignal(&SyncthingConnection::error), connectionSignal(&SyncthingConnection::newConfigTriggered),
connectionSignal(&SyncthingConnection::newConfig, handleNewConfig, &hasNewConfig));
}