1 /***************************************************************************
2     testqgsgui.cpp
3      --------------------------------------
4     Date                 : 26.1.2015
5     Copyright            : (C) 2015 Michael Kirk
6     Email                : michael at jackpine dot me
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #include "qgstest.h"
17 #include "qgsguiutils.h"
18 
19 class TestQgsGui : public QObject
20 {
21     Q_OBJECT
22   private slots:
23     void createFileFilterForFormat();
24     void createFileFilter();
25     void displayValueWithMaximumDecimals();
26     void displayValueWithMaximumDecimals_data();
27 
28 };
29 
createFileFilterForFormat()30 void TestQgsGui::createFileFilterForFormat()
31 {
32   const QString expected = QStringLiteral( "FOO format (*.foo *.FOO)" );
33   const QString actual = QgsGuiUtils::createFileFilter_( QStringLiteral( "foo" ) );
34 
35   QCOMPARE( actual, expected );
36 }
37 
createFileFilter()38 void TestQgsGui::createFileFilter()
39 {
40   const QString expected = QStringLiteral( "My Description (my_regex MY_REGEX)" );
41   const QString actual = QgsGuiUtils::createFileFilter_( QStringLiteral( "My Description" ), QStringLiteral( "my_regex" ) );
42 
43   QCOMPARE( actual, expected );
44 }
45 
displayValueWithMaximumDecimals()46 void TestQgsGui::displayValueWithMaximumDecimals()
47 {
48   QFETCH( QLocale::Language, locale );
49   QFETCH( double, value );
50   QFETCH( Qgis::DataType, dataType );
51   QFETCH( bool, displayTrailingZeroes );
52   QFETCH( QString, result );
53 
54   QLocale::setDefault( QLocale( locale ) );
55   QCOMPARE( QgsGuiUtils::displayValueWithMaximumDecimals( dataType, value, displayTrailingZeroes ), result );
56 }
57 
displayValueWithMaximumDecimals_data()58 void TestQgsGui::displayValueWithMaximumDecimals_data()
59 {
60 
61   QTest::addColumn<QLocale::Language>( "locale" );
62   QTest::addColumn<Qgis::DataType>( "dataType" );
63   QTest::addColumn<double>( "value" );
64   QTest::addColumn<bool>( "displayTrailingZeroes" );
65   QTest::addColumn<QString>( "result" );
66 
67   // Italian locale ("," as decimal point and "." as thousands separator)
68   QTest::newRow( "float_1_it_1" ) << QLocale::Italian << Qgis::DataType::Float32 << 112345.0 << true  << "112.345,0000000" ;
69   QTest::newRow( "float_1_it_0" ) << QLocale::Italian << Qgis::DataType::Float32 << 112345.0 << false << "112.345" ;
70   QTest::newRow( "float_2_it_1" ) << QLocale::Italian << Qgis::DataType::Float32 << 112345.0102 << true  << "112.345,0102000" ;
71   QTest::newRow( "float_2_it_0" ) << QLocale::Italian << Qgis::DataType::Float32 << 112345.0102 << false << "112.345,0102" ;
72 
73   QTest::newRow( "int_2_it_1" ) << QLocale::Italian << Qgis::DataType::Int32 << 112345.0102 << true << "112.345" ;
74   QTest::newRow( "int_2_it_0" ) << QLocale::Italian << Qgis::DataType::Int32 << 112345.0102 << false << "112.345" ;
75 
76   // English locale
77   QTest::newRow( "float_1_en_1" ) << QLocale::English << Qgis::DataType::Float32 << 112345.0 << true  << "112,345.0000000" ;
78   QTest::newRow( "float_1_en_0" ) << QLocale::English << Qgis::DataType::Float32 << 112345.0 << false << "112,345" ;
79   QTest::newRow( "float_2_en_1" ) << QLocale::English << Qgis::DataType::Float32 << 112345.0102 << true  << "112,345.0102000" ;
80   QTest::newRow( "float_2_en_0" ) << QLocale::English << Qgis::DataType::Float32 << 112345.0102 << false << "112,345.0102" ;
81 
82   QTest::newRow( "int_2_en_1" ) << QLocale::English << Qgis::DataType::Int32 << 112345.0102 << true << "112,345" ;
83   QTest::newRow( "int_2_en_0" ) << QLocale::English << Qgis::DataType::Int32 << 112345.0102 << false << "112,345" ;
84 
85 }
86 
87 QGSTEST_MAIN( TestQgsGui )
88 #include "testqgsgui.moc"
89