MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / renderTest

Method renderTest

test/symbol_t.cpp:248–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246 }
247
248 void renderTest()
249 {
250 QFETCH(QString, map_filename);
251 QFETCH(qreal, pixel_per_mm);
252
253 Map map;
254 QVERIFY(map.loadFrom(map_filename));
255
256 // Don' test text symbols: text rendering requires more Qt GUI,
257 // and it depends on fonts and platforms.
258 for (auto i = 0; i < map.getNumSymbols(); ++i)
259 {
260 auto* symbol = map.getSymbol(i);
261 if (symbol && symbol->getType() == Symbol::Text)
262 symbol->setIsHelperSymbol(true);
263 }
264
265 const auto extent = map.calculateExtent().toAlignedRect().adjusted(-1, -1, +1, +1);
266
267 auto image = QImage{pixel_per_mm * extent.size(), QImage::Format_ARGB32_Premultiplied};
268 image.fill(QColor(Qt::white));
269
270 QPainter painter{&image};
271 painter.setRenderHint(QPainter::Antialiasing, false);
272 painter.scale(pixel_per_mm, pixel_per_mm);
273 painter.translate(-extent.topLeft());
274 painter.setClipRect(extent);
275 map.draw(&painter, RenderConfig{map, extent, pixel_per_mm, RenderConfig::DisableAntialiasing, 1});
276 painter.end();
277
278 auto image_filename = QFileInfo{map_filename}.absoluteFilePath();
279 image_filename.chop(4);
280 image_filename.append(QLatin1String{"png"});
281
282#ifdef MAPPER_DEVELOPMENT_BUILD
283 auto out_filename = image_filename;
284 out_filename.insert(image_filename.length() - 4, QLatin1String(".tmp"));
285 QVERIFY(image.save(out_filename, "PNG", 1));
286#endif
287
288 QVERIFY(QFileInfo::exists(image_filename));
289 QImage expected_image;
290 QVERIFY(expected_image.load(image_filename));
291 image = image.convertToFormat(expected_image.format());
292 QCOMPARE(fuzzyDifference(image, expected_image), QPoint(-1,-1));
293
294#ifdef MAPPER_DEVELOPMENT_BUILD
295 QVERIFY(QFile::remove(out_filename));
296#endif
297 }
298
299
300 void invariantTest_data()

Callers

nothing calls this directly

Calls 15

QLatin1StringClass · 0.85
existsFunction · 0.85
fuzzyDifferenceFunction · 0.85
getNumSymbolsMethod · 0.80
setIsHelperSymbolMethod · 0.80
fillMethod · 0.80
formatMethod · 0.80
QColorFunction · 0.50
QPointClass · 0.50
loadFromMethod · 0.45
getSymbolMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected