diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kabc/tests | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kabc/tests')
-rw-r--r-- | kabc/tests/Makefile.am | 55 | ||||
-rw-r--r-- | kabc/tests/bigread.cpp | 65 | ||||
-rw-r--r-- | kabc/tests/bigwrite.cpp | 70 | ||||
-rw-r--r-- | kabc/tests/kabcargl.cpp | 70 | ||||
-rw-r--r-- | kabc/tests/testaddressee.cpp | 57 | ||||
-rw-r--r-- | kabc/tests/testaddresseelist.cpp | 196 | ||||
-rw-r--r-- | kabc/tests/testaddressfmt.cpp | 63 | ||||
-rw-r--r-- | kabc/tests/testaddresslineedit.cpp | 29 | ||||
-rw-r--r-- | kabc/tests/testdb.cpp | 33 | ||||
-rw-r--r-- | kabc/tests/testdistlist.cpp | 59 | ||||
-rw-r--r-- | kabc/tests/testkabc.cpp | 62 | ||||
-rw-r--r-- | kabc/tests/testkabcdlg.cpp | 45 | ||||
-rw-r--r-- | kabc/tests/testldapclient.cpp | 161 | ||||
-rw-r--r-- | kabc/tests/testldapclient.h | 51 | ||||
-rw-r--r-- | kabc/tests/testlock.cpp | 206 | ||||
-rw-r--r-- | kabc/tests/testlock.h | 51 |
16 files changed, 1273 insertions, 0 deletions
diff --git a/kabc/tests/Makefile.am b/kabc/tests/Makefile.am new file mode 100644 index 000000000..99d410a2e --- /dev/null +++ b/kabc/tests/Makefile.am @@ -0,0 +1,55 @@ +# Make sure $(all_includes) remains last! +INCLUDES = -I$(top_builddir)/kabc -I$(top_srcdir)/kabc -I$(top_srcdir)/kab \ + -I$(srcdir)/../vcardparser/ -I$(srcdir)/../vcard/include \ + -I$(srcdir)/../vcard/include/generated \ + -I$(srcdir)/../vcardparser $(all_includes) +LDADD = ../libkabc.la + +METASOURCES = AUTO + +check_PROGRAMS = testlock testldapclient + +testlock_LDFLAGS = $(all_libraries) +testlock_SOURCES = testlock.cpp + +testldapclient_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testldapclient_SOURCES = testldapclient.cpp + +EXTRA_PROGRAMS = testkabc testkabcdlg testdistlist bigread bigwrite testdb \ + testaddressee testaddresseelist testaddressfmt kabcargl testaddresslineedit + +testkabc_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testkabc_SOURCES = testkabc.cpp + +testaddressee_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testaddressee_SOURCES = testaddressee.cpp + +testaddresseelist_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testaddresseelist_SOURCES = testaddresseelist.cpp + +testaddressfmt_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testaddressfmt_SOURCES = testaddressfmt.cpp + +testkabcdlg_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testkabcdlg_SOURCES = testkabcdlg.cpp + +testdistlist_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testdistlist_SOURCES = testdistlist.cpp + +testaddresslineedit_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testaddresslineedit_SOURCES = testaddresslineedit.cpp + +bigread_LDFLAGS = $(all_libraries) $(KDE_RPATH) +bigread_LDADD = ../libkabc.la $(top_builddir)/kabc/plugins/file/libkabc_file.la +bigread_SOURCES = bigread.cpp + +bigwrite_LDFLAGS = $(all_libraries) $(KDE_RPATH) +bigwrite_LDADD = ../libkabc.la $(top_builddir)/kabc/plugins/file/libkabc_file.la +bigwrite_SOURCES = bigwrite.cpp + +testdb_LDFLAGS = $(all_libraries) $(KDE_RPATH) +testdb_SOURCES = testdb.cpp + +kabcargl_LDFLAGS = $(all_libraries) $(KDE_RPATH) +kabcargl_SOURCES = kabcargl.cpp + diff --git a/kabc/tests/bigread.cpp b/kabc/tests/bigread.cpp new file mode 100644 index 000000000..e64bafef8 --- /dev/null +++ b/kabc/tests/bigread.cpp @@ -0,0 +1,65 @@ +#include <sys/times.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "addressbook.h" +#include "vcardformat.h" +#include "plugins/file/resourcefile.h" +#if 0 +#include "resourcesql.h" +#endif + +using namespace KABC; + +int main(int argc,char **argv) +{ + KAboutData aboutData("bigread","BigReadKabc","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + + KApplication app( false, false ); + + AddressBook ab; + + ResourceFile r( "my.kabc", "vcard2" ); + ab.addResource( &r ); + +#if 0 + ResourceSql rsql( &ab, "root", "kde4ever", "localhost" ); + ab.addResource( &rsql ); +#endif + + struct tms start; + + times( &start ); + +#if 0 + kdDebug() << "utime : " << int( start.tms_utime ) << endl; + kdDebug() << "stime : " << int( start.tms_stime ) << endl; + kdDebug() << "cutime: " << int( start.tms_cutime ) << endl; + kdDebug() << "cstime: " << int( start.tms_cstime ) << endl; +#endif + + kdDebug() << "Start load" << endl; + ab.load(); + kdDebug() << "Finished load" << endl; + + struct tms end; + + times( &end ); + +#if 0 + kdDebug() << "utime : " << int( end.tms_utime ) << endl; + kdDebug() << "stime : " << int( end.tms_stime ) << endl; + kdDebug() << "cutime: " << int( end.tms_cutime ) << endl; + kdDebug() << "cstime: " << int( end.tms_cstime ) << endl; +#endif + + kdDebug() << "UTime: " << int( end.tms_utime ) - int( start.tms_utime ) << endl; + kdDebug() << "STime: " << int( end.tms_stime ) - int( start.tms_stime ) << endl; + +// ab.dump(); +} diff --git a/kabc/tests/bigwrite.cpp b/kabc/tests/bigwrite.cpp new file mode 100644 index 000000000..90013a157 --- /dev/null +++ b/kabc/tests/bigwrite.cpp @@ -0,0 +1,70 @@ +#include <sys/times.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "addressbook.h" +#include "vcardformat.h" +#include "plugins/file/resourcefile.h" + +using namespace KABC; + +int main(int argc,char **argv) +{ + KAboutData aboutData("bigwrite","BigWriteKabc","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + + KApplication app( false, false ); + + AddressBook ab; + ResourceFile r( "my.kabc", "vcard" ); + ab.addResource( &r ); + + for( int i = 0; i < 5000; ++i ) { + Addressee a; + a.setGivenName( "number" + QString::number( i ) ); + a.setFamilyName( "Name" ); + a.insertEmail( QString::number( i ) + "@domain" ); + + ab.insertAddressee( a ); + } + printf( "\n" ); + + Ticket *t = ab.requestSaveTicket( &r ); + if ( t ) { + struct tms start; + + times( &start ); + +#if 0 + kdDebug() << "utime : " << int( start.tms_utime ) << endl; + kdDebug() << "stime : " << int( start.tms_stime ) << endl; + kdDebug() << "cutime: " << int( start.tms_cutime ) << endl; + kdDebug() << "cstime: " << int( start.tms_cstime ) << endl; +#endif + + if ( !ab.save( t ) ) { + kdDebug() << "Can't save." << endl; + } + + struct tms end; + + times( &end ); + +#if 0 + kdDebug() << "utime : " << int( end.tms_utime ) << endl; + kdDebug() << "stime : " << int( end.tms_stime ) << endl; + kdDebug() << "cutime: " << int( end.tms_cutime ) << endl; + kdDebug() << "cstime: " << int( end.tms_cstime ) << endl; +#endif + + kdDebug() << "UTime: " << int( end.tms_utime ) - int( start.tms_utime ) << endl; + kdDebug() << "STime: " << int( end.tms_stime ) - int( start.tms_stime ) << endl; + + } else { + kdDebug() << "No ticket for save." << endl; + } +} diff --git a/kabc/tests/kabcargl.cpp b/kabc/tests/kabcargl.cpp new file mode 100644 index 000000000..32251303b --- /dev/null +++ b/kabc/tests/kabcargl.cpp @@ -0,0 +1,70 @@ +/* + This file is part of libkabc. + Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <qfile.h> +#include <qtextstream.h> +#include <qregexp.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <kcmdlineargs.h> +#include <kglobal.h> +#include <kstandarddirs.h> + +#include "stdaddressbook.h" + +using namespace KABC; + +int main(int argc,char **argv) +{ + KAboutData aboutData("kabcargl","Fix broken pre3.0rc3 format","0.1"); + aboutData.addAuthor("Cornelius Schumacher", 0, "schumacher@kde.org"); + + KCmdLineArgs::init(argc,argv,&aboutData); + + KApplication app; + + QString filename = StdAddressBook::fileName(); + + QFile f( filename ); + if ( !f.open( IO_ReadOnly ) ) { + kdDebug() << "Error opening file '" << filename << "' for reading." << endl; + return 1; + } + + QTextStream t( &f ); + t.setEncoding(QTextStream::UnicodeUTF8); + QString text = t.read(); + f.close(); + + text = QString::fromUtf8( text.local8Bit() ); + text.replace( "\n", "\r\n" ); + + if ( !f.open( IO_WriteOnly ) ) { + kdDebug() << "Error opening file '" << filename << "' for writing." << endl; + return 1; + } + + QTextStream t2( &f ); + t2.setEncoding(QTextStream::UnicodeUTF8); + t2 << text; + f.close(); +} diff --git a/kabc/tests/testaddressee.cpp b/kabc/tests/testaddressee.cpp new file mode 100644 index 000000000..d05c3af24 --- /dev/null +++ b/kabc/tests/testaddressee.cpp @@ -0,0 +1,57 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kstandarddirs.h> + +#include "addressbook.h" +#include "plugins/file/resourcefile.h" +#include "formats/binaryformat.h" +#include "vcardformat.h" +#include "phonenumber.h" + +using namespace KABC; + +static const KCmdLineOptions options[] = +{ + { "save", "", 0 }, + { "number", "", 0 }, + KCmdLineLastOption +}; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testaddressee","TestAddressee","0.1"); + KCmdLineArgs::init(argc, argv, &aboutData); + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app; + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + + kdDebug() << "Creating a" << endl; + Addressee a; + + kdDebug() << "tick1" << endl; + a.setGivenName("Hans"); + kdDebug() << "tick2" << endl; + a.setPrefix("Dr."); + + kdDebug() << "Creating b" << endl; + Addressee b( a ); + + kdDebug() << "tack1" << endl; + a.setFamilyName("Wurst"); + kdDebug() << "tack2" << endl; + a.setNickName("hansi"); + + kdDebug() << "Creating c" << endl; + Addressee c = a; + + kdDebug() << "tock1" << endl; + c.setGivenName("Eberhard"); + + a.dump(); + b.dump(); + c.dump(); +} diff --git a/kabc/tests/testaddresseelist.cpp b/kabc/tests/testaddresseelist.cpp new file mode 100644 index 000000000..e7cc123f1 --- /dev/null +++ b/kabc/tests/testaddresseelist.cpp @@ -0,0 +1,196 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kstandarddirs.h> + +#include "addressbook.h" +#include "addresseelist.h" + +using namespace KABC; + +static const KCmdLineOptions options[] = +{ + { "save", "", 0 }, + { "number", "", 0 }, + KCmdLineLastOption +}; + +int main(int /*argc*/,char /* **argv*/) +{ +/* KAboutData aboutData("testaddresseelist","TestAddresseeList","0.1"); + KCmdLineArgs::init(argc, argv, &aboutData); + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app; + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); */ + + kdDebug() << "Creating addressees" << endl; + Addressee a, b, c, d, e, f; + a.setGivenName ("Peter"); + a.setFamilyName("Pan"); + a.setFormattedName("Pan, Peter"); + a.setUid("Asdf"); + b.setGivenName ("Phileas"); + b.setFamilyName("Fogg"); + b.setFormattedName("Fogg, Phileas"); + b.setUid("Rsdf"); + c.setGivenName ("Jim"); + c.setFamilyName("Hawkins"); + c.setFormattedName("Hawkins, Jim"); + c.setUid("Fhwn"); + d.setGivenName ("John"); + d.setFamilyName("Silver"); + d.setPrefix ("Long"); + d.setFormattedName("Long John Silver"); + d.setUid("Z2hk"); + e.setGivenName ("Alice"); + e.setFamilyName("Liddel"); + e.setFormattedName("Liddel, Alice"); + e.setUid("kk45"); + f.setGivenName ("Edmond"); + f.setFamilyName("Dantes"); + f.setFormattedName("Dantes, Edmond"); + f.setUid("78ze"); + + kdDebug() << "Adding to list" << endl; + AddresseeList list; + list.append(a); + list.append(b); + list.append(c); + list.append(d); + list.append(e); + list.append(f); + + list.sortBy(FamilyName); + if ( !( (*list.at(0)).uid()=="78ze" + && (*list.at(1)).uid()=="Rsdf" + && (*list.at(2)).uid()=="Fhwn" + && (*list.at(3)).uid()=="kk45" + && (*list.at(4)).uid()=="Asdf" + && (*list.at(5)).uid()=="Z2hk" + ) ) { + kdError() << "SORTING BY FAMILY NAME NOT CORRECT!" << endl; + kdDebug() << "list sorted by family name:" << endl; + list.dump(); + } else { + kdDebug() << "Sorting by family name correct." << endl; + } + list.setReverseSorting(true); + list.sort(); + if ( !( (*list.at(5)).uid()=="78ze" + && (*list.at(4)).uid()=="Rsdf" + && (*list.at(3)).uid()=="Fhwn" + && (*list.at(2)).uid()=="kk45" + && (*list.at(1)).uid()=="Asdf" + && (*list.at(0)).uid()=="Z2hk" + ) ) { + kdError() << "REVERSE SORTING BY FAMILY NAME NOT CORRECT!" << endl; + kdDebug() << "list reverse sorted by family name:" << endl; + list.dump(); + } else { + kdDebug() << "Reverse sorting by family name correct." << endl; + } + + list.setReverseSorting(false); + list.sortBy(FormattedName); + if ( !( (*list.at(0)).uid()=="78ze" + && (*list.at(1)).uid()=="Rsdf" + && (*list.at(2)).uid()=="Fhwn" + && (*list.at(3)).uid()=="kk45" + && (*list.at(4)).uid()=="Z2hk" + && (*list.at(5)).uid()=="Asdf" + ) ) { + kdError() << "SORTING BY FORMATTED NAME NOT CORRECT!" << endl; + kdDebug() << "list sorted by formatted name:" << endl; + list.dump(); + } else { + kdDebug() << "Sorting by formatted name correct." << endl; + } + list.setReverseSorting(true); + list.sort(); + if ( !( (*list.at(5)).uid()=="78ze" + && (*list.at(4)).uid()=="Rsdf" + && (*list.at(3)).uid()=="Fhwn" + && (*list.at(2)).uid()=="kk45" + && (*list.at(1)).uid()=="Z2hk" + && (*list.at(0)).uid()=="Asdf" + ) ) { + kdError() << "REVERSE SORTING BY FORMATTED NAME NOT CORRECT!" << endl; + kdDebug() << "list reverse sorted by formatted name:" << endl; + list.dump(); + } else { + kdDebug() << "Reverse sorting by formatted name correct." << endl; + } + + + list.setReverseSorting(false); + list.sortBy(Uid); + if ( !( (*list.at(0)).uid()=="78ze" + && (*list.at(1)).uid()=="Asdf" + && (*list.at(2)).uid()=="Fhwn" + && (*list.at(3)).uid()=="Rsdf" + && (*list.at(4)).uid()=="Z2hk" + && (*list.at(5)).uid()=="kk45" + ) ) { + kdError() << "SORTING BY UID NOT CORRECT!" << endl; + kdDebug() << "list sorted by Uid:" << endl; + list.dump(); + } else { + kdDebug() << "Sorting by Uid correct." << endl; + } + list.setReverseSorting(true); + list.sortBy(Uid); + if ( !( (*list.at(5)).uid()=="78ze" + && (*list.at(4)).uid()=="Asdf" + && (*list.at(3)).uid()=="Fhwn" + && (*list.at(2)).uid()=="Rsdf" + && (*list.at(1)).uid()=="Z2hk" + && (*list.at(0)).uid()=="kk45" + ) ) { + kdError() << "REVERSE SORTING BY UID NOT CORRECT!" << endl; + kdDebug() << "list sorted by Uid:" << endl; + list.dump(); + } else { + kdDebug() << "Reverse sorting by Uid correct." << endl; + } + + // zero, one or two entries might give errors in a poor sorting + // implementation + kdDebug() << "sorting empty list" << endl; + AddresseeList list2; + list2.sort(); + + kdDebug() << "sorting one entry list" << endl; + list2.append(a); + list2.sort(); + + kdDebug() << "sorting two entry list" << endl; + list2.append(f); + list2.setReverseSorting(false); + list2.sort(); + if ( !( (*list2.at(0)).uid()=="78ze" + && (*list2.at(1)).uid()=="Asdf" + ) ) { + kdError() << "SORTING BY FORMATTED NAME IN A TWO ENTRY LIST NOT CORRECT!" << endl; + kdDebug() << "list sorted by formatted name, two entries:" << endl; + list2.dump(); + } else { + kdDebug() << "Sorting by FormattedName in a two entry list correct." << endl; + } + list2.setReverseSorting(true); + list2.sort(); + if ( !( (*list2.at(1)).uid()=="78ze" + && (*list2.at(0)).uid()=="Asdf" + ) ) { + kdError() << "REVERSE SORTING BY FORMATTED NAME IN A TWO ENTRY LIST NOT CORRECT!" << endl; + kdDebug() << "list reverse sorted by formatted name, two entries:" << endl; + list2.dump(); + } else { + kdDebug() << "Reverse sorting by FormattedName in a two entry list correct." << endl; + } + +} + + diff --git a/kabc/tests/testaddressfmt.cpp b/kabc/tests/testaddressfmt.cpp new file mode 100644 index 000000000..f422ab692 --- /dev/null +++ b/kabc/tests/testaddressfmt.cpp @@ -0,0 +1,63 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kstandarddirs.h> + +#include "addressbook.h" +#include "address.h" + +using namespace KABC; + +static const KCmdLineOptions options[] = +{ + { "save", "", 0 }, + { "number", "", 0 }, + KCmdLineLastOption +}; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testaddressfmt","TestAddressFormat","0.1"); + KCmdLineArgs::init(argc, argv, &aboutData); + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app; + + Address a; + a.setStreet("Lummerlandstr. 1"); + a.setPostalCode("12345"); + a.setLocality("Lummerstadt"); + a.setCountry ("Germany"); + + Address b; + b.setStreet("457 Foobar Ave"); + b.setPostalCode("1A2B3C"); + b.setLocality("Nervousbreaktown"); + b.setRegion("DC"); + b.setCountry("United States of America"); + + Address c; + c.setStreet("Lummerlandstr. 1"); + c.setPostalCode("12345"); + c.setLocality("Lummerstadt"); + c.setCountry ("Deutschland"); + + Address d; + d.setStreet("Lummerlandstr. 1"); + d.setPostalCode("12345"); + d.setLocality("Lummerstadt"); + d.setCountry (""); + + qDebug( "-------------------------------------\nShould have german address formatting, local country formatting\n" ); + qDebug( a.formattedAddress("Jim Knopf").latin1() ); + qDebug( "-------------------------------------\nShould have US address formatting, local country formatting\n" ); + qDebug( b.formattedAddress("Huck Finn").latin1() ); + qDebug( "-------------------------------------\nShould have german address formatting, local country formatting\n" ); + qDebug( c.formattedAddress("Jim Knopf").latin1() ); + qDebug( "-------------------------------------\nShould have local address formatting, local country formatting\n" ); + qDebug( d.formattedAddress("Jim Knopf").latin1() ); +} + + diff --git a/kabc/tests/testaddresslineedit.cpp b/kabc/tests/testaddresslineedit.cpp new file mode 100644 index 000000000..70c07b446 --- /dev/null +++ b/kabc/tests/testaddresslineedit.cpp @@ -0,0 +1,29 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "addresslineedit.h" + +using namespace KABC; + +int main( int argc,char **argv ) +{ + KAboutData aboutData( "testaddresslineedit", + I18N_NOOP( "Test Address LineEdit" ), "0.1" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + + KApplication app; + + AddressLineEdit *lineEdit = new AddressLineEdit( 0 ); + + lineEdit->show(); + app.setMainWidget( lineEdit ); + + QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); + + app.exec(); + + delete lineEdit; +} diff --git a/kabc/tests/testdb.cpp b/kabc/tests/testdb.cpp new file mode 100644 index 000000000..f94397a62 --- /dev/null +++ b/kabc/tests/testdb.cpp @@ -0,0 +1,33 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "addressbook.h" +#include "vcardformat.h" +#include "resourcesql.h" + +using namespace KABC; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testdb","TestKabcDB","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + +// KApplication app( false, false ); + KApplication app; + + AddressBook ab; + + ResourceSql r( &ab, "root", "kde4ever", "localhost" ); + if ( ! r.open() ) { + kdDebug() << "Failed to open resource." << endl; + } + + r.load( &ab ); + + r.close(); + + ab.dump(); +} diff --git a/kabc/tests/testdistlist.cpp b/kabc/tests/testdistlist.cpp new file mode 100644 index 000000000..a81f8c0dc --- /dev/null +++ b/kabc/tests/testdistlist.cpp @@ -0,0 +1,59 @@ +#include <qwidget.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "stdaddressbook.h" + +#include "distributionlisteditor.h" +#include "distributionlist.h" + +using namespace KABC; + +static const KCmdLineOptions options[] = +{ + {"list <listname>", I18N_NOOP("Show distribution list with name <listname>"), 0}, + KCmdLineLastOption +}; + + +int main(int argc,char **argv) +{ + KAboutData aboutData("testdistlist",I18N_NOOP("Test Distribution Lists"),"0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->isSet("list")) { + QString name = args->getOption("list"); + + DistributionListManager *manager = + new DistributionListManager( StdAddressBook::self() ); + manager->load(); + DistributionList *list = manager->list( name ); + if ( !list ) { + kdDebug() << "No list with name '" << name << "'" << endl; + return 1; + } else { + kdDebug() << "RESULT: " << list->emails().join(", ") << endl; + return 0; + } + } + + DistributionListEditor *editor = + new DistributionListEditor( StdAddressBook::self(), 0 ); + + editor->show(); + app.setMainWidget(editor); + + QObject::connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); + + app.exec(); + + delete editor; +} diff --git a/kabc/tests/testkabc.cpp b/kabc/tests/testkabc.cpp new file mode 100644 index 000000000..15fa11c44 --- /dev/null +++ b/kabc/tests/testkabc.cpp @@ -0,0 +1,62 @@ +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kstandarddirs.h> + +#include <qfile.h> +#include <qimage.h> + +#include "geo.h" +#include "secrecy.h" +#include "stdaddressbook.h" +#include "timezone.h" +#include "key.h" +#include "agent.h" +#include "vcardconverter.h" + +using namespace KABC; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testkabc",I18N_NOOP("TestKabc"),"0.1"); + KCmdLineArgs::init(argc, argv, &aboutData); + + KApplication app( false, false ); + AddressBook *ab = StdAddressBook::self(); + +#define READ + +#ifdef READ + AddressBook::Iterator it; + for ( it = ab->begin(); it != ab->end(); ++it ) { + QString vcard; + VCardConverter converter; + converter.addresseeToVCard( *it, vcard ); + kdDebug() << "card=" << vcard << endl; + } +#else + Addressee addr; + + addr.setGivenName("Tobias"); + addr.setFamilyName("Koenig"); + + + Picture pic; + QImage img; + img.load("/home/tobias/test.png"); +/* + pic.setData(img); + pic.setType(QImage::imageFormat("/home/tobias/test.png")); +*/ + pic.setUrl("http://www.mypict.de"); + addr.setLogo( pic ); + + ab->insertAddressee( addr ); + + StdAddressBook::save(); +#endif + + return 0; +} diff --git a/kabc/tests/testkabcdlg.cpp b/kabc/tests/testkabcdlg.cpp new file mode 100644 index 000000000..c497a9ead --- /dev/null +++ b/kabc/tests/testkabcdlg.cpp @@ -0,0 +1,45 @@ +#include <qwidget.h> + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> + +#include "addresseedialog.h" + +using namespace KABC; + +static const KCmdLineOptions options[] = +{ + {"multiple", I18N_NOOP("Allow selection of multiple addressees"), 0}, + KCmdLineLastOption +}; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testkabcdlg",I18N_NOOP("TestKabc"),"0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->isSet("multiple")) { + Addressee::List al = AddresseeDialog::getAddressees( 0 ); + Addressee::List::ConstIterator it; + kdDebug() << "Selected Addressees:" << endl; + for( it = al.begin(); it != al.end(); ++it ) { + kdDebug() << " " << (*it).fullEmail() << endl; + } + } else { + Addressee a = AddresseeDialog::getAddressee( 0 ); + + if ( !a.isEmpty() ) { + kdDebug() << "Selected Addressee:" << endl; + a.dump(); + } else { + kdDebug() << "No Addressee selected." << endl; + } + } +} diff --git a/kabc/tests/testldapclient.cpp b/kabc/tests/testldapclient.cpp new file mode 100644 index 000000000..f4616d16c --- /dev/null +++ b/kabc/tests/testldapclient.cpp @@ -0,0 +1,161 @@ +/* This file is part of the KDE project + Copyright (C) 2005 David Faure <faure@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "testldapclient.h" + +#include <kapplication.h> +#include <kdebug.h> +#include <kcmdlineargs.h> + +#include <qeventloop.h> + +#include <assert.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + KApplication::disableAutoDcopRegistration(); + KCmdLineArgs::init(argc,argv,"testldapclient", 0, 0, 0, 0); + KApplication app; + + TestLDAPClient test; + test.setup(); + test.runAll(); + test.cleanup(); + kdDebug() << "All tests OK." << endl; + return 0; +} + +void TestLDAPClient::setup() +{ +} + +void TestLDAPClient::runAll() +{ + testIntevation(); +} + +bool TestLDAPClient::check(const QString& txt, QString a, QString b) +{ + if (a.isEmpty()) + a = QString::null; + if (b.isEmpty()) + b = QString::null; + if (a == b) { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "ok" << endl; + } + else { + kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << "'... " << "KO !" << endl; + cleanup(); + exit(1); + } + return true; +} + +void TestLDAPClient::cleanup() +{ + mClient = 0; +} + +void TestLDAPClient::testIntevation() +{ + kdDebug() << k_funcinfo << endl; + mClient = new LdapClient( this ); + + mClient->setHost( "ca.intevation.de" ); + mClient->setPort( "389" ); + mClient->setBase( "o=Intevation GmbH,c=de" ); + + // Same list as in kaddressbook's ldapsearchdialog + QStringList attrs; + attrs << "l" << "Company" << "co" << "department" << "description" << "mail" << "facsimileTelephoneNumber" << "cn" << "homePhone" << "mobile" << "o" << "pager" << "postalAddress" << "st" << "street" << "title" << "uid" << "telephoneNumber" << "postalCode" << "objectClass"; + // the list from ldapclient.cpp + //attrs << "cn" << "mail" << "givenname" << "sn" << "objectClass"; + mClient->setAttrs( attrs ); + + // Taken from LdapSearch + //QString mSearchText = QString::fromUtf8( "Till" ); + //QString filter = QString( "&(|(objectclass=person)(objectclass=groupOfNames)(mail=*))(|(cn=%1*)(mail=%2*)(givenName=%3*)(sn=%4*))" ) + // .arg( mSearchText ).arg( mSearchText ).arg( mSearchText ).arg( mSearchText ); + + // For some reason a fromUtf8 broke the search for me (no results). + // But this certainly looks fishy, it might break on non-utf8 systems. + QString filter = "&(|(objectclass=person)(objectclass=groupofnames)(mail=*))(|(cn=*Ägypten MDK*)(sn=*Ägypten MDK*))"; + + connect( mClient, SIGNAL( result( const KABC::LdapObject& ) ), + this, SLOT( slotLDAPResult( const KABC::LdapObject& ) ) ); + connect( mClient, SIGNAL( done() ), + this, SLOT( slotLDAPDone() ) ); + connect( mClient, SIGNAL( error( const QString& ) ), + this, SLOT( slotLDAPError( const QString& ) ) ); + mClient->startQuery( filter ); + kapp->eventLoop()->enterLoop(); + delete mClient; mClient = 0; +} + +// from kaddressbook... ugly though... +static QString asUtf8( const QByteArray &val ) +{ + if ( val.isEmpty() ) + return QString::null; + + const char *data = val.data(); + + //QString::fromUtf8() bug workaround + if ( data[ val.size() - 1 ] == '\0' ) + return QString::fromUtf8( data, val.size() - 1 ); + else + return QString::fromUtf8( data, val.size() ); +} + +static QString join( const KABC::LdapAttrValue& lst, const QString& sep ) +{ + QString res; + bool already = false; + for ( KABC::LdapAttrValue::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { + if ( already ) + res += sep; + already = TRUE; + res += asUtf8( *it ); + } + return res; +} + +void TestLDAPClient::slotLDAPResult( const KABC::LdapObject& obj ) +{ + QString cn = join( obj.attrs[ "cn" ], ", " ); + kdDebug() << " cn:" << cn << endl; + assert( !obj.attrs[ "mail" ].isEmpty() ); + QString mail = join( obj.attrs[ "mail" ], ", " ); + kdDebug() << " mail:" << mail << endl; + assert( mail.contains( '@' ) ); +} + +void TestLDAPClient::slotLDAPError( const QString& err ) +{ + kdDebug() << k_funcinfo << err << endl; + ::exit( 1 ); +} + +void TestLDAPClient::slotLDAPDone() +{ + kdDebug() << k_funcinfo << endl; + kapp->eventLoop()->exitLoop(); +} + +#include "testldapclient.moc" diff --git a/kabc/tests/testldapclient.h b/kabc/tests/testldapclient.h new file mode 100644 index 000000000..583ead073 --- /dev/null +++ b/kabc/tests/testldapclient.h @@ -0,0 +1,51 @@ +/* This file is part of the KDE project + Copyright (C) 2005 David Faure <faure@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef TESTLDAPCLIENT_H +#define TESTLDAPCLIENT_H + +#include <qobject.h> + +#include "../ldapclient.h" +typedef KABC::LdapClient LdapClient; + +class TestLDAPClient : public QObject +{ + Q_OBJECT + +public: + TestLDAPClient() {} + void setup(); + void runAll(); + void cleanup(); + + // tests + void testIntevation(); + +private slots: + void slotLDAPResult( const KABC::LdapObject& ); + void slotLDAPError( const QString& ); + void slotLDAPDone(); + +private: + bool check(const QString& txt, QString a, QString b); + + LdapClient* mClient; +}; + +#endif diff --git a/kabc/tests/testlock.cpp b/kabc/tests/testlock.cpp new file mode 100644 index 000000000..c922c7a7e --- /dev/null +++ b/kabc/tests/testlock.cpp @@ -0,0 +1,206 @@ +/* + This file is part of libkabc. + + Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "testlock.h" + +#include "stdaddressbook.h" + +#include <kaboutdata.h> +#include <kapplication.h> +#include <kdebug.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kdirwatch.h> + +#include <kmessagebox.h> +#include <kdialog.h> + +#include <qwidget.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qlistview.h> +#include <qdir.h> + +#include <iostream> + +#include <sys/types.h> +#include <unistd.h> + +using namespace KABC; + +LockWidget::LockWidget( const QString &identifier ) +{ + QVBoxLayout *topLayout = new QVBoxLayout( this ); + topLayout->setMargin( KDialog::marginHint() ); + topLayout->setSpacing( KDialog::spacingHint() ); + + if ( identifier.isEmpty() ) { + mLock = 0; + } else { + mLock = new Lock( identifier ); + + int pid = getpid(); + + QLabel *pidLabel = new QLabel( "Process ID: " + QString::number( pid ), + this ); + topLayout->addWidget( pidLabel ); + + QHBoxLayout *identifierLayout = new QHBoxLayout( topLayout ); + + QLabel *resourceLabel = new QLabel( "Identifier:", this ); + identifierLayout->addWidget( resourceLabel ); + + QLabel *resourceIdentifier = new QLabel( identifier, this ); + identifierLayout->addWidget( resourceIdentifier ); + + mStatus = new QLabel( "Status: Unlocked", this ); + topLayout->addWidget( mStatus ); + + QPushButton *button = new QPushButton( "Lock", this ); + topLayout->addWidget( button ); + connect( button, SIGNAL( clicked() ), SLOT( lock() ) ); + + button = new QPushButton( "Unlock", this ); + topLayout->addWidget( button ); + connect( button, SIGNAL( clicked() ), SLOT( unlock() ) ); + } + + mLockView = new QListView( this ); + topLayout->addWidget( mLockView ); + mLockView->addColumn( "Lock File" ); + mLockView->addColumn( "PID" ); + mLockView->addColumn( "Locking App" ); + + updateLockView(); + + QPushButton *quitButton = new QPushButton( "Quit", this ); + topLayout->addWidget( quitButton ); + connect( quitButton, SIGNAL( clicked() ), SLOT( close() ) ); + + KDirWatch *watch = KDirWatch::self(); + connect( watch, SIGNAL( dirty( const QString & ) ), + SLOT( updateLockView() ) ); + connect( watch, SIGNAL( created( const QString & ) ), + SLOT( updateLockView() ) ); + connect( watch, SIGNAL( deleted( const QString & ) ), + SLOT( updateLockView() ) ); + watch->addDir( Lock::locksDir() ); + watch->startScan(); +} + +LockWidget::~LockWidget() +{ + delete mLock; +} + +void LockWidget::updateLockView() +{ + mLockView->clear(); + + QDir dir( Lock::locksDir() ); + + QStringList files = dir.entryList( "*.lock" ); + + QStringList::ConstIterator it; + for( it = files.begin(); it != files.end(); ++it ) { + if ( *it == "." || *it == ".." ) continue; + + QString app; + int pid; + if ( !Lock::readLockFile( dir.filePath( *it ), pid, app ) ) { + kdWarning() << "Unable to open lock file '" << *it << "'" << endl; + } else { + new QListViewItem( mLockView, *it, QString::number( pid ), app ); + } + } +} + +void LockWidget::lock() +{ + if ( !mLock->lock() ) { + KMessageBox::sorry( this, mLock->error() ); + } else { + mStatus->setText( "Status: Locked" ); + } +} + +void LockWidget::unlock() +{ + if ( !mLock->unlock() ) { + KMessageBox::sorry( this, mLock->error() ); + } else { + mStatus->setText( "Status: Unlocked" ); + } +} + + +static const KCmdLineOptions options[] = +{ + { "a", 0, 0 }, + { "addressbook", "Standard address book", 0 }, + { "d", 0, 0 }, + { "diraddressbook", "Standard address book directory resource", 0 }, + { "+identifier", "Identifier of resource to be locked, e.g. filename", 0 }, + KCmdLineLastOption +}; + +int main(int argc,char **argv) +{ + KAboutData aboutData("testlock",I18N_NOOP("Test libkabc Lock"),"0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + QString identifier; + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if ( args->count() == 1 ) { + identifier = args->arg( 0 ); + } else if ( args->count() != 0 ) { + std::cerr << "Usage: testlock <identifier>" << std::endl; + return 1; + } + + if ( args->isSet( "addressbook" ) ) { + if ( args->count() == 1 ) { + std::cerr << "Ignoring resource identifier" << std::endl; + } + identifier = StdAddressBook::fileName(); + } + + if ( args->isSet( "diraddressbook" ) ) { + if ( args->count() == 1 ) { + std::cerr << "Ignoring resource identifier" << std::endl; + } + identifier = StdAddressBook::directoryName(); + } + + LockWidget mainWidget( identifier ); + + kapp->setMainWidget( &mainWidget ); + mainWidget.show(); + + return app.exec(); +} + +#include "testlock.moc" diff --git a/kabc/tests/testlock.h b/kabc/tests/testlock.h new file mode 100644 index 000000000..16c128bf1 --- /dev/null +++ b/kabc/tests/testlock.h @@ -0,0 +1,51 @@ +/* + This file is part of libkabc. + + Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef KABC_TESTLOCK_H +#define KABC_TESTLOCK_H + +#include "lock.h" + +#include <qwidget.h> + +class QLabel; +class QListView; + +class KABC_EXPORT LockWidget : public QWidget +{ + Q_OBJECT + public: + LockWidget( const QString &identifier ); + ~LockWidget(); + + protected slots: + void lock(); + void unlock(); + + void updateLockView(); + + private: + KABC::Lock *mLock; + + QLabel *mStatus; + QListView *mLockView; +}; + +#endif |