Navigation Menu

Skip to content

Commit

Permalink
Unit tests for extract binary algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 12, 2018
1 parent 62bdc28 commit a192dab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/analysis/processing/qgsalgorithmextractbinary.cpp
Expand Up @@ -32,7 +32,9 @@ QString QgsExtractBinaryFieldAlgorithm::displayName() const

QString QgsExtractBinaryFieldAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm extracts contents from a binary field, saving them to individual files." );
return QObject::tr( "This algorithm extracts contents from a binary field, saving them to individual files.\n\n"
"Filenames can be generated using data defined values, allowing them to be taken from"
"an attribute in the source table or based on a more complex expression." );
}

QString QgsExtractBinaryFieldAlgorithm::shortDescription() const
Expand Down
40 changes: 40 additions & 0 deletions tests/src/analysis/testqgsprocessingalgs.cpp
Expand Up @@ -47,6 +47,7 @@ class TestQgsProcessingAlgs: public QObject
void transformAlg();
void kmeansCluster();
void categorizeByStyle();
void extractBinary();

private:

Expand Down Expand Up @@ -628,6 +629,45 @@ void TestQgsProcessingAlgs::categorizeByStyle()
QCOMPARE( catRenderer->categories().at( catRenderer->categoryIndexForValue( QStringLiteral( "c " ) ) ).symbol()->color().name(), QStringLiteral( "#0000ff" ) );
}

void TestQgsProcessingAlgs::extractBinary()
{
std::unique_ptr< QgsProcessingAlgorithm > alg( QgsApplication::processingRegistry()->createAlgorithmById( QStringLiteral( "native:extractbinary" ) ) );
QVERIFY( alg != nullptr );

std::unique_ptr< QgsProcessingContext > context = qgis::make_unique< QgsProcessingContext >();
QgsProject p;
context->setProject( &p );

QString dataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
const QString source = dataDir + QStringLiteral( "/attachments.gdb|layername=points__ATTACH" );


QVariantMap parameters;
parameters.insert( QStringLiteral( "INPUT" ), source );
parameters.insert( QStringLiteral( "FIELD" ), QStringLiteral( "DATA" ) );
parameters.insert( QStringLiteral( "FILENAME" ), QgsProperty::fromExpression( QStringLiteral( "'test' || \"ATTACHMENTID\" || '.jpg'" ) ) );
const QString folder = QDir::tempPath();
parameters.insert( QStringLiteral( "FOLDER" ), folder );

bool ok = false;
QgsProcessingFeedback feedback;
QVariantMap results = alg->run( parameters, *context, &feedback, &ok );
QVERIFY( ok );

QCOMPARE( results.count(), 1 );
QCOMPARE( results.value( QStringLiteral( "FOLDER" ) ), folder );

QFile file( folder + "/test1.jpg" );
QVERIFY( file.open( QIODevice::ReadOnly ) );
QByteArray d = file.readAll();
QCOMPARE( QCryptographicHash::hash( d, QCryptographicHash::Md5 ).toHex(), QStringLiteral( "ef3dbc530cc39a545832a6c82aac57b6" ) );

QFile file2( folder + "/test2.jpg" );
QVERIFY( file2.open( QIODevice::ReadOnly ) );
d = file2.readAll();
QCOMPARE( QCryptographicHash::hash( d, QCryptographicHash::Md5 ).toHex(), QStringLiteral( "4b952b80e4288ca5111be2f6dd5d6809" ) );
}


QGSTEST_MAIN( TestQgsProcessingAlgs )
#include "testqgsprocessingalgs.moc"

0 comments on commit a192dab

Please sign in to comment.