Fix qgsVariantGreaterThan may return false result when values are equal

Fixes #61759
This commit is contained in:
Nyall Dawson 2025-05-09 10:52:38 +10:00
parent 2d49d1e7bf
commit 96247de345
5 changed files with 229 additions and 66 deletions

View File

@ -3728,6 +3728,25 @@ for incorrect numbers of digits between thousand separators
.. versionadded:: 3.4
%End
int qgsVariantCompare( const QVariant &lhs, const QVariant &rhs );
%Docstring
Compares two QVariant values.
:return: < 0 if lhs < rhs, > 0 if lhs > rhs, or 0 if lhs == rhs
Useful for sorting lists of variants, correctly handling sorting of the
various QVariant data types (such as strings, numeric values, dates and
times)
Invalid < NULL < Values
.. seealso:: :py:func:`qgsVariantLessThan`
.. seealso:: :py:func:`qgsVariantGreaterThan`
.. versionadded:: 3.44
%End
bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs );
%Docstring
Compares two QVariant values and returns whether the first is less than
@ -3738,6 +3757,8 @@ values, dates and times)
Invalid < NULL < Values
.. seealso:: :py:func:`qgsVariantGreaterThan`
.. seealso:: :py:func:`qgsVariantCompare`
%End
bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs );
@ -3760,6 +3781,8 @@ handling sorting of the various QVariant data types (such as strings,
numeric values, dates and times)
.. seealso:: :py:func:`qgsVariantLessThan`
.. seealso:: :py:func:`qgsVariantCompare`
%End

View File

@ -3728,6 +3728,25 @@ for incorrect numbers of digits between thousand separators
.. versionadded:: 3.4
%End
int qgsVariantCompare( const QVariant &lhs, const QVariant &rhs );
%Docstring
Compares two QVariant values.
:return: < 0 if lhs < rhs, > 0 if lhs > rhs, or 0 if lhs == rhs
Useful for sorting lists of variants, correctly handling sorting of the
various QVariant data types (such as strings, numeric values, dates and
times)
Invalid < NULL < Values
.. seealso:: :py:func:`qgsVariantLessThan`
.. seealso:: :py:func:`qgsVariantGreaterThan`
.. versionadded:: 3.44
%End
bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs );
%Docstring
Compares two QVariant values and returns whether the first is less than
@ -3738,6 +3757,8 @@ values, dates and times)
Invalid < NULL < Values
.. seealso:: :py:func:`qgsVariantGreaterThan`
.. seealso:: :py:func:`qgsVariantCompare`
%End
bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs );
@ -3760,6 +3781,8 @@ handling sorting of the various QVariant data types (such as strings,
numeric values, dates and times)
.. seealso:: :py:func:`qgsVariantLessThan`
.. seealso:: :py:func:`qgsVariantCompare`
%End

View File

@ -126,38 +126,101 @@ void qgsFree( void *ptr )
free( ptr );
}
bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs )
int qgsVariantCompare( const QVariant &lhs, const QVariant &rhs )
{
// invalid < NULL < any value
if ( !lhs.isValid() )
return rhs.isValid();
{
return rhs.isValid() ? -1 : 0;
}
else if ( lhs.isNull() )
return rhs.isValid() && !rhs.isNull();
{
if ( !rhs.isValid() )
return 1;
if ( rhs.isNull() )
return 0;
return -1;
}
else if ( !rhs.isValid() || rhs.isNull() )
return false;
{
return 1;
}
// both valid
switch ( lhs.userType() )
{
case QMetaType::Type::Int:
return lhs.toInt() < rhs.toInt();
case QMetaType::Type::Char:
case QMetaType::Type::Short:
{
const int lhsInt = lhs.toInt();
const int rhsInt = rhs.toInt();
return lhsInt < rhsInt ? -1 : ( lhsInt == rhsInt ? 0 : 1 );
}
case QMetaType::Type::UInt:
return lhs.toUInt() < rhs.toUInt();
case QMetaType::Type::UChar:
case QMetaType::Type::UShort:
{
const uint lhsUInt = lhs.toUInt();
const uint rhsUInt = rhs.toUInt();
return lhsUInt < rhsUInt ? -1 : ( lhsUInt == rhsUInt ? 0 : 1 );
}
case QMetaType::Type::LongLong:
return lhs.toLongLong() < rhs.toLongLong();
case QMetaType::Type::Long:
{
const qlonglong lhsLongLong = lhs.toLongLong();
const qlonglong rhsLongLong = rhs.toLongLong();
return lhsLongLong < rhsLongLong ? -1 : ( lhsLongLong == rhsLongLong ? 0 : 1 );
}
case QMetaType::Type::ULongLong:
return lhs.toULongLong() < rhs.toULongLong();
case QMetaType::Type::ULong:
{
const qulonglong lhsULongLong = lhs.toULongLong();
const qulonglong rhsULongLong = rhs.toULongLong();
return lhsULongLong < rhsULongLong ? -1 : ( lhsULongLong == rhsULongLong ? 0 : 1 );
}
case QMetaType::Type::Double:
return lhs.toDouble() < rhs.toDouble();
{
const double lhsDouble = lhs.toDouble();
const double rhsDouble = rhs.toDouble();
return lhsDouble < rhsDouble ? -1 : ( lhsDouble == rhsDouble ? 0 : 1 );
}
case QMetaType::Type::Float:
{
const float lhsFloat = lhs.toFloat();
const float rhsFloat = rhs.toFloat();
return lhsFloat < rhsFloat ? -1 : ( lhsFloat == rhsFloat ? 0 : 1 );
}
case QMetaType::Type::QChar:
return lhs.toChar() < rhs.toChar();
{
const QChar lhsChar = lhs.toChar();
const QChar rhsChar = rhs.toChar();
return lhsChar < rhsChar ? -1 : ( lhsChar == rhsChar ? 0 : 1 );
}
case QMetaType::Type::QDate:
return lhs.toDate() < rhs.toDate();
{
const QDate lhsDate = lhs.toDate();
const QDate rhsDate = rhs.toDate();
return lhsDate < rhsDate ? -1 : ( lhsDate == rhsDate ? 0 : 1 );
}
case QMetaType::Type::QTime:
return lhs.toTime() < rhs.toTime();
{
const QTime lhsTime = lhs.toTime();
const QTime rhsTime = rhs.toTime();
return lhsTime < rhsTime ? -1 : ( lhsTime == rhsTime ? 0 : 1 );
}
case QMetaType::Type::QDateTime:
return lhs.toDateTime() < rhs.toDateTime();
{
const QDateTime lhsTime = lhs.toDateTime();
const QDateTime rhsTime = rhs.toDateTime();
return lhsTime < rhsTime ? -1 : ( lhsTime == rhsTime ? 0 : 1 );
}
case QMetaType::Type::Bool:
return lhs.toBool() < rhs.toBool();
{
const bool lhsBool = lhs.toBool();
const bool rhsBool = rhs.toBool();
return lhsBool == rhsBool ? 0 : ( lhsBool ? 1 : -1 );
}
case QMetaType::Type::QVariantList:
{
@ -165,13 +228,13 @@ bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs )
const QList<QVariant> &rhsl = rhs.toList();
int i, n = std::min( lhsl.size(), rhsl.size() );
for ( i = 0; i < n && lhsl[i].userType() == rhsl[i].userType() && qgsVariantEqual( lhsl[i], rhsl[i] ); i++ )
for ( i = 0; i < n && lhsl[i].userType() == rhsl[i].userType() && qgsVariantCompare( lhsl[i], rhsl[i] ) == 0; i++ )
;
if ( i == n )
return lhsl.size() < rhsl.size();
return lhsl.size() < rhsl.size() ? -1 : ( lhsl.size() > rhsl.size() ? 1 : 0 );
else
return qgsVariantLessThan( lhsl[i], rhsl[i] );
return qgsVariantCompare( lhsl[i], rhsl[i] );
}
case QMetaType::Type::QStringList:
@ -184,21 +247,27 @@ bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs )
;
if ( i == n )
return lhsl.size() < rhsl.size();
return lhsl.size() < rhsl.size() ? -1 : ( lhsl.size() > rhsl.size() ? 1 : 0 );
else
return lhsl[i] < rhsl[i];
return lhsl[i] < rhsl[i] ? -1 : ( lhsl[i] == rhsl[i] ? 0 : 1 );
}
default:
return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
return QString::localeAwareCompare( lhs.toString(), rhs.toString() );
}
}
bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs )
{
return qgsVariantCompare( lhs, rhs ) < 0;
}
bool qgsVariantGreaterThan( const QVariant &lhs, const QVariant &rhs )
{
return ! qgsVariantLessThan( lhs, rhs );
return qgsVariantCompare( lhs, rhs ) > 0;
}
QString qgsVsiPrefix( const QString &path )
{
return QgsGdalUtils::vsiPrefixForPath( path );

View File

@ -6649,6 +6649,23 @@ CORE_EXPORT int qgsPermissiveToInt( QString string, bool &ok );
*/
CORE_EXPORT qlonglong qgsPermissiveToLongLong( QString string, bool &ok );
/**
* Compares two QVariant values.
*
* \returns < 0 if lhs < rhs, > 0 if lhs > rhs, or 0 if lhs == rhs
*
* Useful for sorting lists of variants, correctly handling sorting of the various
* QVariant data types (such as strings, numeric values, dates and times)
*
* Invalid < NULL < Values
*
* \see qgsVariantLessThan()
* \see qgsVariantGreaterThan()
*
* \since QGIS 3.44
*/
CORE_EXPORT int qgsVariantCompare( const QVariant &lhs, const QVariant &rhs );
/**
* Compares two QVariant values and returns whether the first is less than the second.
* Useful for sorting lists of variants, correctly handling sorting of the various
@ -6657,6 +6674,7 @@ CORE_EXPORT qlonglong qgsPermissiveToLongLong( QString string, bool &ok );
* Invalid < NULL < Values
*
* \see qgsVariantGreaterThan()
* \see qgsVariantCompare()
*/
CORE_EXPORT bool qgsVariantLessThan( const QVariant &lhs, const QVariant &rhs );
@ -6674,7 +6692,9 @@ CORE_EXPORT bool qgsVariantEqual( const QVariant &lhs, const QVariant &rhs );
* Compares two QVariant values and returns whether the first is greater than the second.
* Useful for sorting lists of variants, correctly handling sorting of the various
* QVariant data types (such as strings, numeric values, dates and times)
*
* \see qgsVariantLessThan()
* \see qgsVariantCompare()
*/
CORE_EXPORT bool qgsVariantGreaterThan( const QVariant &lhs, const QVariant &rhs );

View File

@ -266,53 +266,79 @@ void TestQgis::qVariantCompare_data()
QTest::addColumn<QVariant>( "rhs" );
QTest::addColumn<bool>( "lessThan" );
QTest::addColumn<bool>( "greaterThan" );
QTest::addColumn<int>( "compare" );
QTest::newRow( "invalid to value" ) << QVariant() << QVariant( 2 ) << true << false;
QTest::newRow( "invalid to value 2" ) << QVariant( 2 ) << QVariant() << false << true;
QTest::newRow( "invalid to null" ) << QVariant() << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << true << false;
QTest::newRow( "invalid to null2 " ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << QVariant() << false << true;
QTest::newRow( "null to value" ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << QVariant( "a" ) << true << false;
QTest::newRow( "null to value 2" ) << QVariant( "a" ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << false << true;
QTest::newRow( "both invalid" ) << QVariant() << QVariant() << false << false << 0;
QTest::newRow( "invalid to value" ) << QVariant() << QVariant( 2 ) << true << false << -1;
QTest::newRow( "invalid to value 2" ) << QVariant( 2 ) << QVariant() << false << true << 1;
QTest::newRow( "invalid to null" ) << QVariant() << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << true << false << -1;
QTest::newRow( "invalid to null2 " ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << QVariant() << false << true << 1;
QTest::newRow( "both null" ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << false << false << 0;
QTest::newRow( "null to value" ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << QVariant( "a" ) << true << false << -1;
QTest::newRow( "null to value 2" ) << QVariant( "a" ) << QgsVariantUtils::createNullVariant( QMetaType::Type::QString ) << false << true << 1;
QTest::newRow( "int" ) << QVariant( 1 ) << QVariant( 2 ) << true << false;
QTest::newRow( "int 2" ) << QVariant( 1 ) << QVariant( -2 ) << false << true;
QTest::newRow( "int 3" ) << QVariant( 0 ) << QVariant( 1 ) << true << false;
QTest::newRow( "uint" ) << QVariant( 1u ) << QVariant( 2u ) << true << false;
QTest::newRow( "uint 2" ) << QVariant( 2u ) << QVariant( 0u ) << false << true;
QTest::newRow( "long long" ) << QVariant( 1LL ) << QVariant( 2LL ) << true << false;
QTest::newRow( "long long 2" ) << QVariant( 1LL ) << QVariant( -2LL ) << false << true;
QTest::newRow( "long long 3" ) << QVariant( 0LL ) << QVariant( 1LL ) << true << false;
QTest::newRow( "ulong long" ) << QVariant( 1uLL ) << QVariant( 2uLL ) << true << false;
QTest::newRow( "ulong long 2" ) << QVariant( 2uLL ) << QVariant( 0uLL ) << false << true;
QTest::newRow( "double" ) << QVariant( 1.5 ) << QVariant( 2.5 ) << true << false;
QTest::newRow( "double 2" ) << QVariant( 1.5 ) << QVariant( -2.5 ) << false << true;
QTest::newRow( "double 3" ) << QVariant( 0.5 ) << QVariant( 1.5 ) << true << false;
QTest::newRow( "char" ) << QVariant( 'b' ) << QVariant( 'x' ) << true << false;
QTest::newRow( "char 2" ) << QVariant( 'x' ) << QVariant( 'b' ) << false << true;
QTest::newRow( "date" ) << QVariant( QDate( 2000, 5, 6 ) ) << QVariant( QDate( 2000, 8, 6 ) ) << true << false;
QTest::newRow( "date 2" ) << QVariant( QDate( 2000, 8, 6 ) ) << QVariant( QDate( 2000, 5, 6 ) ) << false << true;
QTest::newRow( "time" ) << QVariant( QTime( 13, 5, 6 ) ) << QVariant( QTime( 13, 8, 6 ) ) << true << false;
QTest::newRow( "time 2" ) << QVariant( QTime( 18, 8, 6 ) ) << QVariant( QTime( 13, 5, 6 ) ) << false << true;
QTest::newRow( "datetime" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 8, 6 ), QTime( 13, 5, 6 ) ) ) << true << false;
QTest::newRow( "datetime 2" ) << QVariant( QDateTime( QDate( 2000, 8, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << false << true;
QTest::newRow( "datetime 3" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << true << false;
QTest::newRow( "datetime 4" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << false << true;
QTest::newRow( "bool" ) << QVariant( false ) << QVariant( true ) << true << false;
QTest::newRow( "bool 2" ) << QVariant( true ) << QVariant( false ) << false << true;
QTest::newRow( "qvariantlist" ) << QVariant( QVariantList() << QVariant( 5 ) ) << QVariant( QVariantList() << QVariant( 9 ) ) << true << false;
QTest::newRow( "qvariantlist 2" ) << QVariant( QVariantList() << QVariant( 9 ) ) << QVariant( QVariantList() << QVariant( 5 ) ) << false << true;
QTest::newRow( "qvariantlist 3" ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 3 ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << true << false;
QTest::newRow( "qvariantlist 4" ) << QVariant( QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 3 ) ) << false << true;
QTest::newRow( "qvariantlist 5" ) << QVariant( QVariantList() << QVariant( 5 ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << true << false;
QTest::newRow( "qvariantlist 5" ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << QVariant( QVariantList() << QVariant( 5 ) ) << false << true;
QTest::newRow( "qstringlist" ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << true << false;
QTest::newRow( "qstringlist 2" ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << false << true;
QTest::newRow( "qstringlist 3" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "cc" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << true << false;
QTest::newRow( "qstringlist 4" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "cc" ) ) << false << true;
QTest::newRow( "qstringlist 5" ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << true << false;
QTest::newRow( "qstringlist 6" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << false << true;
QTest::newRow( "string" ) << QVariant( "a b c" ) << QVariant( "d e f" ) << true << false;
QTest::newRow( "string 2" ) << QVariant( "d e f" ) << QVariant( "a b c" ) << false << true;
QTest::newRow( "int" ) << QVariant( 1 ) << QVariant( 2 ) << true << false << -1;
QTest::newRow( "int 2" ) << QVariant( 1 ) << QVariant( -2 ) << false << true << 1;
QTest::newRow( "int 3" ) << QVariant( 0 ) << QVariant( 1 ) << true << false << -1;
QTest::newRow( "int equal" ) << QVariant( 1 ) << QVariant( 1 ) << false << false << 0;
QTest::newRow( "uint" ) << QVariant( 1u ) << QVariant( 2u ) << true << false << -1;
QTest::newRow( "uint 2" ) << QVariant( 2u ) << QVariant( 0u ) << false << true << 1;
QTest::newRow( "uint equal" ) << QVariant( 2u ) << QVariant( 2u ) << false << false << 0;
QTest::newRow( "long long" ) << QVariant( 1LL ) << QVariant( 2LL ) << true << false << -1;
QTest::newRow( "long long 2" ) << QVariant( 1LL ) << QVariant( -2LL ) << false << true << 1;
QTest::newRow( "long long 3" ) << QVariant( 0LL ) << QVariant( 1LL ) << true << false << -1;
QTest::newRow( "long long equal" ) << QVariant( 1LL ) << QVariant( 1LL ) << false << false << 0;
QTest::newRow( "ulong long" ) << QVariant( 1uLL ) << QVariant( 2uLL ) << true << false << -1;
QTest::newRow( "ulong long 2" ) << QVariant( 2uLL ) << QVariant( 0uLL ) << false << true << 1;
QTest::newRow( "ulong long equal" ) << QVariant( 2uLL ) << QVariant( 2uLL ) << false << false << 0;
QTest::newRow( "double" ) << QVariant( 1.5 ) << QVariant( 2.5 ) << true << false << -1;
QTest::newRow( "double 2" ) << QVariant( 1.5 ) << QVariant( -2.5 ) << false << true << 1;
QTest::newRow( "double 3" ) << QVariant( 0.5 ) << QVariant( 1.5 ) << true << false << -1;
QTest::newRow( "double equal" ) << QVariant( 1.5 ) << QVariant( 1.5 ) << false << false << 0;
QTest::newRow( "float" ) << QVariant( 1.5f ) << QVariant( 2.5f ) << true << false << -1;
QTest::newRow( "float 2" ) << QVariant( 1.5f ) << QVariant( -2.5f ) << false << true << 1;
QTest::newRow( "float 3" ) << QVariant( 0.5f ) << QVariant( 1.5f ) << true << false << -1;
QTest::newRow( "float equal" ) << QVariant( 1.5f ) << QVariant( 1.5f ) << false << false << 0;
QTest::newRow( "char" ) << QVariant( 'b' ) << QVariant( 'x' ) << true << false << -1;
QTest::newRow( "char 2" ) << QVariant( 'x' ) << QVariant( 'b' ) << false << true << 1;
QTest::newRow( "char equal" ) << QVariant( 'x' ) << QVariant( 'x' ) << false << false << 0;
QTest::newRow( "date" ) << QVariant( QDate( 2000, 5, 6 ) ) << QVariant( QDate( 2000, 8, 6 ) ) << true << false << -1;
QTest::newRow( "date 2" ) << QVariant( QDate( 2000, 8, 6 ) ) << QVariant( QDate( 2000, 5, 6 ) ) << false << true << 1;
QTest::newRow( "date equal" ) << QVariant( QDate( 2000, 8, 6 ) ) << QVariant( QDate( 2000, 8, 6 ) ) << false << false << 0;
QTest::newRow( "time" ) << QVariant( QTime( 13, 5, 6 ) ) << QVariant( QTime( 13, 8, 6 ) ) << true << false << -1;
QTest::newRow( "time 2" ) << QVariant( QTime( 18, 8, 6 ) ) << QVariant( QTime( 13, 5, 6 ) ) << false << true << 1;
QTest::newRow( "time equal" ) << QVariant( QTime( 18, 8, 6 ) ) << QVariant( QTime( 18, 8, 6 ) ) << false << false << 0;
QTest::newRow( "datetime" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 8, 6 ), QTime( 13, 5, 6 ) ) ) << true << false << -1;
QTest::newRow( "datetime 2" ) << QVariant( QDateTime( QDate( 2000, 8, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << false << true << 1;
QTest::newRow( "datetime 3" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << true << false << -1;
QTest::newRow( "datetime 4" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 5, 6 ) ) ) << false << true << 1;
QTest::newRow( "datetime equal" ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << QVariant( QDateTime( QDate( 2000, 5, 6 ), QTime( 13, 9, 6 ) ) ) << false << false << 0;
QTest::newRow( "bool" ) << QVariant( false ) << QVariant( true ) << true << false << -1;
QTest::newRow( "bool 2" ) << QVariant( true ) << QVariant( false ) << false << true << 1;
QTest::newRow( "bool equal true" ) << QVariant( true ) << QVariant( true ) << false << false << 0;
QTest::newRow( "bool equal false" ) << QVariant( false ) << QVariant( false ) << false << false << 0;
QTest::newRow( "qvariantlist both empty" ) << QVariant( QVariantList() ) << QVariant( QVariantList() ) << false << false << 0;
QTest::newRow( "qvariantlist" ) << QVariant( QVariantList() << QVariant( 5 ) ) << QVariant( QVariantList() << QVariant( 9 ) ) << true << false << -1;
QTest::newRow( "qvariantlist 2" ) << QVariant( QVariantList() << QVariant( 9 ) ) << QVariant( QVariantList() << QVariant( 5 ) ) << false << true << 1;
QTest::newRow( "qvariantlist equal one element" ) << QVariant( QVariantList() << QVariant( 9 ) ) << QVariant( QVariantList() << QVariant( 9 ) ) << false << false << 0;
QTest::newRow( "qvariantlist 3" ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 3 ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << true << false << -1;
QTest::newRow( "qvariantlist 4" ) << QVariant( QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 3 ) ) << false << true << 1;
QTest::newRow( "qvariantlist equal two element" ) << QVariant( QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << false << false << 0;
QTest::newRow( "qvariantlist 5" ) << QVariant( QVariantList() << QVariant( 5 ) ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << true << false << -1;
QTest::newRow( "qvariantlist 5" ) << QVariant( QVariantList() << QVariant( 5 ) << QVariant( 6 ) ) << QVariant( QVariantList() << QVariant( 5 ) ) << false << true << 1;
QTest::newRow( "qstringlist empty" ) << QVariant( QStringList() ) << QVariant( QStringList() ) << false << false << 0;
QTest::newRow( "qstringlist" ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << true << false << -1;
QTest::newRow( "qstringlist 2" ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << false << true << 1;
QTest::newRow( "qstringlist equal one element" ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << QVariant( QStringList() << QStringLiteral( "bb" ) ) << false << false << 0;
QTest::newRow( "qstringlist 3" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "cc" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << true << false << -1;
QTest::newRow( "qstringlist 4" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "cc" ) ) << false << true << 1;
QTest::newRow( "qstringlist equal two element" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << false << false << 0;
QTest::newRow( "qstringlist 5" ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << true << false << -1;
QTest::newRow( "qstringlist 6" ) << QVariant( QStringList() << QStringLiteral( "aa" ) << QStringLiteral( "xx" ) ) << QVariant( QStringList() << QStringLiteral( "aa" ) ) << false << true << 1;
QTest::newRow( "string both empty" ) << QVariant( QString() ) << QVariant( QString() ) << false << false << 0;
QTest::newRow( "string" ) << QVariant( "a b c" ) << QVariant( "d e f" ) << true << false << -1;
QTest::newRow( "string 2" ) << QVariant( "d e f" ) << QVariant( "a b c" ) << false << true << 1;
QTest::newRow( "string equal" ) << QVariant( "a b c" ) << QVariant( "a b c" ) << false << false << 0;
}
void TestQgis::qVariantCompare()
@ -321,9 +347,11 @@ void TestQgis::qVariantCompare()
QFETCH( QVariant, rhs );
QFETCH( bool, lessThan );
QFETCH( bool, greaterThan );
QFETCH( int, compare );
QCOMPARE( qgsVariantLessThan( lhs, rhs ), lessThan );
QCOMPARE( qgsVariantGreaterThan( lhs, rhs ), greaterThan );
QCOMPARE( qgsVariantCompare( lhs, rhs ), compare );
}
void TestQgis::testNanCompatibleEquals_data()