aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHolger Schroeder <holger.schroeder.ext@basyskom.de>2010-06-09 15:32:23 +0200
committerMike FABIAN <mike.fabian@basyskom.de>2010-06-10 16:45:44 +0300
commit23670fa3614880413efd2a17638d0995b0b938cf (patch)
tree6032316e64833b9241f30dfd4ef6fdf3e35212ad /tests
parentd2212f0d90f2cd198574b1e9b4f73ad28000fdc5 (diff)
Changes: get phone number grouping setting from gconf
RevBy: TrustMe Details: this patch adds a gconf key /meegotouch/i18n/lc_telephone. if that key starts with en_US, north american phone number grouping is used in formatPhoneNumber(), when it is called with parameter DefaultGrouping, otherwise no grouping is used.
Diffstat (limited to 'tests')
-rw-r--r--tests/ut_phonenumberformatting/ut_phonenumberformatting.cpp86
-rw-r--r--tests/ut_phonenumberformatting/ut_phonenumberformatting.h11
2 files changed, 92 insertions, 5 deletions
diff --git a/tests/ut_phonenumberformatting/ut_phonenumberformatting.cpp b/tests/ut_phonenumberformatting/ut_phonenumberformatting.cpp
index a401fa08..a5c37c46 100644
--- a/tests/ut_phonenumberformatting/ut_phonenumberformatting.cpp
+++ b/tests/ut_phonenumberformatting/ut_phonenumberformatting.cpp
@@ -19,6 +19,23 @@
#include "ut_phonenumberformatting.h"
#include "mlocale.h"
+#include "mgconfitem.h"
+
+void Ut_PhoneNumberFormatting::initTestCase()
+{
+ m_pLocale = new MLocale;
+
+ // for some reason only the default locale gets
+ // the signals when the gconf keys change,
+ // so for this test we make this locale the default
+ // locale...
+ m_pLocale->setDefault( *m_pLocale );
+}
+
+void Ut_PhoneNumberFormatting::cleanupTestCase()
+{
+ delete m_pLocale;
+}
void Ut_PhoneNumberFormatting::testFormatting_data()
{
@@ -281,17 +298,76 @@ void Ut_PhoneNumberFormatting::testFormatting()
QFETCH( QString, formattedPhoneNumber );
QFETCH( bool, doGrouping );
- Q_UNUSED(doGrouping);
-
MLocale locale;
QString myGroupedPhoneNumber = locale.formatPhoneNumber(
rawPhoneNumber, doGrouping ?
- MLocale::NorthAmericanGrouping :
- MLocale::NoGrouping );
+ MLocale::NorthAmericanPhoneNumberGrouping :
+ MLocale::NoPhoneNumberGrouping );
QCOMPARE( myGroupedPhoneNumber, formattedPhoneNumber );
}
+void Ut_PhoneNumberFormatting::testDefaultFormatting_data()
+{
+ QTest::addColumn<QString>("rawPhoneNumber");
+ QTest::addColumn<QString>("formattedPhoneNumber");
+ QTest::addColumn<QString>("phoneLocale");
+
+ // here we just test two switches between north
+ // american grouping and no grouping
+
+ QTest::newRow( "" ) << QString()
+ << QString()
+ << QString();
+
+ QTest::newRow( "fi" ) << QString( "+3581234567" )
+ << QString( "+358 1234567" )
+ << QString( "fi" );
+
+ QTest::newRow( "en_US" ) << QString( "+3581234567" )
+ << QString( "+358 (123) 456-7" )
+ << QString( "en_US" );
+
+ QTest::newRow( "fi2" ) << QString( "+3581234567" )
+ << QString( "+358 1234567" )
+ << QString( "fi" );
+
+ QTest::newRow( "en_US2" ) << QString( "+3581234567" )
+ << QString( "+358 (123) 456-7" )
+ << QString( "en_US" );
+}
+
+void Ut_PhoneNumberFormatting::testDefaultFormatting()
+{
+ QTest::addColumn<QString>("rawPhoneNumber");
+ QTest::addColumn<QString>("formattedPhoneNumber");
+ QTest::addColumn<QString>("phoneLocale");
+
+ QFETCH( QString, rawPhoneNumber );
+ QFETCH( QString, formattedPhoneNumber );
+ QFETCH( QString, phoneLocale );
+
+ // here we set the telephone locale first,
+ // and then we get the formatted phone number
+ // for the default locale.
+ // this way we test if a change in the
+ // locale gconf key really results in different
+ // formatted phone numbers for different phone
+ // locales.
+
+ MGConfItem lcPhoneItem( "/meegotouch/i18n/lc_telephone" );
+
+ lcPhoneItem.set( phoneLocale );
+
+ // for some reason the gconf items do need this
+ // wait call to propagate the key change.
+ QTest::qWait( 10 );
+
+ QString myGroupedPhoneNumber = m_pLocale->formatPhoneNumber(
+ rawPhoneNumber, MLocale::DefaultPhoneNumberGrouping );
+
+ QCOMPARE( myGroupedPhoneNumber, formattedPhoneNumber );
+}
-QTEST_APPLESS_MAIN(Ut_PhoneNumberFormatting);
+QTEST_MAIN(Ut_PhoneNumberFormatting);
diff --git a/tests/ut_phonenumberformatting/ut_phonenumberformatting.h b/tests/ut_phonenumberformatting/ut_phonenumberformatting.h
index beab3c2d..274b17c3 100644
--- a/tests/ut_phonenumberformatting/ut_phonenumberformatting.h
+++ b/tests/ut_phonenumberformatting/ut_phonenumberformatting.h
@@ -23,13 +23,24 @@
#include <QtTest/QtTest>
#include <QObject>
+class MLocale;
+
class Ut_PhoneNumberFormatting : public QObject
{
Q_OBJECT
private slots:
+ void initTestCase();
+ void cleanupTestCase();
+
void testFormatting_data();
void testFormatting();
+
+ void testDefaultFormatting_data();
+ void testDefaultFormatting();
+
+private:
+ MLocale* m_pLocale;
};
#endif