summaryrefslogtreecommitdiffstats
path: root/libtdepim/komposer/core/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libtdepim/komposer/core/tests')
-rw-r--r--libtdepim/komposer/core/tests/Makefile.am20
-rw-r--r--libtdepim/komposer/core/tests/main.cpp52
-rw-r--r--libtdepim/komposer/core/tests/managertest.cpp43
-rw-r--r--libtdepim/komposer/core/tests/managertest.h45
-rw-r--r--libtdepim/komposer/core/tests/tester.cpp30
-rw-r--r--libtdepim/komposer/core/tests/tester.h71
-rw-r--r--libtdepim/komposer/core/tests/testfactory.h71
-rw-r--r--libtdepim/komposer/core/tests/testkomposer.cpp18
-rw-r--r--libtdepim/komposer/core/tests/testmanager.cpp53
-rw-r--r--libtdepim/komposer/core/tests/testmanager.h26
10 files changed, 429 insertions, 0 deletions
diff --git a/libtdepim/komposer/core/tests/Makefile.am b/libtdepim/komposer/core/tests/Makefile.am
new file mode 100644
index 000000000..fbf127956
--- /dev/null
+++ b/libtdepim/komposer/core/tests/Makefile.am
@@ -0,0 +1,20 @@
+INCLUDES = -I$(top_builddir)/libtdepim/komposer/core $(all_includes)
+
+check_PROGRAMS = testfactory testmanager testkomposer
+
+METASOURCES = AUTO
+
+testfactory_SOURCES = main.cpp managertest.cpp
+testfactory_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor
+testfactory_LDADD = ../libkomposer.la
+
+testmanager_SOURCES = testmanager.cpp
+testmanager_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor
+testmanager_LDADD = ../libkomposer.la
+
+testkomposer_SOURCES = testkomposer.cpp
+testkomposer_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_KDECORE) $(LIB_KDEUI) -ltdefx $(LIB_KIO) -lktexteditor
+testkomposer_LDADD = ../libkomposer.la
+
+check: testfactory
+ @./testfactory 2>&1 | grep "tests:"
diff --git a/libtdepim/komposer/core/tests/main.cpp b/libtdepim/komposer/core/tests/main.cpp
new file mode 100644
index 000000000..4a33a2f13
--- /dev/null
+++ b/libtdepim/komposer/core/tests/main.cpp
@@ -0,0 +1,52 @@
+/**
+ * main.cpp
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include "testfactory.h"
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kcmdlineargs.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
+static const KCmdLineOptions options[] =
+{
+ {"verbose", "Verbose output", 0},
+ KCmdLineLastOption
+};
+int main( int argc, char** argv )
+{
+ KAboutData aboutData( "tests","Test","0.1" );
+ KCmdLineArgs::init( argc, argv, &aboutData );
+ KCmdLineArgs::addCmdLineOptions( options );
+
+ KApplication app;
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+ Q_UNUSED( args );
+
+ TestFactory t;
+ return t.runTests();
+}
diff --git a/libtdepim/komposer/core/tests/managertest.cpp b/libtdepim/komposer/core/tests/managertest.cpp
new file mode 100644
index 000000000..487a84c59
--- /dev/null
+++ b/libtdepim/komposer/core/tests/managertest.cpp
@@ -0,0 +1,43 @@
+/**
+ * managertest.cpp
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include "managertest.h"
+
+#include "pluginmanager.h"
+using namespace Komposer;
+
+ManagerTest::ManagerTest( TQObject* parent )
+ : TQObject( parent )
+{
+ m_manager = new PluginManager( this );
+}
+
+
+void ManagerTest::allTests()
+{
+ CHECK( m_manager->availablePlugins().isEmpty(), true );
+ CHECK( m_manager->loadedPlugins().empty(), true );
+ CHECK( m_manager->plugin( "non-existing" ), ( Plugin* )0 );
+ m_manager->loadAllPlugins();
+ CHECK( m_manager->loadedPlugins().empty(), true );
+ m_manager->shutdown();
+}
+
+#include "managertest.moc"
diff --git a/libtdepim/komposer/core/tests/managertest.h b/libtdepim/komposer/core/tests/managertest.h
new file mode 100644
index 000000000..f02510e67
--- /dev/null
+++ b/libtdepim/komposer/core/tests/managertest.h
@@ -0,0 +1,45 @@
+/*
+ * managertest.h
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef MANAGERTEST_H
+#define MANAGERTEST_H
+
+#include <tqobject.h>
+#include "tester.h"
+
+namespace Komposer {
+ class PluginManager;
+}
+
+class ManagerTest : public TQObject,
+ public Tester
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ ManagerTest( TQObject* parent = 0 );
+
+public slots:
+ void allTests();
+private:
+ Komposer::PluginManager* m_manager;
+};
+
+#endif
diff --git a/libtdepim/komposer/core/tests/tester.cpp b/libtdepim/komposer/core/tests/tester.cpp
new file mode 100644
index 000000000..b32c89644
--- /dev/null
+++ b/libtdepim/komposer/core/tests/tester.cpp
@@ -0,0 +1,30 @@
+/**
+ * tester.cpp
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include "tester.h"
+
+
+Tester::Tester( TQObject* parent )
+ : TQObject( parent )
+{
+}
+
+
+#include "tester.moc"
diff --git a/libtdepim/komposer/core/tests/tester.h b/libtdepim/komposer/core/tests/tester.h
new file mode 100644
index 000000000..5981d681d
--- /dev/null
+++ b/libtdepim/komposer/core/tests/tester.h
@@ -0,0 +1,71 @@
+/*
+ * tester.h
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef TESTER_H
+#define TESTER_H
+
+#include <kdebug.h>
+#include <tqstringlist.h>
+
+#define CHECK( x, y ) check( __FILE__, __LINE__, #x, x, y )
+
+class Tester
+{
+public:
+ Tester() : m_tests( 0 ) {}
+ virtual ~Tester() {}
+
+public:
+ virtual void allTests() = 0;
+
+public:
+ int testsFinished() const {
+ return m_tests;
+ }
+ int testsFailed() const {
+ return m_errorList.count();
+ }
+ TQStringList errorList() const {
+ return m_errorList;
+ }
+
+protected:
+ template<typename T>
+ void check( const char* file, int line, const char* str,
+ const T& result, const T& expectedResult )
+ {
+ if ( result != expectedResult ) {
+ TQString error;
+ TQTextStream ts( &error, IO_WriteOnly );
+ ts << file << "["<< line <<"]:"
+ <<" failed on \""<< str <<"\""
+ << "\ntests:\t\t result = "
+ << result
+ << ", expected = "<< expectedResult;
+ m_errorList.append( error );
+ }
+ ++m_tests;
+ }
+private:
+ TQStringList m_errorList;
+ int m_tests;
+};
+
+#endif
diff --git a/libtdepim/komposer/core/tests/testfactory.h b/libtdepim/komposer/core/tests/testfactory.h
new file mode 100644
index 000000000..9354e52ad
--- /dev/null
+++ b/libtdepim/komposer/core/tests/testfactory.h
@@ -0,0 +1,71 @@
+/*
+ * testfactory.h
+ *
+ * Copyright (C) 2004 Zack Rusin <zack@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef TESTFACTORY_H
+#define TESTFACTORY_H
+
+#include "managertest.h"
+
+#include <tqasciidict.h>
+
+#define ADD_TEST(x) addTest( #x, new x )
+
+class TestFactory
+{
+public:
+ TestFactory()
+ {
+ ADD_TEST( ManagerTest );
+ m_tests.setAutoDelete( true );
+ }
+
+ int runTests()
+ {
+ int result = 0;
+ kdDebug()<<"Running tests..."<<endl;
+ TQAsciiDictIterator<Tester> it( m_tests );
+ for( ; it.current(); ++it ) {
+ Tester* test = it.current();
+ test->allTests();
+ TQStringList errorList = test->errorList();
+ if ( !errorList.empty() ) {
+ ++result;
+ kdDebug()<< it.currentKey() <<" errors:" << endl;
+ for ( TQStringList::Iterator itr = errorList.begin();
+ itr != errorList.end(); ++itr ) {
+ kdDebug()<< "\t" << (*itr).latin1() <<endl;;
+ }
+ } else {
+ kdDebug()<< it.currentKey()<< " OK "<<endl;
+ }
+ }
+ kdDebug()<< "Done" <<endl;
+ return result;
+ }
+public:
+ void addTest( const char* name, Tester* test )
+ {
+ m_tests.insert( name, test );
+ }
+private:
+ TQAsciiDict<Tester> m_tests;
+};
+
+#endif
diff --git a/libtdepim/komposer/core/tests/testkomposer.cpp b/libtdepim/komposer/core/tests/testkomposer.cpp
new file mode 100644
index 000000000..b7997e8c3
--- /dev/null
+++ b/libtdepim/komposer/core/tests/testkomposer.cpp
@@ -0,0 +1,18 @@
+#include "core.h"
+
+#include <kplugininfo.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <kdebug.h>
+
+int main( int argc, char **argv )
+{
+ KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" );
+ KApplication app;
+
+ Komposer::Core *core = new Komposer::Core();
+ app.setMainWidget( core );
+ core->show();
+
+ return app.exec();
+}
diff --git a/libtdepim/komposer/core/tests/testmanager.cpp b/libtdepim/komposer/core/tests/testmanager.cpp
new file mode 100644
index 000000000..0fcba16b9
--- /dev/null
+++ b/libtdepim/komposer/core/tests/testmanager.cpp
@@ -0,0 +1,53 @@
+#include "testmanager.h"
+#include "testmanager.moc"
+
+#include "pluginmanager.h"
+#include "plugin.h"
+
+#include <kplugininfo.h>
+#include <kcmdlineargs.h>
+#include <kapplication.h>
+#include <kdebug.h>
+
+using namespace Komposer;
+
+TestManager::TestManager( TQObject *parent )
+ : TQObject( parent )
+{
+ m_manager = new PluginManager( this );
+ connect( m_manager, TQT_SIGNAL(pluginLoaded(Plugin*)),
+ TQT_SLOT(slotPluginLoaded(Plugin*)) );
+ connect( m_manager, TQT_SIGNAL(allPluginsLoaded()),
+ TQT_SLOT(slotAllPluginsLoaded()) );
+ m_manager->loadAllPlugins();
+
+ TQValueList<KPluginInfo*> plugins = m_manager->availablePlugins();
+ kdDebug()<<"Number of available plugins is "<< plugins.count() <<endl;
+ for ( TQValueList<KPluginInfo*>::iterator it = plugins.begin(); it != plugins.end(); ++it ) {
+ KPluginInfo *i = ( *it );
+ kdDebug()<<"\tAvailable plugin "<< i->name()
+ <<", comment = "<< i->comment() <<endl;
+ }
+}
+
+void TestManager::slotAllPluginsLoaded()
+{
+ kdDebug()<<"Done"<<endl;
+ m_manager->shutdown();
+ tqApp->exit();
+}
+
+void TestManager::slotPluginLoaded( Plugin *plugin )
+{
+ kdDebug()<<"A plugin "<< m_manager->pluginName( plugin ) << " has been loaded"<<endl;
+}
+
+int main( int argc, char **argv )
+{
+ KCmdLineArgs::init( argc, argv, "test", "test", "test", "0.1" );
+ KApplication app;
+
+ TestManager manager( &app );
+
+ return app.exec();
+}
diff --git a/libtdepim/komposer/core/tests/testmanager.h b/libtdepim/komposer/core/tests/testmanager.h
new file mode 100644
index 000000000..5dfaa15d1
--- /dev/null
+++ b/libtdepim/komposer/core/tests/testmanager.h
@@ -0,0 +1,26 @@
+#ifndef TESTMANAGER_H
+#define TESTMANAGER_H
+
+#include <tqobject.h>
+
+namespace Komposer {
+ class Plugin;
+ class PluginManager;
+}
+using Komposer::Plugin;
+
+class TestManager : public TQObject
+{
+ Q_OBJECT
+ TQ_OBJECT
+public:
+ TestManager( TQObject *parent );
+
+public slots:
+ void slotPluginLoaded( Plugin *plugin );
+ void slotAllPluginsLoaded();
+private:
+ Komposer::PluginManager *m_manager;
+};
+
+#endif