Skip to content

Commit

Permalink
creating new autotests for photoRenaming
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Jun 24, 2024
1 parent aafd2f6 commit b71a9d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions app/test/testattributecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,47 +697,56 @@ void TestAttributeController::testFieldsOutsideForm()

void TestAttributeController::testPhotoRenaming()
{
QString projectName = QStringLiteral( "testPhotoRenaming" );
QString projectDir = QDir::tempPath() + "/" + projectName;
QString projectFileName = "project.qgz";
QString projectName = QStringLiteral( "testPhotoRenaming" );
QString projectDir = QDir::tempPath() + "/" + projectName;
QString projectFileName = "project.qgz";

QDir tempDir( projectDir );
tempDir.removeRecursively();
QDir tempDir( projectDir );
tempDir.removeRecursively();

InputUtils::cpDir( TestUtils::testDataDir() + "/test_photo_rename", projectDir );
InputUtils::cpDir( TestUtils::testDataDir() + "/test_photo_rename", projectDir );

QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo2.jpg" ) ) );
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/default_photo_naming.jpg" ) ) );

QVERIFY( QgsProject::instance()->read( projectDir + QStringLiteral( "/test_photo_rename.qgz" ) ) );
QVERIFY( QgsProject::instance()->read( projectDir + QStringLiteral( "/test_photo_rename.qgz" ) ) );

QgsMapLayer *layer = QgsProject::instance()->mapLayersByName( QStringLiteral( "Survey" ) ).at( 0 );
QgsVectorLayer *surveyLayer = static_cast<QgsVectorLayer *>( layer );
QgsMapLayer *layer = QgsProject::instance()->mapLayersByName( QStringLiteral( "Survey" ) ).at( 0 );
QgsVectorLayer *surveyLayer = static_cast<QgsVectorLayer *>( layer );

QVERIFY( surveyLayer && surveyLayer->isValid() );
QVERIFY( surveyLayer && surveyLayer->isValid() );

QgsFeature feat;
feat.setValid( true );
feat.setFields( surveyLayer->fields(), true );
FeatureLayerPair pair( feat, surveyLayer );
QgsFeature feat;
feat.setValid( true );
feat.setFields( surveyLayer->fields(), true );
FeatureLayerPair pair( feat, surveyLayer );

AttributeController controller;
controller.setFeatureLayerPair( pair );
AttributeController controller;
controller.setFeatureLayerPair( pair );

const TabItem *tab = controller.tabItem( 0 );
const QVector<QUuid> items = tab->formItems();
QCOMPARE( items.size(), 4 );

controller.setFormValue( items.at( 2 ), QStringLiteral( "test" ) );
controller.setFormValue( items.at( 3 ), QStringLiteral( "photo.jpg" ) );
controller.setFormValue( items.at( 4 ), QStringLiteral( "photo_with_slash.jpg" ) );
controller.save();

QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo_default_value.jpg" ) ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 3 ), QStringLiteral( "image_test.jpg" ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 4 ), QStringLiteral( "photo_default_value.jpg" ) );
const TabItem *tab = controller.tabItem( 0 );
const QVector<QUuid> items = tab->formItems();
QCOMPARE( items.size(), 5 );

QgsFields fields = surveyLayer->fields();
for (int i = 0; i < fields.count(); ++i) {
qDebug() << "Field" << i << ":" << fields.at(i).name() << "Type:" << fields.at(i).typeName();
}

controller.setFormValue( items.at( 2 ), QStringLiteral( "test" ) );
controller.setFormValue( items.at( 3 ), QStringLiteral( "photo.jpg" ) );
controller.setFormValue( items.at( 4 ), QStringLiteral( "photo2.jpg" ) );
controller.save();
qDebug() << "PROJECT DIR: " << projectDir;
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 3 ), QStringLiteral( "image_test.jpg" ) );

QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photo2.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/default_photo_naming.jpg" ) ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 4 ), QStringLiteral( "default_photo_naming.jpg" ) );
}

void TestAttributeController::testHtmlAndTextWidgets()
Expand Down
Binary file modified test/test_data/test_photo_rename/Survey_points.gpkg
Binary file not shown.
Binary file added test/test_data/test_photo_rename/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test_data/test_photo_rename/test_photo_rename.qgz
Binary file not shown.

1 comment on commit b71a9d6

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 24.6.635911 just submitted!

Please sign in to comment.