lib

kohyphentest.cpp
1//KoHyphenator test, Lukas Tinkl <lukas.tinkl@suse.cz>
2
3#include <stdio.h>
4#include <stdlib.h>
5
6#include <tqstringlist.h>
7
8#include <tdeaboutdata.h>
9#include <tdeapplication.h>
10#include <tdecmdlineargs.h>
11
12#include "kohyphen.h"
13#include <kdebug.h>
14
15static bool check(TQString a, TQString b)
16{
17 if (a.isEmpty())
18 a = TQString();
19 if (b.isEmpty())
20 b = TQString();
21 if (a == b) {
22 kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl;
23 }
24 else {
25 kdDebug() << "checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl;
26 exit(1);
27 }
28 return true;
29}
30
31KoHyphenator * hypher = 0L;
32
33void check_hyphenation( const TQStringList& tests, const TQStringList& results, const char* lang )
34{
35 TQStringList::ConstIterator it, itres;
36 for ( it = tests.begin(), itres = results.begin(); it != tests.end() ; ++it, ++itres ) {
37 TQString result = hypher->hyphenate((*it), lang);
38 kdDebug() << (*it) << " hyphenates like this: " << result << endl;
39 check( result.replace(TQChar(0xad),'-'), *itres );
40 }
41}
42
43int main (int argc, char ** argv)
44{
45 TDEAboutData aboutData("KoHyphenator test", "KoHyphenator test", "0");
46 TDECmdLineArgs::init( argc, argv, &aboutData );
47 TDEApplication app(false, false, false);
48
49 try {
50 hypher = KoHyphenator::self();
51 }
52 catch (KoHyphenatorException &e)
53 {
54 kdDebug() << e.message() << endl;
55 return 1;
56 }
57
58 TQStringList::ConstIterator it, itres;
59
60 //testing Czech language, this text is in UTF-8!
61 TQStringList cs_tests = TQStringList() << "Žluťoučký" << "kůň" << "úpěl" <<
62 "ďábelské" << "ódy";
63
64 for ( it = cs_tests.begin(); it != cs_tests.end() ; ++it )
65 kdDebug() << (*it) << " hyphenates like this: " << hypher->hyphenate((*it), "cs") << endl;
66
67 //testing English
68 TQStringList en_tests = TQStringList() << "Follow" << "white" << "rabbit";
69 TQStringList en_results = TQStringList() << "Fol-low" << "white" << "rab-bit";
70 check_hyphenation( en_tests, en_results, "en" );
71
72 TQStringList fr_tests = TQStringList() << "constitution" ;
73 TQStringList fr_results = TQStringList() << "consti-tu-tion" ;
74 check_hyphenation( fr_tests, fr_results, "fr" );
75
76 return 0;
77}
The KoHyphenator class provides an interface to the libhnj hyphenation library.
Definition kohyphen.h:56
static KoHyphenator * self()
Returns the single KoHyphenator instance (singleton pattern) Beware that this might throw an exceptio...
Definition kohyphen.cpp:41