File indexing completed on 2024-07-14 03:58:55

0001 // krazy:excludeall=spelling
0002 /**
0003  * SPDX-FileCopyrightText: 2007 Zack Rusin <zack@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #include "test_core.h"
0009 #include "speller.h"
0010 
0011 #include <QDebug>
0012 #include <QElapsedTimer>
0013 #include <QTest>
0014 
0015 QTEST_GUILESS_MAIN(SonnetCoreTest)
0016 
0017 using namespace Sonnet;
0018 
0019 void SonnetCoreTest::testCore()
0020 {
0021     Speller dict(QStringLiteral("en_US"));
0022 
0023     qDebug() << "Clients are " << dict.availableBackends();
0024     qDebug() << "Languages are " << dict.availableLanguages();
0025     qDebug() << "Language names are " << dict.availableLanguageNames();
0026     qDebug() << "Language dicts " << dict.availableDictionaries();
0027 
0028     QStringList words;
0029     words.reserve(5 * 35);
0030 
0031     for (int i = 0; i < 35; ++i) {
0032         words << QStringLiteral("hello") << QStringLiteral("helo") << QStringLiteral("enviroment") << QStringLiteral("guvernment") << QStringLiteral("farted");
0033     }
0034 
0035     QElapsedTimer mtime;
0036     mtime.start();
0037     for (QStringList::Iterator itr = words.begin(); itr != words.end(); ++itr) {
0038         if (!dict.isCorrect(*itr)) {
0039             // qDebug()<<"Word " << *itr <<" is misspelled";
0040             QStringList sug = dict.suggest(*itr);
0041             // qDebug()<<"Suggestions : "<<sug;
0042         }
0043     }
0044     // mtime.stop();
0045     qDebug() << "Elapsed time is " << mtime.elapsed();
0046 
0047     qDebug() << "Detecting language ...";
0048     // FIXME
0049     //    QString sentence = QString::fromLatin1("QClipboard features some convenience functions to access common data types: setText() allows the exchange of
0050     //    Unicode text and setPixmap() and setImage() allows the exchange of QPixmaps and QImages between applications.");
0051 
0052     //    qDebug() << "\tlang is" << Sonnet::detectLanguage(sentence);
0053 }
0054 
0055 void SonnetCoreTest::testCore2()
0056 {
0057     Speller dict(QStringLiteral("de_DE"));
0058     if (!dict.availableLanguages().contains(QLatin1String("de_DE"))) {
0059         QSKIP("This test requires a german spelling dictionary");
0060         return;
0061     }
0062     qDebug() << "Clients are " << dict.availableBackends();
0063     qDebug() << "Languages are " << dict.availableLanguages();
0064     qDebug() << "Language names are " << dict.availableLanguageNames();
0065     qDebug() << "Language dicts " << dict.availableDictionaries();
0066 
0067     QStringList words;
0068     words.reserve(5 * 35);
0069     for (int i = 0; i < 35; ++i) {
0070         words << QStringLiteral("Hallo") << QStringLiteral("halo") << QStringLiteral("Umgebunp") << QStringLiteral("Regirung") << QStringLiteral("bet");
0071     }
0072 
0073     QElapsedTimer mtime;
0074     mtime.start();
0075     for (QStringList::Iterator itr = words.begin(); itr != words.end(); ++itr) {
0076         if (!dict.isCorrect(*itr)) {
0077             // qDebug()<<"Word " << *itr <<" is misspelled";
0078             QStringList sug = dict.suggest(*itr);
0079             // qDebug()<<"Suggestions : "<<sug;
0080         }
0081     }
0082     // mtime.stop();
0083     qDebug() << "Elapsed time is " << mtime.elapsed();
0084 
0085     qDebug() << "Detecting language ...";
0086     // FIXME
0087     // QString sentence = QString::fromLatin1("Die K Desktop Environment (KDE; auf Deutsch K-Arbeitsumgebung; früher: Kool Desktop Environment) ist eine frei
0088     // verfügbare Arbeitsumgebung, das heißt eine grafische Benutzeroberfläche mit vielen Zusatzprogrammen für den täglichen Gebrauch.");
0089 
0090     // qDebug() << "\tlang is" << Sonnet::detectLanguage(sentence);
0091 }
0092 
0093 #include "moc_test_core.cpp"