@@ -2344,6 +2344,24 @@ void TestQgsProcessing::parameterLayer()
23442344 QCOMPARE ( fromCode->description (), QStringLiteral ( " optional" ) );
23452345 QCOMPARE ( fromCode->flags (), def->flags () );
23462346 QCOMPARE ( fromCode->defaultValue (), def->defaultValue () );
2347+
2348+ // check if can manage QgsProcessingOutputLayerDefinition
2349+ // as QVariat value in parameters (e.g. coming from an input of
2350+ // another algorithm)
2351+
2352+ // all ok
2353+ def.reset ( new QgsProcessingParameterMapLayer ( " non_optional" , QString (), r1->id (), true ) );
2354+ QString sink_name ( r1->id () );
2355+ QgsProcessingOutputLayerDefinition val ( sink_name );
2356+ params.insert ( " non_optional" , QVariant::fromValue ( val ) );
2357+ QCOMPARE ( QgsProcessingParameters::parameterAsLayer ( def.get (), params, context )->id (), r1->id () );
2358+
2359+ // not ok, e.g. source name is not a layer and it's not possible to generate a layer from it source
2360+ def.reset ( new QgsProcessingParameterMapLayer ( " non_optional" , QString (), r1->id (), true ) );
2361+ sink_name = QString ( " i'm not a layer, and nothing you can do will make me one" );
2362+ QgsProcessingOutputLayerDefinition val2 ( sink_name );
2363+ params.insert ( " non_optional" , QVariant::fromValue ( val2 ) );
2364+ QVERIFY ( !QgsProcessingParameters::parameterAsLayer ( def.get (), params, context ) );
23472365}
23482366
23492367void TestQgsProcessing::parameterExtent ()
0 commit comments