Skip to content
Permalink
Browse files

[GRASS] edit test fixed for GRASS 6

  • Loading branch information
blazek committed Oct 13, 2015
1 parent 4bd6cf1 commit 9556a760dac8aca1e2ceaee84352a0cd979e96ad
Showing with 26 additions and 44 deletions.
  1. +9 −33 src/providers/grass/qgsgrassvectormaplayer.cpp
  2. +17 −11 tests/src/providers/grass/testqgsgrassprovider.cpp
@@ -983,49 +983,25 @@ void QgsGrassVectorMapLayer::deleteAttribute( int cat, QString &error )
bool QgsGrassVectorMapLayer::recordExists( int cat, QString &error )
{
QgsDebugMsg( QString( "mField = %1 cat = %2" ).arg( mField ).arg( cat ) );
bool exists = false;
if ( !mDriver )
{
error = tr( "Driver is not open" );
QgsDebugMsg( error );
return false;
}

QgsDebugMsg( "Database opened -> select record" );
QgsDebugMsg( "Database open -> select record" );

dbString dbstr;
db_init_string( &dbstr );

QString query = QString( "SELECT count(*) FROM %1 WHERE %2 = %3" ).arg( mFieldInfo->table ).arg( mFieldInfo->key ).arg( cat );
db_set_string( &dbstr, query.toLatin1().data() );

QgsDebugMsg( QString( "SQL: %1" ).arg( db_get_string( &dbstr ) ) );

dbCursor cursor;
if ( db_open_select_cursor( mDriver, &dbstr, &cursor, DB_SCROLL ) != DB_OK )
{
error = tr( "Cannot query database: %1" ).arg( query );
}
else
// DBF driver in GRASS does not support count(*)
dbValue value;
int nValues = db_select_value(mDriver, mFieldInfo->table, mFieldInfo->key, cat, mFieldInfo->key, &value);
if ( nValues == -1)
{
int more;
if ( db_fetch( &cursor, DB_NEXT, &more ) != DB_OK )
{
error = tr( "Cannot fetch DB record" );
}
else
{
dbTable *table = db_get_cursor_table( &cursor );
dbColumn *column = db_get_table_column( table, 0 );
dbValue *value = db_get_column_value( column );
int count = db_get_value_int( value );
QgsDebugMsg( QString( "count = %1" ).arg( count ) );
exists = count > 0;
}
db_close_cursor( &cursor );
error = tr( "Cannot select record from table" );
return false;
}
db_free_string( &dbstr );
return exists;

return nValues > 0;
}

bool QgsGrassVectorMapLayer::isOrphan( int cat, QString &error )
@@ -1205,7 +1205,7 @@ bool TestQgsGrassProvider::equal( QgsFeature feature, QgsFeature expectedFeature
indexes.remove( index );
if ( feature.attribute( index ) != expectedFeature.attribute( i ) )
{
reportRow( QString( "Attribute name %1, value: '%2'' does not match expected value: '%2'" )
reportRow( QString( "Attribute name %1, value: '%2' does not match expected value: '%2'" )
.arg( name ).arg( feature.attribute( index ).toString() ).arg( expectedFeature.attribute( i ).toString() ) );
return false;
}
@@ -1257,6 +1257,7 @@ bool TestQgsGrassProvider::compare( QList<QgsFeature> features, QList<QgsFeature

bool TestQgsGrassProvider::compare( QString uri, QgsGrassObject mapObject, QgsVectorLayer *expectedLayer, bool& ok )
{
Q_UNUSED(mapObject)
QList<QgsFeature> expectedFeatures = getFeatures( expectedLayer );

// read the map using another layer/provider
@@ -1281,6 +1282,10 @@ bool TestQgsGrassProvider::compare( QString uri, QgsGrassObject mapObject, QgsVe
reportRow( "comparison with shared layer failed" );
}

// We cannot test attribute table changes with independent layer in GRASS 6, which is using
// DBF files, which are written when driver is closed (map layer keeps driver open during editing)
bool independentOk = true;
#if GRASS_VERSION_MAJOR >= 7
// Open an independent layer which does not share data with edited one
// build topology
G_TRY
@@ -1291,19 +1296,19 @@ bool TestQgsGrassProvider::compare( QString uri, QgsGrassObject mapObject, QgsVe
int result = Vect_open_old( map, mapObject.name().toUtf8().data(), mapObject.mapset().toUtf8().data() );

if ( result == -1 )
{
QgsGrass::vectDestroyMapStruct( map );
throw QgsGrass::Exception( "Cannot open map " + mapObject.name() );
}
{
QgsGrass::vectDestroyMapStruct( map );
throw QgsGrass::Exception( "Cannot open map " + mapObject.name() );
}

#if ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6
Vect_build( map );
Vect_build( map );
#else
Vect_build( map, stderr );
Vect_build( map, stderr );
#endif
//Vect_set_release_support( map );
Vect_close( map );
QgsGrass::vectDestroyMapStruct( map );
//Vect_set_release_support( map );
Vect_close( map );
QgsGrass::vectDestroyMapStruct( map );
}
G_CATCH( QgsGrass::Exception &e )
{
@@ -1327,7 +1332,7 @@ bool TestQgsGrassProvider::compare( QString uri, QgsGrassObject mapObject, QgsVe
QgsGrassVectorMapStore::setStore( 0 );
delete mapStore;

bool independentOk = compare( features, expectedFeatures, ok );
independentOk = compare( features, expectedFeatures, ok );
if ( independentOk )
{
//reportRow( "comparison with independent layer ok" );
@@ -1336,6 +1341,7 @@ bool TestQgsGrassProvider::compare( QString uri, QgsGrassObject mapObject, QgsVe
{
reportRow( "comparison with independent layer failed" );
}
#endif // GRASS_VERSION_MAJOR >= 7

return sharedOk && independentOk;
}

0 comments on commit 9556a76

Please sign in to comment.
You can’t perform that action at this time.