Ignore:
Timestamp:
Nov 26, 2009, 1:02:38 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

tests/widget: Added a testcase for the text codec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/widget/widget.cpp

    r346 r351  
    466466};
    467467
     468void testCodec(const char *title, const QString &sample, QTextCodec *codec)
     469{
     470    // test console output
     471
     472    printf("%s : Unicode (source) : ", title);
     473    foreach (QChar ch, sample)
     474        printf("%hX ", ch.unicode());
     475    printf("\n");
     476
     477    QByteArray eightbit = codec->fromUnicode(sample);
     478    printf("%s : 8-bit (as is)    : %s\n", title, eightbit.data());
     479
     480    QString sample2 = codec->toUnicode(eightbit);
     481    printf("%s : Unicode (result) : ", title);
     482    foreach (QChar ch, sample2)
     483        printf("%hX ", ch.unicode());
     484    printf("\n");
     485
     486    if (sample != sample2)
     487        qWarning() << "Source and resulting Unicode differ!";
     488
     489    qWarning() << "";
     490
     491    // test GUI output (both window title and window text)
     492
     493    QString combined = QString("%1 : %2").arg(QLatin1String(title), sample);
     494    QMessageBox mbox;
     495    mbox.setWindowTitle(combined);
     496    mbox.setText(combined);
     497    mbox.exec();
     498}
     499
    468500int main(int argc, char **argv)
    469501{
     
    474506    QCoreApplication app(argc, argv);
    475507
     508#else
     509    ////////////////////////////////////////////////////////////////////////////
     510    // GUI
     511
     512    QApplication app(argc, argv);
     513
     514#if 1
     515    //--------------------------------------------------------------------------
     516    // locale test
     517
     518    QLocale locale = QLocale::system();
     519
     520    qWarning() << "Library paths    :" << QApplication::libraryPaths();
     521    qWarning() << "";
    476522    qWarning() << "Available codecs :\n" << QTextCodec::availableCodecs();
    477523    qWarning() << "";
     
    479525    qWarning() << "         Aliases :" << QTextCodec::codecForLocale()->aliases();
    480526    qWarning() << "";
    481     qWarning() << "Library paths    :" << QApplication::libraryPaths();
    482 
    483 #else
    484     ////////////////////////////////////////////////////////////////////////////
    485     // GUI
    486 
    487     QApplication app(argc, argv);
    488 
     527    qWarning() << "Country for locale  :" << QLocale::countryToString(locale.country())
     528                                          << "[" << locale.country() << "]";
     529    qWarning() << "Language for locale :" << QLocale::languageToString(locale.language())
     530                                          << "[" << locale.language() << "]";
     531    qWarning() << "";
     532
     533    testCodec("First 3 months",
     534              QString("%1, %2, %3").arg(locale.standaloneMonthName(1),
     535                                        locale.standaloneMonthName(2),
     536                                        locale.standaloneMonthName(3)),
     537              QTextCodec::codecForLocale());
     538    return 0;
     539#endif
     540
     541#if 0
    489542    QRect r = QApplication::desktop()->availableGeometry();
    490543    MyWidget widget;
     
    493546
    494547    widget.show();
     548#endif
    495549
    496550#if 0
Note: See TracChangeset for help on using the changeset viewer.