Skip to content
Permalink
Browse files

Fix failing tests

And localise changes to texteditwrapper
  • Loading branch information
stev-0 committed Dec 28, 2019
1 parent 7226d34 commit cda184dc667025bd70ff6c26f6609704796f00d8
@@ -497,7 +497,7 @@ QVariant QgsJsonUtils::parseJson( const std::string &jsonString )
}
else if ( jObj.is_string() )
{
if ( isPrimitive && ( jObj.get<std::string>().length() == 0 || QString::fromStdString( jObj.get<std::string>() ).at( 0 ) != "\"" ) )
if ( isPrimitive && jObj.get<std::string>().length() == 0 )
{
result = QString::fromStdString( jObj.get<std::string>() ).append( "\"" ).insert( 0, "\"" );
}
@@ -281,13 +281,20 @@ void QgsTextEditWrapper::setWidgetValue( const QVariant &val )
if ( !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
v = QgsApplication::nullRepresentation();
}
// this has to be overridden for json which has only values (i.e. no objects or arrays), as qgsfield.cpp uses QJsonDocument which doesn't recognise
// this as valid JSON although it technically is
else if ( field().type() == QVariant::Map )
{
// this has to be overridden for json which has only values (i.e. no objects or arrays), as qgsfield.cpp displayString()
// uses QJsonDocument which doesn't recognise this as valid JSON although it technically is
if ( field().displayString( val ).isEmpty() )
{
v = val.toString();
if ( val.type() == QVariant::String && val.toString() != QStringLiteral( "\"\"" ) )
{
v = val.toString().append( "\"" ).insert( 0, "\"" );
}
else
{
v = val.toString();
}
}
else
{
@@ -62,7 +62,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper


/**
* Returns whether the text edit widget contains Invalid JSON
* Returns whether the text edit widget contains Invalid JSON
* \since QGIS 3.12
*/
bool isInvalidJSON();
@@ -157,4 +157,4 @@ ADD_QGIS_TEST(rasterlayersaveasdialog testqgsrasterlayersaveasdialog.cpp)
ADD_QGIS_TEST(valuerelationwidgetwrapper testqgsvaluerelationwidgetwrapper.cpp)
ADD_QGIS_TEST(relationreferencewidget testqgsrelationreferencewidget.cpp)
ADD_QGIS_TEST(featurelistcombobox testqgsfeaturelistcombobox.cpp)
ADD_QGIS_TEST(qgstexteditwrapper testqgstexteditwrapper.cpp)
ADD_QGIS_TEST(texteditwrapper testqgstexteditwrapper.cpp)
@@ -121,13 +121,15 @@ void TestQgsTextEditWrapper::testWithJsonInPostgres()

//test empty
widget->setText( QString( "" ) );
QVERIFY( !w_json.value().isValid() );
QVERIFY( w_json.value().isValid() );
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"\"" ) );

//test quoted empty
widget->setText( QString( "\"\"" ) );
QVERIFY( w_json.value().isValid() );
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\" \"" ) );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"\"" ) );

// test invalid JSON
widget->setText( QString( "{\"body\";\"text\"}" ) );
@@ -166,7 +168,7 @@ void TestQgsTextEditWrapper::testWithJsonInPostgres()
QVERIFY( w_json.value().isValid() ) ;
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
// avoid dumping as strings are quoted, so would be double quoted
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"abc\"" ) );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "abc" ) );
}

void TestQgsTextEditWrapper::testWithJsonBInPostgres()
@@ -221,13 +223,16 @@ void TestQgsTextEditWrapper::testWithJsonBInPostgres()

//test empty
widget->setText( QString( "" ) );
QVERIFY( !w_json.value().isValid() );
QVERIFY( w_json.value().isValid() );
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"\"" ) );


//test quoted empty
widget->setText( QString( "\"\"" ) );
QVERIFY( w_json.value().isValid() );
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\" \"" ) );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"\"" ) );

// test invalid JSON
widget->setText( QString( "{\"body\";\"text\"}" ) );
@@ -267,7 +272,7 @@ void TestQgsTextEditWrapper::testWithJsonBInPostgres()
QVERIFY( w_json.value().isValid() ) ;
QVERIFY( QgsJsonUtils::jsonFromVariant( w_json.value() ).is_string() );
// avoid dumping as strings are quoted, so would be double quoted
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "\"abc\"" ) );
QCOMPARE( QString::fromStdString( QgsJsonUtils::jsonFromVariant( w_json.value() ).front( ) ), QStringLiteral( "abc" ) );
}

QGSTEST_MAIN( TestQgsTextEditWrapper )

0 comments on commit cda184d

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