Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

negative norwegian test2 #110

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4c614dd
Fix QgsDoubleValidator for exponential sign
agiudiceandrea Apr 29, 2023
7451b62
Fix some typos
agiudiceandrea Apr 29, 2023
dfaada8
Fix some typos
agiudiceandrea Apr 29, 2023
d2e3b4f
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 29, 2023
fdf4b79
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 29, 2023
d9abc44
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 29, 2023
c602474
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 29, 2023
cc04220
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
372a476
Update run-tests.yml
agiudiceandrea Apr 30, 2023
6ffd01a
Update run-tests.yml
agiudiceandrea Apr 30, 2023
a5a4271
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
1009dc0
Update qgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
53f405b
Update testqgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
ee847d7
Update
agiudiceandrea Apr 30, 2023
e72b71d
Update testqgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
68c7c43
Update testqgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
07d3406
Update testqgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
9671f97
Update
agiudiceandrea Apr 30, 2023
35b638f
Update
agiudiceandrea Apr 30, 2023
efc8b7a
Update testqgsdoublevalidator.cpp
agiudiceandrea Apr 30, 2023
44e456f
Update
agiudiceandrea May 1, 2023
96ef536
Update testqgsdoublevalidator.cpp
agiudiceandrea May 1, 2023
452b6ae
Update
agiudiceandrea May 1, 2023
becb2bc
Update qgsdoublevalidator.cpp
agiudiceandrea May 1, 2023
3cf88b4
Update src/gui/qgsdoublevalidator.cpp
agiudiceandrea May 1, 2023
0656116
Update testqgsdoublevalidator.cpp
agiudiceandrea May 2, 2023
f422990
Update
agiudiceandrea May 3, 2023
1159b31
Update run-tests.yml
agiudiceandrea May 3, 2023
a8d589b
Update
agiudiceandrea May 8, 2023
8a09847
Update
agiudiceandrea May 8, 2023
b7ddfbd
Update tests/src/core/testqgscompositionconverter.cpp
agiudiceandrea May 8, 2023
daedce1
Update testqgsproject.cpp
agiudiceandrea May 8, 2023
94ffc29
Update testqgsdoublevalidator.cpp
agiudiceandrea May 8, 2023
08ede39
Update testqgsdoublevalidator.cpp
agiudiceandrea May 9, 2023
538a785
Apply suggestions from code review
agiudiceandrea May 9, 2023
8b3c02e
Update testqgsdoublevalidator.cpp
agiudiceandrea May 9, 2023
ff08b69
Update
agiudiceandrea May 9, 2023
7e91396
Update tests/src/gui/testqgsdoublevalidator.cpp
agiudiceandrea May 9, 2023
3317dd9
downgrade to qt 6.4.3
agiudiceandrea May 11, 2023
925116c
Update run-tests.yml
agiudiceandrea May 12, 2023
018bdf9
Update
agiudiceandrea Jun 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ jobs:
strategy:
matrix:
include:
- distro-version: '22.04'
qt-version: 5
run-tests: true
docker-tag-suffix: ''
with-qt6: OFF
with-qt5: ON
with-3d: ON
with-quick: ON
with-clazy: ON
with-grass7: OFF
with-grass8: OFF
with-compile-commands: ON
# LD_PRELOAD: /lib/x86_64-linux-gnu/libSegFault.so
experimental: false

- distro-version: '38'
qt-version: 6
run-tests: true
Expand Down Expand Up @@ -290,23 +275,14 @@ jobs:

strategy:
matrix:
qt-version: [5, 6]
test-batch: [ALL_BUT_PROVIDERS, POSTGRES, HANA]
qt-version: [6]
test-batch: [ALL_BUT_PROVIDERS]

include:
- qt-version: 5
distro-version: 22.04
docker-target: binary-only

- qt-version: 6
distro-version: 38
docker-target: single

- qt-version: 5
distro-version: 22.04
test-batch: ORACLE
docker-target: binary-for-oracle

exclude:
- qt-version: 6
test-batch: HANA
Expand Down
29 changes: 22 additions & 7 deletions src/gui/qgsdoublevalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@

#include "qgsdoublevalidator.h"

const QString PERMISSIVE_DOUBLE = R"([+\-%3]?[\d]{0,1000}([\.%1][\d]{0,1000})?(e[+\-%3]?[\d]{0,%2})?)";
const QString PERMISSIVE_DOUBLE = R"([+\-%3]?[\d]{0,1000}([\.%1][\d]{0,%2})?([eE%4][+\-%3]?[\d]{0,3})?)";
agiudiceandrea marked this conversation as resolved.
Show resolved Hide resolved
agiudiceandrea marked this conversation as resolved.
Show resolved Hide resolved

QgsDoubleValidator::QgsDoubleValidator( QObject *parent )
: QRegularExpressionValidator( parent )
, mMinimum( std::numeric_limits<qreal>::lowest() )
, mMaximum( std::numeric_limits<qreal>::max() )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ).arg( locale().negativeSign() ) );
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() )
.arg( QString::number( 1000 ) )
.arg( QLocale().negativeSign() )
.arg( QLocale().exponential() ) );
setRegularExpression( reg );
}

Expand All @@ -51,7 +54,10 @@ QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, QObject *pare
, mMaximum( top )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( 1000 ).arg( locale().negativeSign() ) );
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() )
.arg( QString::number( 1000 ) )
.arg( QLocale().negativeSign() )
.arg( QLocale().exponential() ) );
setRegularExpression( reg );
}

Expand All @@ -61,7 +67,10 @@ QgsDoubleValidator::QgsDoubleValidator( double bottom, double top, int decimal,
, mMaximum( top )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( decimal ) ).arg( locale().negativeSign() ) );
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() )
.arg( QString::number( decimal ) )
.arg( QLocale().negativeSign() )
.arg( QLocale().exponential() ) );
setRegularExpression( reg );
}

Expand All @@ -71,13 +80,19 @@ QgsDoubleValidator::QgsDoubleValidator( int decimal, QObject *parent )
, mMaximum( std::numeric_limits<qreal>::max() )
{
// The regular expression accept double with point as decimal point but also the locale decimal point
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( decimal ) ).arg( locale().negativeSign() ) );
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() )
.arg( QString::number( decimal ) )
.arg( QLocale().negativeSign() )
.arg( QLocale().exponential() ) );
setRegularExpression( reg );
}

void QgsDoubleValidator::setMaxDecimals( int maxDecimals )
{
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( locale().decimalPoint() ).arg( QString::number( maxDecimals ) ).arg( locale().negativeSign() ) );
const QRegularExpression reg( PERMISSIVE_DOUBLE.arg( QLocale().decimalPoint() )
.arg( QString::number( maxDecimals ) )
.arg( QLocale().negativeSign() )
.arg( QLocale().exponential() ) );
setRegularExpression( reg );
}

Expand Down Expand Up @@ -142,7 +157,7 @@ double QgsDoubleValidator::toDouble( const QString &input, bool *ok )
// Still non ok? Try without locale's group separator
if ( ! *ok && !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
{
value = QLocale( ).toDouble( QString( input ).replace( QLocale().groupSeparator(), QString() ), ok );
value = QLocale().toDouble( QString( input ).replace( QLocale().groupSeparator(), QString() ), ok );
}
return value ;
}
66 changes: 45 additions & 21 deletions tests/src/gui/testqgsdoublevalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ void TestQgsDoubleValidator::validate_data()

QTest::newRow( "positive sign C decimal" ) << QString( "+4cd6" ) << int( QValidator::Acceptable ) << false;

QTest::newRow( "exponent <e> C negative" ) << QString( "44446ecn1" ) << int( QValidator::Acceptable ) << false;
QTest::newRow( "exponent <e> locale negative" ) << QString( "44446eln1" ) << int( QValidator::Acceptable ) << false;
QTest::newRow( "locale decimal exponent <E> positive" ) << QString( "444ld46E1" ) << int( QValidator::Acceptable ) << false;
QTest::newRow( "locale decimal exponent <E> positive sign" ) << QString( "444ld46E+1" ) << int( QValidator::Acceptable ) << false;
QTest::newRow( "locale exponent locale negative" ) << QString( "4446leln1" ) << int( QValidator::Acceptable ) << false;

QTest::newRow( "exponent <e> without digits" ) << QString( "4446e" ) << int( QValidator::Intermediate ) << false;
QTest::newRow( "exponent <e> with 4 digits" ) << QString( "44cd46e0001" ) << int( QValidator::Intermediate ) << false;

QTest::newRow( "locale decimal with many decimals exponent <e>" ) << QString( "0ld00000000000000000000000000000123e30" ) << int( QValidator::Acceptable ) << false;

// QgsDoubleValidator doesn't expect group separator but it tolerates it,
// so the result will be QValidator::Intermediate and not QValidator::Acceptable
QTest::newRow( "locale group separator + locale decimal" ) << QString( "4lg444ld6" ) << int( QValidator::Intermediate ) << false;
Expand Down Expand Up @@ -99,6 +110,17 @@ void TestQgsDoubleValidator::toDouble_data()

QTest::newRow( "positive sign C decimal" ) << QString( "+4cd6" ) << 4.6;

QTest::newRow( "exponent <e> C negative" ) << QString( "44446ecn1" ) << 4444.6;
QTest::newRow( "exponent <e> locale negative" ) << QString( "44446eln1" ) << 4444.6;
QTest::newRow( "locale decimal exponent <E> positive" ) << QString( "444ld46E1" ) << 4444.6;
agiudiceandrea marked this conversation as resolved.
Show resolved Hide resolved
QTest::newRow( "locale decimal exponent <E> positive sign" ) << QString( "444ld46E+1" ) << 4444.6;
QTest::newRow( "locale exponent locale negative" ) << QString( "44446leln1" ) << 4444.6;

QTest::newRow( "exponent <e> without digits" ) << QString( "4446e" ) << 0.0;
QTest::newRow( "exponent <e> with 4 digits" ) << QString( "44cd46e0001" ) << 444.6;

QTest::newRow( "locale decimal with many decimals and exponent <e>" ) << QString( "0ld00000000000000000000000000000123e30" ) << 1.23;

// QgsDoubleValidator doesn't expect group separator but it tolerates it,
// so the result will be QValidator::Intermediate and not QValidator::Acceptable
QTest::newRow( "locale group separator + locale decimal" ) << QString( "4lg444ld6" ) << 4444.6;
Expand All @@ -116,35 +138,36 @@ void TestQgsDoubleValidator::toDouble_data()
void TestQgsDoubleValidator::validate()
{
QLineEdit *lineEdit = new QLineEdit();
QgsDoubleValidator *validator = new QgsDoubleValidator( lineEdit );

QFETCH( QString, actualState );
QFETCH( int, expState );
QFETCH( bool, negative );
QString value;
int expectedValue;

if ( negative )
validator->setRange( -10000, -4 );
else
validator->setRange( 4, 10000 );

lineEdit->setValidator( validator );

const QVector<QLocale>listLocale( {QLocale::English, QLocale::French, QLocale::German, QLocale::Italian, QLocale::NorwegianBokmal} );
const QVector<QLocale>listLocale( {QLocale::English, QLocale::French, QLocale::German, QLocale::Italian, QLocale::NorwegianBokmal, QLocale::Ukrainian} );
QLocale loc;
for ( int i = 0; i < listLocale.count(); ++i )
{
loc = listLocale.at( i );
QLocale::setDefault( loc );

QgsDoubleValidator *validator = new QgsDoubleValidator( lineEdit );
if ( negative )
validator->setRange( -10000, -4 );
else
validator->setRange( 4, 10000 );
validator->setLocale( loc );
lineEdit->setValidator( validator );

value = actualState;
value = value.replace( "ld", QLocale().decimalPoint() )
.replace( "cd", QLocale( QLocale::C ).decimalPoint() )
.replace( "lg", QLocale().groupSeparator() )
.replace( "cg", QLocale( QLocale::C ).groupSeparator() )
.replace( "ln", QLocale().negativeSign() )
.replace( "cn", QLocale( QLocale::C ).negativeSign() );
.replace( "cn", QLocale( QLocale::C ).negativeSign() )
.replace( "le", QLocale().exponential() );
expectedValue = expState;
// if the local group separator / decimal point is equal to the C one,
// expected result will be different for double with test with mixed
Expand All @@ -159,19 +182,19 @@ void TestQgsDoubleValidator::validate()
// and validator->validate(4cg444cd6) == 1 and not 0
if ( ( QLocale( QLocale::C ).groupSeparator() == QLocale().groupSeparator() ||
QLocale( QLocale::C ).decimalPoint() == QLocale().decimalPoint() )
&& value != "string" && expectedValue == 0 )
&& value != "string" && value != "4446e" && expectedValue == 0 )
expectedValue = 1;
// There is another corner case in the test where the group separator is equal
// to the C decimal point and there is no decimal point,
// in that case the value is valid, because the fall
// back check is to test after removing all group separators
if ( QLocale( ).groupSeparator() == QLocale( QLocale::C ).decimalPoint()
&& ! value.contains( QLocale( ).decimalPoint() )
&& value != "string" && expectedValue == 0 )
if ( QLocale().groupSeparator() == QLocale( QLocale::C ).decimalPoint()
&& ! value.contains( QLocale().decimalPoint() )
&& value != "string" && value != "4446e" && expectedValue == 0 )
{
expectedValue = 1;
}
// qDebug() << value << loc << int( validator->validate( value ) ) << expectedValue;
//qDebug() << value << loc << int( validator->validate( value ) ) << expectedValue;
QCOMPARE( int( validator->validate( value ) ), expectedValue );
}
}
Expand All @@ -183,7 +206,7 @@ void TestQgsDoubleValidator::toDouble()
QString value;
double expectedValue;

const QVector<QLocale>listLocale( {QLocale::English, QLocale::French, QLocale::German, QLocale::Italian, QLocale::NorwegianBokmal} );
const QVector<QLocale>listLocale( {QLocale::English, QLocale::French, QLocale::German, QLocale::Italian, QLocale::NorwegianBokmal, QLocale::Ukrainian} );
QLocale loc;
for ( int i = 0; i < listLocale.count(); ++i )
{
Expand All @@ -195,7 +218,8 @@ void TestQgsDoubleValidator::toDouble()
.replace( "lg", QLocale().groupSeparator() )
.replace( "cg", QLocale( QLocale::C ).groupSeparator() )
.replace( "ln", QLocale().negativeSign() )
.replace( "cn", QLocale( QLocale::C ).negativeSign() );
.replace( "cn", QLocale( QLocale::C ).negativeSign() )
.replace( "le", QLocale().exponential() );
expectedValue = expValue;
// if the local group separator / decimal point is equal to the C one,
// expected result will be different for double with test with mixed
Expand All @@ -210,15 +234,15 @@ void TestQgsDoubleValidator::toDouble()
// and QgsDoubleValidator::toDouble(4cg444cd6) == 4444.6 and not 0.0
if ( ( QLocale( QLocale::C ).groupSeparator() == QLocale().groupSeparator() ||
QLocale( QLocale::C ).decimalPoint() == QLocale().decimalPoint() )
&& value != "string" && expectedValue == 0.0 )
&& value != "string" && value != "4446e" && expectedValue == 0.0 )
expectedValue = 4444.6;
// There is another corner case in the test where the group separator is equal
// to the C decimal point and there is no decimal point,
// in that case the value is valid, because the fall
// back check is to test after removing all group separators
if ( QLocale( ).groupSeparator() == QLocale( QLocale::C ).decimalPoint()
&& ! value.contains( QLocale( ).decimalPoint() )
&& value != "string" && expectedValue == 0 )
if ( QLocale().groupSeparator() == QLocale( QLocale::C ).decimalPoint()
&& ! value.contains( QLocale().decimalPoint() )
&& value != "string" && value != "4446e" && expectedValue == 0 )
{
expectedValue = 44446;
}
Expand Down