[contextualprocess] Improve tests, fix off-by-one

- there's no string representation for a QVariantMap, so it
  won't be converted; in *debug* output it looks like there's a
  string there.
- off-by-one when diving into compound selectors, spotted by
  test, now fixed.
This commit is contained in:
Adriaan de Groot 2020-02-27 22:44:49 +01:00
parent 28bf4082b3
commit 72dcf886bf
2 changed files with 4 additions and 2 deletions

View File

@ -77,7 +77,7 @@ fetch( QString& value, QStringList& selector, int index, const QVariant& v )
} }
const QVariantMap map = v.toMap(); const QVariantMap map = v.toMap();
const QString& key = selector.at( index ); const QString& key = selector.at( index );
if ( index == selector.length() ) if ( index == selector.length() - 1)
{ {
value = map.value( key ).toString(); value = map.value( key ).toString();
return map.contains( key ); return map.contains( key );

View File

@ -88,6 +88,8 @@ ContextualProcessTests::testProcessListSampleConfig()
void ContextualProcessTests::testFetch() void ContextualProcessTests::testFetch()
{ {
Logger::setupLogLevel( Logger::LOGVERBOSE );
QVariantMap m; QVariantMap m;
// Some keys without sub-map // Some keys without sub-map
m.insert( QStringLiteral( "carrot" ), true ); m.insert( QStringLiteral( "carrot" ), true );
@ -150,7 +152,7 @@ void ContextualProcessTests::testFetch()
ContextualProcessBinding b( QStringLiteral( "berries" ) ); ContextualProcessBinding b( QStringLiteral( "berries" ) );
QString s; QString s;
QVERIFY( b.fetch( gs, s ) ); QVERIFY( b.fetch( gs, s ) );
QVERIFY( s.contains( QStringLiteral( "QVariant" ) ) ); QVERIFY( s.isEmpty() ); // No string representation
} }
{ {
// Compound lookup // Compound lookup