F:/KPlato/koffice/libs/kotext/kohyphen/kohyphentest.cpp

Aller à la documentation de ce fichier.
00001 //KoHyphenator test, Lukas Tinkl <lukas.tinkl@suse.cz>
00002 
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 #include <QStringList>
00007 
00008 #include <kapplication.h>
00009 
00010 #include "kohyphen.h"
00011 #include <kdebug.h>
00012 
00013 static bool check(QString a, QString b)
00014 {
00015   if (a.isEmpty())
00016      a = QString::null;
00017   if (b.isEmpty())
00018      b = QString::null;
00019   if (a == b) {
00020     kDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
00021   }
00022   else {
00023     kDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
00024     exit(1);
00025   }
00026   return true;
00027 }
00028 
00029 KoHyphenator * hypher = 0L;
00030 
00031 void check_hyphenation( const QStringList& tests, const QStringList& results, const char* lang )
00032 {
00033     QStringList::ConstIterator it, itres;
00034     for ( it = tests.begin(), itres = results.begin(); it != tests.end() ; ++it, ++itres ) {
00035         QString result = hypher->hyphenate((*it), lang);
00036         kDebug() << (*it) << " hyphenates like this: " << result << endl;
00037         check( result.replace(QChar(0xad),'-'), *itres );
00038     }
00039 }
00040 
00041 int main (int argc, char ** argv)
00042 {
00043     QApplication app(argc, argv);
00044 
00045     try {
00046         hypher = KoHyphenator::self();
00047     }
00048     catch (KoHyphenatorException &e)
00049     {
00050         kDebug() << e.message() << endl;
00051         return 1;
00052     }
00053 
00054     QStringList::ConstIterator it, itres;
00055 
00056     //testing Czech language, this text is in UTF-8!
00057     QStringList cs_tests = QStringList() << "ŽluÅ¥ouÄký" << "kůň" << "úpÄ›l" <<
00058                         "Äábelské" << "ódy";
00059 
00060     for ( it = cs_tests.begin(); it != cs_tests.end() ; ++it )
00061         kDebug() << (*it) << " hyphenates like this: " << hypher->hyphenate((*it), "cs") << endl;
00062 
00063     //testing English
00064     QStringList en_tests = QStringList() << "Follow" << "white" << "rabbit";
00065     QStringList en_results = QStringList() << "Fol-low" << "white" << "rab-bit";
00066     check_hyphenation( en_tests, en_results, "en" );
00067 
00068     QStringList fr_tests = QStringList() << "constitution" ;
00069     QStringList fr_results = QStringList() << "consti-tu-tion" ;
00070     check_hyphenation( fr_tests, fr_results, "fr" );
00071 
00072     return 0;
00073 }

Généré le Wed Nov 22 23:41:08 2006 pour KPlato par  doxygen 1.5.1-p1