@@ -47,6 +47,7 @@ class TestQgsProcessingAlgs: public QObject
47
47
void transformAlg ();
48
48
void kmeansCluster ();
49
49
void categorizeByStyle ();
50
+ void extractBinary ();
50
51
51
52
private:
52
53
@@ -628,6 +629,45 @@ void TestQgsProcessingAlgs::categorizeByStyle()
628
629
QCOMPARE ( catRenderer->categories ().at ( catRenderer->categoryIndexForValue ( QStringLiteral ( " c " ) ) ).symbol ()->color ().name (), QStringLiteral ( " #0000ff" ) );
629
630
}
630
631
632
+ void TestQgsProcessingAlgs::extractBinary ()
633
+ {
634
+ std::unique_ptr< QgsProcessingAlgorithm > alg ( QgsApplication::processingRegistry ()->createAlgorithmById ( QStringLiteral ( " native:extractbinary" ) ) );
635
+ QVERIFY ( alg != nullptr );
636
+
637
+ std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
638
+ QgsProject p;
639
+ context->setProject ( &p );
640
+
641
+ QString dataDir ( TEST_DATA_DIR ); // defined in CmakeLists.txt
642
+ const QString source = dataDir + QStringLiteral ( " /attachments.gdb|layername=points__ATTACH" );
643
+
644
+
645
+ QVariantMap parameters;
646
+ parameters.insert ( QStringLiteral ( " INPUT" ), source );
647
+ parameters.insert ( QStringLiteral ( " FIELD" ), QStringLiteral ( " DATA" ) );
648
+ parameters.insert ( QStringLiteral ( " FILENAME" ), QgsProperty::fromExpression ( QStringLiteral ( " 'test' || \" ATTACHMENTID\" || '.jpg'" ) ) );
649
+ const QString folder = QDir::tempPath ();
650
+ parameters.insert ( QStringLiteral ( " FOLDER" ), folder );
651
+
652
+ bool ok = false ;
653
+ QgsProcessingFeedback feedback;
654
+ QVariantMap results = alg->run ( parameters, *context, &feedback, &ok );
655
+ QVERIFY ( ok );
656
+
657
+ QCOMPARE ( results.count (), 1 );
658
+ QCOMPARE ( results.value ( QStringLiteral ( " FOLDER" ) ), folder );
659
+
660
+ QFile file ( folder + " /test1.jpg" );
661
+ QVERIFY ( file.open ( QIODevice::ReadOnly ) );
662
+ QByteArray d = file.readAll ();
663
+ QCOMPARE ( QCryptographicHash::hash ( d, QCryptographicHash::Md5 ).toHex (), QStringLiteral ( " ef3dbc530cc39a545832a6c82aac57b6" ) );
664
+
665
+ QFile file2 ( folder + " /test2.jpg" );
666
+ QVERIFY ( file2.open ( QIODevice::ReadOnly ) );
667
+ d = file2.readAll ();
668
+ QCOMPARE ( QCryptographicHash::hash ( d, QCryptographicHash::Md5 ).toHex (), QStringLiteral ( " 4b952b80e4288ca5111be2f6dd5d6809" ) );
669
+ }
670
+
631
671
632
672
QGSTEST_MAIN ( TestQgsProcessingAlgs )
633
673
#include " testqgsprocessingalgs.moc"
0 commit comments