diff options
| author | Martin Gräßlin <mgraesslin@kde.org> | 2014-06-05 14:05:44 +0200 | 
|---|---|---|
| committer | Thomas Braxton <kde.braxton@gmail.com> | 2014-06-12 17:48:21 -0500 | 
| commit | 69c203156d21385a8c263096cb35600e85a5c604 (patch) | |
| tree | 38a69b65bea0a85ef43df011194ce4e0742aec55 /autotests/kdesktopfiletest.cpp | |
| parent | ac6703215ba5e152379173ba503f5ba3bd7e8a85 (diff) | |
| download | kconfig-69c203156d21385a8c263096cb35600e85a5c604.tar.gz kconfig-69c203156d21385a8c263096cb35600e85a5c604.tar.bz2 | |
Fix locale-aware reading in KDesktopFile
The underlying KConfig used QLocale::name() for getting the locale
aware part. But this returns "de_DE" while the desktop files store
"de".
In addition it constructs a QLocale object instead of using the
system locale. This has the advantage that the usage of
QLocale::setDafault() gets honored by KConfig.
REVIEW: 118564
Diffstat (limited to 'autotests/kdesktopfiletest.cpp')
| -rw-r--r-- | autotests/kdesktopfiletest.cpp | 30 | 
1 files changed, 30 insertions, 0 deletions
| diff --git a/autotests/kdesktopfiletest.cpp b/autotests/kdesktopfiletest.cpp index 494a43c0..6c3af4c2 100644 --- a/autotests/kdesktopfiletest.cpp +++ b/autotests/kdesktopfiletest.cpp @@ -16,6 +16,7 @@   *  Boston, MA 02110-1301, USA.   */  #include "kdesktopfiletest.h" +#include "helper.h"  #include <kconfiggroup.h>  #include <qtemporaryfile.h> @@ -49,6 +50,35 @@ void KDesktopFileTest::testRead()      QCOMPARE(df.fileName(), QFileInfo(fileName).canonicalFilePath());  } +void KDesktopFileTest::testReadLocalized() +{ +    QTemporaryFile file("testReadLocalizedXXXXXX.desktop"); +    QVERIFY(file.open()); +    const QString fileName = file.fileName(); +    QTextStream ts(&file); +    ts << +       "[Desktop Entry]\n" +       "Type=Application\n" +       "Name=My Application\n" +       "Name[de]=Meine Anwendung\n" +       "Icon=foo\n" +       "\n"; +    file.close(); +    QVERIFY(QFile::exists(fileName)); +    QVERIFY(KDesktopFile::isDesktopFile(fileName)); + +    DefaultLocale defaultLocale; +    // set language to German for which we have a translation +    QLocale::setDefault(QLocale(QLocale::German)); +    KDesktopFile df(fileName); +    QCOMPARE(df.readName(), QString::fromLatin1("Meine Anwendung")); + +    // set language to French for which we don't have a translation +    QLocale::setDefault(QLocale(QLocale::French)); +    KDesktopFile df2(fileName); +    QCOMPARE(df2.readName(), QString::fromLatin1("My Application")); +} +  void KDesktopFileTest::testSuccessfulTryExec()  {      QTemporaryFile file; | 
