Skip to content

Commit

Permalink
Test rendered legend image (with label entry) against reference image
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed May 13, 2021
1 parent b46fb25 commit f12dfad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/src/core/testqgslegendrenderer.cpp
Expand Up @@ -205,7 +205,8 @@ class TestQgsLegendRenderer : public QObject
void testBasicJson();
void testOpacityJson();
void testBigMarkerJson();
void testLabelLegendJson();

void testLabelLegend();

private:
QgsLayerTree *mRoot = nullptr;
Expand Down Expand Up @@ -1546,8 +1547,9 @@ void TestQgsLegendRenderer::testBigMarkerJson()
QVERIFY( _verifyImage( test_name, mReport, 50 ) );
}

void TestQgsLegendRenderer::testLabelLegendJson()
void TestQgsLegendRenderer::testLabelLegend()
{
const QString testName( "test_label_legend" );
QgsPalLayerSettings *labelSettings = new QgsPalLayerSettings();
labelSettings->fieldName = QStringLiteral( "test_attr" );
QgsRuleBasedLabeling::Rule *rootRule = new QgsRuleBasedLabeling::Rule( nullptr ); //root rule
Expand All @@ -1569,17 +1571,23 @@ void TestQgsLegendRenderer::testLabelLegendJson()
QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings;

//first test if label legend nodes are present in json
const QJsonObject json = _renderJsonLegend( &legendModel, settings );
const QJsonArray nodes = json["nodes"].toArray();
const QJsonObject point_layer = nodes[1].toObject();
const QJsonArray point_layer_symbols = point_layer["symbols"].toArray();
const QJsonObject point_layer_labeling_symbol = point_layer_symbols[3].toObject();
QString labelTitle = point_layer_labeling_symbol["title"].toString();

QVERIFY( labelTitle == "labelingRule" );

//test rendered legend agains reference image
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
_renderLegend( testName, &legendModel, settings );
QVERIFY( _verifyImage( testName, mReport ) );

vLayerLegend->setShowLabelLegend( bkLabelLegendEnabled );
mVL3->setLabelsEnabled( bkLabelsEnabled );

QVERIFY( labelTitle == "labelingRule" );
}


Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f12dfad

Please sign in to comment.