summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tests
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/protocols/groupwise/libgroupwise/tests
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.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/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/protocols/groupwise/libgroupwise/tests')
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/Makefile.am22
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/client_test.cpp10
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.cpp107
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.h57
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/coreprotocol_test.cpp30
-rw-r--r--kopete/protocols/groupwise/libgroupwise/tests/field_test.cpp154
6 files changed, 380 insertions, 0 deletions
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/Makefile.am b/kopete/protocols/groupwise/libgroupwise/tests/Makefile.am
new file mode 100644
index 00000000..33a603ad
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/Makefile.am
@@ -0,0 +1,22 @@
+INCLUDES = -I$(top_srcdir)/kopete/protocols/groupwise/libgroupwise/qca/src \
+ -I$(top_srcdir)/kopete/protocols/groupwise/libgroupwise \
+ -I$(top_srcdir)/kopete/protocols/groupwise \
+ $(all_includes)
+METASOURCES = AUTO
+noinst_PROGRAMS = clientstream_test field_test coreprotocol_test client_test
+coreprotocol_test_LDFLAGS = -no-undefined $(all_libraries)
+coreprotocol_test_SOURCES = coreprotocol_test.cpp
+coreprotocol_test_LDADD = \
+ ../libgwtest.la -lqt-mt
+field_test_LDFLAGS = -no-undefined $(all_libraries)
+field_test_SOURCES = field_test.cpp
+field_test_LDADD = \
+ ../libgwtest.la -lqt-mt
+
+clientstream_test_SOURCES = clientstream_test.cpp
+clientstream_test_LDADD = -lqt-mt \
+ ../../kopete_groupwise.la
+
+client_test_SOURCES = client_test.cpp
+client_test_LDADD = ../../../../protocols/groupwise/kopete_groupwise.la \
+ ../libgwtest.la -lqt-mt
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/client_test.cpp b/kopete/protocols/groupwise/libgroupwise/tests/client_test.cpp
new file mode 100644
index 00000000..22f92282
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/client_test.cpp
@@ -0,0 +1,10 @@
+#include "client.h"
+#include "task.h"
+
+int main()
+{
+ Client c;
+ Task rootTask( &c, true );
+
+ return 0;
+}
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.cpp b/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.cpp
new file mode 100644
index 00000000..bbd10ee8
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.cpp
@@ -0,0 +1,107 @@
+#include "clientstream_test.h"
+
+ClientStreamTest::ClientStreamTest(int argc, char ** argv) : QApplication( argc, argv )
+{
+ // set up client stream
+ myConnector = new KNetworkConnector( 0 );
+ //myConnector->setOptHostPort( "localhost", 8300 );
+ myConnector->setOptHostPort( "reiser.suse.de", 8300 );
+ myConnector->setOptSSL( true );
+ Q_ASSERT( QCA::isSupported(QCA::CAP_TLS) );
+ myTLS = new QCA::TLS;
+ myTLSHandler = new QCATLSHandler( myTLS );
+ myTestObject = new ClientStream( myConnector, myTLSHandler, 0);
+ // notify when the transport layer is connected
+ connect( myTestObject, SIGNAL( connected() ), SLOT( slotConnected() ) );
+ // it's necessary to catch this signal and tell the TLS handler to proceed, even if we don't check cert validity
+ connect( myTLSHandler, SIGNAL(tlsHandshaken()), SLOT(slotTLSHandshaken()) );
+ // notify and start sending
+ connect( myTestObject, SIGNAL( securityLayerActivated(int) ), SLOT( slotSend(int) ) );
+ connect( myTestObject, SIGNAL( warning(int) ), SLOT( slotWarning(int) ) );
+
+ // do test once the event loop is running
+ QTimer::singleShot( 0, this, SLOT( slotDoTest() ) );
+}
+
+ClientStreamTest::~ClientStreamTest()
+{
+ delete myTestObject;
+ delete myTLSHandler;
+ delete myTLS;
+ delete myConnector;
+}
+
+void ClientStreamTest::slotDoTest()
+{
+ NovellDN dn;
+ dn.dn = "maeuschen";
+ dn.server = "reiser.suse.de";
+ // connect to server
+ qDebug( "connecting to server ");
+ myTestObject->connectToServer( dn, true ); // fine up to here...
+}
+
+void ClientStreamTest::slotConnected()
+{
+ qDebug( "connection is up");
+}
+
+void ClientStreamTest::slotWarning(int warning)
+{
+ qDebug( "warning: %i", warning);
+}
+
+void ClientStreamTest::slotsend(int layer)
+{
+ qDebug( "security layer is up: %i", layer);
+ RequestFactory testFactory;
+ // we're not connecting...
+ qDebug( "sending request" );
+ // send a request
+ QCString command("login");
+ Request * firstRequest = testFactory.request( command );
+ Field::FieldList lst;
+ lst.append( new Field::SingleField( NM_A_SZ_USERID, 0, NMFIELD_TYPE_UTF8, "maeuschen" ) );
+ lst.append( new Field::SingleField( NM_A_SZ_CREDENTIALS, 0, NMFIELD_TYPE_UTF8, "maeuschen" ) );
+ lst.append( new Field::SingleField( NM_A_SZ_USER_AGENT, 0, NMFIELD_TYPE_UTF8, "libgroupwise/0.1 (linux, 2.6.5-7.97-smp)" ) );
+ lst.append( new Field::SingleField( NM_A_UD_BUILD, 0, NMFIELD_TYPE_UDWORD, 2 ) );
+ lst.append( new Field::SingleField( NM_A_IP_ADDRESS, 0, NMFIELD_TYPE_UTF8, "10.10.11.103" ) );
+ firstRequest->setFields( lst );
+ myTestObject->write( firstRequest );
+ qDebug( "done");
+}
+
+void ClientStreamTest::slotTLSHandshaken()
+{
+ qDebug( "TLS handshake complete" );
+ int validityResult = myTLS->certificateValidityResult ();
+
+ if( validityResult == QCA::TLS::Valid )
+ {
+ qDebug( "Certificate is valid, continuing.");
+ // valid certificate, continue
+ myTLSHandler->continueAfterHandshake ();
+ }
+ else
+ {
+ qDebug( "Certificate is not valid, continuing" );
+ // certificate is not valid, query the user
+ /* if(handleTLSWarning (validityResult, server (), myself()->contactId ()) == KMessageBox::Continue)
+ {*/
+ myTLSHandler->continueAfterHandshake ();
+ /* }
+ else
+ {
+ disconnect ( Kopete::Account::Manual );
+ }*/
+ }
+
+}
+int main(int argc, char ** argv)
+{
+ ClientStreamTest a( argc, argv );
+ a.exec();
+ return 0;
+}
+
+#include "clientstream_test.moc"
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.h b/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.h
new file mode 100644
index 00000000..2c77f4e1
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/clientstream_test.h
@@ -0,0 +1,57 @@
+//
+// C++ Implementation: clientstream_test
+//
+// Description:
+//
+//
+// Author: Kopete Developers <[email protected]>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef clientstream_test_h
+#define clientstream_test_h
+
+#include <qglobal.h>
+#include <qapplication.h>
+#include <qtimer.h>
+
+#include "gwclientstream.h"
+#include "gwconnector.h"
+#include <qca.h>
+#include "qcatlshandler.h"
+#include "requestfactory.h"
+#include "request.h"
+#include "usertransfer.h"
+
+#include "coreprotocol.h"
+
+#define QT_FATAL_ASSERT 1
+
+class ClientStreamTest : public QApplication
+{
+Q_OBJECT
+public:
+ ClientStreamTest(int argc, char ** argv);
+
+ ~ClientStreamTest();
+
+public slots:
+ void slotDoTest();
+
+ void slotConnected();
+
+ void slotWarning(int warning);
+
+ void slotsend(int layer);
+ void slotTLSHandshaken();
+
+private:
+ KNetworkConnector *myConnector;
+ QCA::TLS *myTLS;
+ QCATLSHandler *myTLSHandler;
+ ClientStream *myTestObject;
+};
+
+#endif
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/coreprotocol_test.cpp b/kopete/protocols/groupwise/libgroupwise/tests/coreprotocol_test.cpp
new file mode 100644
index 00000000..d1de6084
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/coreprotocol_test.cpp
@@ -0,0 +1,30 @@
+//
+// C++ Implementation: coreprotocol_test
+//
+// Description:
+//
+//
+// Author: Kopete Developers <[email protected]>, (C) 2004
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "requestfactory.h"
+#include "request.h"
+#include "usertransfer.h"
+
+#include "coreprotocol.h"
+
+int main()
+{
+ CoreProtocol testObject;
+ RequestFactory testFactory;
+ QCString command("login");
+ Request * firstRequest = testFactory.request( command );
+ Field::FieldList lst;
+ lst.append( new Field::SingleField( NM_A_SZ_USERID, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_UTF8, "[email protected]" ) );
+ firstRequest->setFields( lst );
+ testObject.outgoingTransfer( firstRequest );
+ return 0;
+}
diff --git a/kopete/protocols/groupwise/libgroupwise/tests/field_test.cpp b/kopete/protocols/groupwise/libgroupwise/tests/field_test.cpp
new file mode 100644
index 00000000..eec3f1f2
--- /dev/null
+++ b/kopete/protocols/groupwise/libgroupwise/tests/field_test.cpp
@@ -0,0 +1,154 @@
+#include "gwfield.h"
+#include <stdio.h>
+
+static Field::FieldList fl;
+
+void buildList();
+void buildFakeContactList();
+void extractFields( Field::FieldList );
+
+int main()
+{
+ buildFakeContactList();
+ // look for a field in the list
+/* if ( fl.find( NM_A_FA_MESSAGE ) != fl.end() )
+ printf( "Found a field, where there was supposed to be one :)\n" );
+ else
+ printf( "Didn't find a field, where there was supposed to be one :(\n" );
+ Field::FieldListIterator it;
+ if ( (it = fl.find( NM_A_SZ_OBJECT_ID ) ) != fl.end() )
+ printf( "Found a field, where there was NOT supposed to be one :(\n" );
+ else
+ printf( "Didn't find a field, where there wasn't supposed to be one :)\n" );*/
+ //printf( "%i\n", static_cast<Field::MultiField*>(*it) );
+ // dump the list
+ fl.dump( true );
+
+ printf( "\nNow testing find routines.\n");
+ // find the field containing the contact list
+ Field::MultiField * clf = dynamic_cast< Field::MultiField * >( *(fl.find( NM_A_FA_CONTACT_LIST ) ) );
+ if ( clf )
+ {
+ Field::FieldList cl = clf->fields();
+ // look for a folder in the list
+ Field::FieldListIterator it = cl.find( NM_A_FA_FOLDER );
+ if ( it != cl.end() )
+ printf( "Found the first folder :)\n");
+ else
+ printf( "Didn't find the first folder, where did it go? :(\n");
+
+ printf( "Looking for a second folder :)\n");
+ it = cl.find( ++it, NM_A_FA_FOLDER );
+ if ( it == cl.end() )
+ printf( "Didn't find a second folder :)\n" );
+ else
+ printf( "Found a second folder, now did that get there? :(\n");
+ }
+ else
+ printf( "Didn't find the contact list, where did it go? :(\n");
+
+ //extractFields( fl );
+ return 0;
+}
+// test Field subclasses by creating various FieldLists and recovering the data
+
+void buildList()
+{
+ // STRUCTURE
+ // fl - top list
+ // sf - faust quote
+ // mf - Multifield - participants, containing
+ // nl - nested list
+ // sf - contactlist (empty field array)
+ // sf - message body
+
+ Field::SingleField* sf = new Field::SingleField( NM_A_FA_MESSAGE, 0, NMFIELD_TYPE_UTF8, QString::fromLatin1( "Da steh ich nun, ich armer Tor! Und bin so klug als wie zuvor..." ) );
+ fl.append( sf );
+ sf = new Field::SingleField( NM_A_SZ_TRANSACTION_ID, 0, NMFIELD_TYPE_UTF8, QString::fromLatin1( "maeuschen" ) );
+ fl.append( sf );
+ // nested list
+ Field::FieldList nl;
+ sf = new Field::SingleField( NM_A_SZ_STATUS, 0, NMFIELD_TYPE_UDWORD, 123 );
+ nl.append( sf );
+ sf = new Field::SingleField( NM_A_SZ_MESSAGE_BODY, 0, NMFIELD_TYPE_UTF8, QString::fromLatin1( "bla bla" ) );
+ nl.append( sf );
+ Field::MultiField* mf = new Field::MultiField( NM_A_FA_PARTICIPANTS, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY );
+ mf->setFields( nl );
+ fl.append( mf );
+
+/* Field::SingleField * ext = sf;
+ printf( "tag: %s flags: %i type: %i value: %s\n", ext->tag().data(), ext->flags(), ext->type(), ext->value().toString().ascii() );*/
+}
+
+void buildFakeContactList()
+{
+ using namespace Field;
+
+ FieldList contactlist;
+ // add a few contacts
+ {
+ const char* names[] = { "apple", "banana", "cherry", "damson", "elderberry", "framboise" };
+ for ( int i = 0; i < 6; i ++ )
+ {
+ FieldList contact;
+ Field::SingleField* sf = new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, QString::number( i ) );
+ contact.append( sf );
+ sf = new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, names[i] );
+ contact.append( sf );
+ MultiField* mf = new MultiField( NM_A_FA_CONTACT, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, contact );
+ contactlist.append( mf );
+ }
+ }
+ // add a folder
+ {
+ FieldList folder;
+ Field::SingleField* sf = new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, QString::number( 1 ) );
+ folder.append( sf );
+ sf = new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, "buddies" );
+ folder.append( sf );
+ MultiField* mf = new MultiField( NM_A_FA_FOLDER, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, folder );
+ contactlist.append( mf );
+ }
+ // add some more contacts
+ {
+ const char* names[] = { "aardvark", "boar", "cat" };
+ for ( int i = 0; i < 3; i ++ )
+ {
+ FieldList contact;
+ Field::SingleField* sf = new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, QString::number( i ) );
+ contact.append( sf );
+ sf = new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, names[i] );
+ contact.append( sf );
+ MultiField* mf = new MultiField( NM_A_FA_CONTACT, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, contact );
+ contactlist.append( mf );
+ }
+ }
+
+
+ MultiField * cl = new MultiField( NM_A_FA_CONTACT_LIST, NMFIELD_METHOD_VALID, 0, NMFIELD_TYPE_ARRAY, contactlist );
+ fl.append( cl );
+}
+
+void extractFields( Field::FieldList l )
+{
+ Field::FieldListIterator it;
+ printf ("iterating over %i fields\n", l.count() );
+ for ( it = l.begin(); it != l.end() ; ++it )
+ {
+ printf ("field\n");
+ Field::SingleField * ext = dynamic_cast<Field::SingleField *>( *it );
+ if ( ext )
+ printf( "tag: %s flags: %i type: %i value: %s\n", ext->tag().data(), ext->flags(), ext->type(), ext->value().toString().ascii() );
+ else
+ {
+ Field::MultiField* mf = dynamic_cast<Field::MultiField *>( *it );
+ if ( mf )
+ {
+ printf( "found a multi value field\n" );
+ extractFields( mf->fields() );
+ }
+ }
+ }
+
+ printf ("done\n");
+}