summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/macros/tests
diff options
context:
space:
mode:
Diffstat (limited to 'kexi/plugins/macros/tests')
-rw-r--r--kexi/plugins/macros/tests/Makefile.am28
-rw-r--r--kexi/plugins/macros/tests/actiontests.cpp211
-rw-r--r--kexi/plugins/macros/tests/actiontests.h89
-rw-r--r--kexi/plugins/macros/tests/commontests.cpp907
-rw-r--r--kexi/plugins/macros/tests/commontests.h118
-rw-r--r--kexi/plugins/macros/tests/komacrotest.cpp58
-rw-r--r--kexi/plugins/macros/tests/komacrotestbase.h90
-rw-r--r--kexi/plugins/macros/tests/komacrotestgui.cpp60
-rw-r--r--kexi/plugins/macros/tests/macroitemtests.cpp243
-rw-r--r--kexi/plugins/macros/tests/macroitemtests.h87
-rw-r--r--kexi/plugins/macros/tests/macrotests.cpp192
-rw-r--r--kexi/plugins/macros/tests/macrotests.h74
-rw-r--r--kexi/plugins/macros/tests/testaction.cpp61
-rw-r--r--kexi/plugins/macros/tests/testaction.h78
-rw-r--r--kexi/plugins/macros/tests/testobject.cpp117
-rw-r--r--kexi/plugins/macros/tests/testobject.h85
-rw-r--r--kexi/plugins/macros/tests/variabletests.cpp236
-rw-r--r--kexi/plugins/macros/tests/variabletests.h87
-rw-r--r--kexi/plugins/macros/tests/xmlhandlertests.cpp619
-rw-r--r--kexi/plugins/macros/tests/xmlhandlertests.h122
-rw-r--r--kexi/plugins/macros/tests/xmlhandlertests2.cpp1161
-rw-r--r--kexi/plugins/macros/tests/xmlhandlertests2.h132
22 files changed, 4855 insertions, 0 deletions
diff --git a/kexi/plugins/macros/tests/Makefile.am b/kexi/plugins/macros/tests/Makefile.am
new file mode 100644
index 00000000..36dbd76f
--- /dev/null
+++ b/kexi/plugins/macros/tests/Makefile.am
@@ -0,0 +1,28 @@
+if include_kunittestgui
+ GUIBINPROGRAM = komacrotestgui
+else
+ GUIBINPROGRAM =
+endif
+
+bin_PROGRAMS = komacrotest $(GUIBINPROGRAM)
+
+komacrotest_SOURCES = komacrotest.cpp testobject.cpp testaction.cpp actiontests.cpp macrotests.cpp macroitemtests.cpp variabletests.cpp xmlhandlertests.cpp xmlhandlertests2.cpp
+komacrotest_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+komacrotest_LDADD = -lkunittest ../lib/libkomacro.la $(LIB_KDEUI) $(LIB_KPARTS)
+
+if include_kunittestgui
+ komacrotestgui_SOURCES = komacrotestgui.cpp testobject.cpp testaction.cpp actiontests.cpp macrotests.cpp macroitemtests.cpp variabletests.cpp xmlhandlertests.cpp xmlhandlertests2.cpp
+ komacrotestgui_LDFLAGS = $(KDE_RPATH) $(all_libraries)
+ komacrotestgui_LDADD = -lkunittestgui ../lib/libkomacro.la $(LIB_KDEUI) $(LIB_KPARTS)
+endif
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+INCLUDES = -I$(srcdir)/tests -I$(srcdir)../ $(all_includes)
+METASOURCES = AUTO
+
+guicheck: komacrotestgui
+ kunittest ./komacrotestgui
+
+check: komacrotest
+ echo $(srcdir)
+ kunittest ./komacrotest
diff --git a/kexi/plugins/macros/tests/actiontests.cpp b/kexi/plugins/macros/tests/actiontests.cpp
new file mode 100644
index 00000000..0150ecfd
--- /dev/null
+++ b/kexi/plugins/macros/tests/actiontests.cpp
@@ -0,0 +1,211 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "actiontests.h"
+#include "testobject.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/function.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/metaobject.h"
+#include "../lib/metamethod.h"
+#include "../lib/metaparameter.h"
+#include "../lib/exception.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+
+#include <qstringlist.h>
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+
+ KUNITTEST_SUITE("KoMacroTestSuite");
+ KUNITTEST_REGISTER_TESTER(ActionTests);
+
+
+ class ActionTests::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ TestAction* testaction;
+
+ QDomDocument* doomdocument;
+
+ KSharedPtr<KoMacro::Macro> macro;
+
+ QValueList< KSharedPtr<KoMacro::MacroItem> > items;
+
+ KSharedPtr<KoMacro::Action> actionptr;
+
+ Private()
+ : xmlguiclient(0)
+ , testaction(0)
+ , doomdocument(0)
+ , macro(0)
+ , actionptr(0)
+ {
+ }
+ };
+}
+
+typedef QValueList< KSharedPtr<KoMacro::MacroItem> >::size_type sizetype;
+
+
+ActionTests::ActionTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+ActionTests::~ActionTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+
+void ActionTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+
+ d->doomdocument = new QDomDocument();
+
+ QString const xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\" >"
+ "<item action=\"testaction\" >"
+ "</item>"
+ "</macro>");
+
+ d->doomdocument->setContent(xml);
+ d->macro = KoMacro::Manager::self()->createMacro("testMacro");
+ d->macro->parseXML(d->doomdocument->documentElement());
+ d->macro->execute(this);
+ d->items = d->macro->items();
+ d->actionptr = d->items[0]->action();
+}
+
+void ActionTests::tearDown()
+{
+ delete d->actionptr;
+ delete d->macro;
+ delete d->doomdocument;
+ delete d->xmlguiclient;
+}
+
+
+void ActionTests::testMacro()
+{
+ kdDebug()<<"===================== testMacro() ======================" << endl;
+
+ //fetch Items and ..
+ //QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+
+ //... check that there is one
+ KOMACROTEST_XASSERT( d->items.count(), sizetype(0) );
+}
+
+void ActionTests::testAction()
+{
+ kdDebug()<<"===================== testAction() ======================" << endl;
+
+ //get it
+ //KSharedPtr<KoMacro::Action> actionptr = d->items[0]->action();
+ //-> check that it is not null
+ KOMACROTEST_XASSERT(sizetype(d->actionptr.data()), sizetype(0));
+}
+
+void ActionTests::testText()
+{
+ kdDebug()<<"===================== testText() ======================" << endl;
+
+ //KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ const QString leetSpeech = "']['3 $']['";
+
+ //check i18n text
+ KOMACROTEST_ASSERT(d->actionptr->text(),QString("Test"));
+ //change it
+ d->actionptr->setText(leetSpeech);
+ //retest it
+ KOMACROTEST_ASSERT(d->actionptr->text(),QString(leetSpeech));
+}
+
+
+void ActionTests::testName()
+{
+ kdDebug()<<"===================== testName() ======================" << endl;
+
+ //KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //check name
+ KOMACROTEST_ASSERT(d->actionptr->name(),QString("testaction"));
+ //change it
+ d->actionptr->setName("ActionJackson");
+ //retest it
+ KOMACROTEST_ASSERT(d->actionptr->name(),QString("ActionJackson"));
+}
+
+void ActionTests::testComment()
+{
+ kdDebug()<<"===================== testComment() ======================" << endl;
+
+ //KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //check comment
+ KOMACROTEST_XASSERT(d->actionptr->comment(),QString("No Comment!"));
+ //set comment
+ d->actionptr->setComment("Stringtest");
+ //check comment again
+ KOMACROTEST_ASSERT(d->actionptr->comment(),QString("Stringtest"));
+}
+
+#include "actiontests.moc"
diff --git a/kexi/plugins/macros/tests/actiontests.h b/kexi/plugins/macros/tests/actiontests.h
new file mode 100644
index 00000000..48b5a252
--- /dev/null
+++ b/kexi/plugins/macros/tests/actiontests.h
@@ -0,0 +1,89 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_ACTIONTESTS_H
+#define KOMACROTEST_ACTIONTESTS_H
+
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class ActionTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ ActionTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~ActionTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacro();
+
+ /**
+ * Test the @a KoMacro::Action functionality.
+ */
+ void testAction();
+
+ void testText();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testName();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testComment();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/commontests.cpp b/kexi/plugins/macros/tests/commontests.cpp
new file mode 100644
index 00000000..84c596aa
--- /dev/null
+++ b/kexi/plugins/macros/tests/commontests.cpp
@@ -0,0 +1,907 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "commontests.h"
+#include "testobject.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/function.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/metaobject.h"
+#include "../lib/metamethod.h"
+#include "../lib/metaparameter.h"
+#include "../lib/exception.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+#include <climits>
+
+#include <qstringlist.h>
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+ KUNITTEST_SUITE("CommonTestsSuite")
+ KUNITTEST_REGISTER_TESTER(CommonTests);
+
+ /**
+ * @internal d-pointer class to be more flexible on future extension of the
+ * functionality without to much risk to break the binary compatibility.
+ */
+ class CommonTests::Private
+ {
+ public:
+
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ TestObject* testobject;
+
+ TestAction* testaction;
+
+ QDomDocument* doomdocument;
+
+ /**
+ * Constructor.
+ */
+ Private()
+ : xmlguiclient(0)
+ , testobject(0)
+ , testaction(0)
+ , doomdocument(0)
+ {
+ }
+ };
+
+}
+
+typedef QValueList< KSharedPtr<KoMacro::MacroItem> >::size_type sizetype;
+
+CommonTests::CommonTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+CommonTests::~CommonTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+void CommonTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+ ::KoMacro::Manager::init( d->xmlguiclient );
+
+ d->testobject = new TestObject( this );
+ ::KoMacro::Manager::self()->publishObject("TestObject", d->testobject);
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+
+ d->doomdocument = new QDomDocument();
+
+ QString const xml = QString("<!DOCTYPE macros>"
+
+ "<macro xmlversion=\"1\">"
+
+ "<item action=\"testaction\" >"
+ "</item>"
+ "</macro>");
+
+ d->doomdocument->setContent(xml);
+}
+
+void CommonTests::tearDown()
+{
+ delete d->doomdocument;
+ delete d->testobject;
+ delete d->xmlguiclient;
+}
+
+void CommonTests::testManager()
+{
+ kdDebug()<<"===================== testManager() ======================" << endl;
+
+ //check if manager-guiClient equals xmlguiclient
+ KOMACROTEST_ASSERT( ::KoMacro::Manager::self()->guiClient(), d->xmlguiclient );
+ //check if manger-object equals testobject
+ KOMACROTEST_ASSERT( dynamic_cast<TestObject*>( (QObject*)::KoMacro::Manager::self()->object("TestObject") ), d->testobject );
+}
+/*
+void CommonTests::testAction()
+{
+ const QString testString = "teststring";
+ const QString testInt = "testint";
+ const QString testBool = "testbool";
+
+ //TODO: CLEANUP!!!!!!
+ //TODO: test manipulation of action and macroitem and context.
+
+ kdDebug()<<"===================== testAction() ======================" << endl;
+
+ //Publish TestAction for the first time.
+
+ QDomElement const domelement = d->doomdocument->documentElement();
+
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+
+ //Is our XML parseable ?
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
+
+ //??
+ macro->execute(this);
+
+ //create list of KSharedPtr from the childs of the macro
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = macro->items();
+
+
+ //check that there is one
+ KOMACROTEST_ASSERT( items.count(), sizetype(1) );
+ //fetch the first one
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+ //How do we know that an action exist ?
+ //-> check that it is not null
+ KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
+ //fetch the "teststring"-variable
+ KSharedPtr<KoMacro::Variable> variableptr = actionptr->variable("teststring");
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("testString"));
+
+ //fetch the "testint"-variable
+ variableptr = actionptr->variable("testint");
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toInt(),int(0));
+
+ //fetch the "testbool"-variable
+ variableptr = actionptr->variable("testbool");
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),true);
+
+ actionptr->setVariable("teststring", "STRINGTEST", "TestString");
+ variableptr = actionptr->variable("teststring");
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("TestString"));
+
+ actionptr->setVariable("testint","INTTEST",INT_MAX);
+ variableptr = actionptr->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
+
+ actionptr->setVariable("testbool","BOOLTEST", "false");
+ variableptr = actionptr->variable("testbool");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
+
+ //create new macroitem for testing
+ KoMacro::MacroItem* macroitem = new KoMacro::MacroItem();
+ //set the action
+ macroitem->setAction(d->testaction);
+ //append the macroitem to testitems
+ items.append(macroitem);
+ //increased ??
+ KOMACROTEST_ASSERT( items.count(), sizetype(2) );
+
+ //Manipulate the macroitem
+ macroitem->setVariable("teststring", "TeStString");
+ variableptr = macroitem->variable("teststring");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("TeStString"));
+
+ macroitem->setVariable("testint",INT_MIN);
+ variableptr = macroitem->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MIN));
+
+ macroitem->setVariable("testint",-1);
+ variableptr = macroitem->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(-1));
+
+
+ //commontests.cpp: In member function 'void KoMacroTest::CommonTests::testAction()':
+ //commontests.cpp:249: error: call of overloaded 'setVariable(const char [8], int)' is ambiguous
+ //../lib/macroitem.h:131: note: candidates are: QStringList KoMacro::MacroItem::setVariable(const QString&, KSharedPtr<KoMacro::Variable>)
+ //../lib/macroitem.h:137: note: QStringList KoMacro::MacroItem::setVariable(const QString&, const QVariant&)
+
+ macroitem->setVariable("testint",(int) 0);
+ variableptr = macroitem->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(0));
+
+
+ macroitem->setVariable("testint",1);
+ variableptr = macroitem->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(1));
+
+ macroitem->setVariable("testint",INT_MAX);
+ variableptr = macroitem->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
+
+ macroitem->setVariable("testbool","false");
+ variableptr = macroitem->variable("testbool");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
+
+ //secondway for appending an macroitem
+ //add the manipulated macroitem
+ macro->addItem(macroitem);
+ //increased ??
+ KOMACROTEST_ASSERT( items.count(), sizetype(3));
+} */
+
+void CommonTests::testXmlhandler()
+{
+ kdDebug()<<"===================== testXmlhandler() ======================" << endl;
+
+ // Local Init
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomElement domelement;
+
+ // Save old doomdocument
+ QString xmlOld = d->doomdocument->toString();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testbla\" >somethingwrong</variable>" // TODO Is here a kdDebug-msg enough?
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ //Is our XML parseable ?
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
+
+ // Test-XML-document with bad root element.
+ xml = QString("<!DOCTYPE macros>"
+ "<maro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</maro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),false);
+
+ // Test-XML-document with wrong macro-xmlversion.
+ xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"2\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),false);
+
+ // TODO Test-XML-document if it has a wrong structure like wrong parathesis
+ // or missing end tag (is this critical??).
+ /*xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "</item>"
+ "</macro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),false);*/
+
+ // Test-XML-document with wrong item- and variable-tags.
+ // TODO Could this happen??
+ xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<iem action=\"testaction\" >"
+ "<vle name=\"teststring\" >testString</variable>"
+ "<v name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true); //should be false?
+
+ // TODO Test-XML-document with maximum field-size.
+ xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" > 0 </variable>" // the value should be INT_MAX
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>" // DBL_MAX
+ "</item>"
+ "</macro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
+
+ // TODO Test-XML-document with minimum field-size.
+ xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString</variable>"
+ "<variable name=\"testint\" >0</variable>" // INT_MIN
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>" // DBL_MIN
+ "</item>"
+ "</macro>");
+ d->doomdocument->setContent(xml);
+ domelement = d->doomdocument->documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
+
+ // TODO Part 2: Read the parsen macro and make a comparison to the XML-document.
+
+ // TODO Part 3: From a Macro to XML.
+
+ // RODO Part 4: Compare the transformed XML with the given macro.
+
+ // Set back xml-string for other tests.
+ d->doomdocument->setContent(xmlOld);
+}
+
+void CommonTests::testFunction()
+{
+//TODO: CLEANUP!!!!!!
+/*
+ kdDebug()<<"===================== testFunction() ======================" << endl;
+
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+ //create some data
+ QString const comment = "Describe what the function does";
+ QString const name = "myfunc";
+ QString const text = "My Function";
+ QString const receiver = "TestObject";
+ QString const argument1 = "Some string";
+ int const argument2 = 12345;
+
+ //set "Function"-content in QDocument
+ domdocument.setContent(QString(
+ "<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver + "\" slot=\"myslot(const QString &amp; , int)\">"
+ "<argument>" + argument1 + "</argument>"
+ "<argument>" + QString("%1").arg(argument2) + "</argument>"
+ "</function>"
+ ));
+
+ //create an KomacroFunction with our data, and put it into a KSharedPtr
+ KSharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //cast KSharedPtr to KoMacro-"Function"
+ KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
+ //check that function is not null
+ KOMACROTEST_XASSERT((int) func, 0);
+
+ //check domElement
+ KOMACROTEST_ASSERT( func->domElement(), domdocument.documentElement() );
+ //check name
+ KOMACROTEST_ASSERT( QString(func->name()), name );
+ //check text
+ KOMACROTEST_ASSERT( func->text(), text );
+ //check comment
+ KOMACROTEST_ASSERT( func->comment(), comment );
+ //check receiver
+ KOMACROTEST_ASSERT( func->receiver(), receiver );
+ //check slot (arguments)
+ KOMACROTEST_ASSERT( QString(func->slot()), QString("myslot(const QString&,int)") );
+
+ //create KoMacro-MetaObject from receiverObject
+ KSharedPtr<KoMacro::MetaObject> receivermetaobject = func->receiverObject();
+ //check that receivermetaobject.data is not null
+ KOMACROTEST_XASSERT((int) receivermetaobject.data(), 0);
+
+ //create KoMacro-MetaMethod from receiverObject
+ KSharedPtr<KoMacro::MetaMethod> receivermetamethod = receivermetaobject->slot( func->slot().latin1() );
+ //check that receivermetamethod.data is not null
+ KOMACROTEST_XASSERT((int) receivermetamethod.data(), 0);
+
+ //create list of variables from func
+ KoMacro::Variable::List funcvariables = func->variables();
+ //counter for hardcoded tests see below ...
+ uint i = 0;
+ KoMacro::Variable::List::ConstIterator it, end( funcvariables.constEnd() );
+ for( it = funcvariables.constBegin(); it != end; ++it) {
+ kdDebug() << "VARIABLE => " << (*it ? (*it)->toString() : "<NULL>") << endl;
+ //hardcoded test:
+ // firstrun we have a QString, secondrun we have an int
+ switch(i) {
+ case 0: { // returnvalue
+ KOMACROTEST_ASSERT(*it, KSharedPtr<KoMacro::Variable>(NULL));
+ } break;
+ case 1: { // first parameter
+ //check first variable of func is the same as argument1
+ //QString const argument1 = "Some string";
+ KOMACROTEST_ASSERT((*it)->toString(), argument1);
+ } break;
+ case 2: { // second parameter
+ //check second variable of func is the same as argument2
+ //int const argument2 = 12345;
+ KOMACROTEST_ASSERT((*it)->toInt(), argument2);
+ } break;
+ default: {
+ } break;
+ }
+ i++;
+ }
+
+ //check that we have two arguments + one returnvalue in func
+ KOMACROTEST_ASSERT( funcvariables.count(), uint(3) );
+
+ // check that the first argument (the returnvalue) is empty
+ KOMACROTEST_ASSERT( funcvariables[0], KSharedPtr<KoMacro::Variable>(NULL) );
+
+ //create a KoMacro-Variable-Ptr from first func argument
+ KSharedPtr<KoMacro::Variable> stringvar = funcvariables[1];
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) stringvar.data(),0);
+ //check via QVariant type that stringvar is from Type Variant
+ KOMACROTEST_ASSERT( stringvar->type(), KoMacro::MetaParameter::TypeVariant );
+ //check via metaparameter that variant is from type string
+ KOMACROTEST_ASSERT( stringvar->variantType(), QVariant::String );
+ //chech that stringvar equals argument1
+ KOMACROTEST_ASSERT( stringvar->toString(), argument1 );
+
+ //create a KoMacro-Variable-Ptr from second func argument
+ KSharedPtr<KoMacro::Variable> intvar = funcvariables[2];
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) intvar.data(), 0);
+ //check via QVariant type that stringvar is from Type Variant
+ KOMACROTEST_ASSERT( intvar->type(), KoMacro::MetaParameter::TypeVariant );
+ //check that intvar is An String -> we create an string from int because of xml
+ KOMACROTEST_ASSERT( intvar->variantType(), QVariant::String );
+ //check that intvar equals argument2
+ KOMACROTEST_ASSERT( intvar->toInt(), argument2 );
+
+ //returnvalue see testobject ....
+ KSharedPtr<KoMacro::Variable> funcreturnvalue = receivermetamethod->invoke( funcvariables );
+ kdDebug() << "CommonTests::testFunction() RETURNVALUE =====> " << funcreturnvalue->toString() << endl;
+ KOMACROTEST_ASSERT( funcreturnvalue->toInt(), argument2 );
+
+ //check returnvalue
+ //func->setReturnValue(new KoMacro::Variable("54321"));
+ //KOMACROTEST_ASSERT( func->returnValue()->toString(), QString("54321") );
+*/
+}
+
+void CommonTests::testIntFunction()
+{
+//TODO: CLEANUP!!!!!!
+/*
+ kdDebug()<<"===================== testIntFunction() ======================" << endl;
+
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+
+ //set "Function"-content in QDocument
+ domdocument.setContent(QString(
+ "<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const QString &amp; , int)\">"
+ "<argument>Some string</argument>"
+ "<argument>12345</argument>"
+ "</function>"
+ ));
+
+ //create an KomacroFunction with our data, and put it into a KSharedPtr
+ KSharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //Cast data to function
+ KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) func, 0);
+ //execute the function
+ func->activate();
+ //Check returnvalue is same value we entered
+ //KOMACROTEST_ASSERT(func->returnValue()->toString(),QString("12345"));
+*/
+}
+
+void CommonTests::testDoubleFunction()
+{
+//TODO: CLEANUP!!!!!!
+/*
+ kdDebug()<<"===================== testDoubleFunction() ======================" << endl;
+
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+
+ //set "Function"-content in QDocument
+ domdocument.setContent(QString(
+ "<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const QString &amp; , double)\">"
+ "<argument>Some string</argument>"
+ "<argument>12.56</argument>"
+ "</function>"
+ ));
+
+ //create an KomacroFunction with our data, and put it into a KSharedPtr
+ KSharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //Cast data to function
+ KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) func, 0);
+ //execute the function
+ func->activate();
+ //Check returnvalue is same value we entered
+ //KOMACROTEST_ASSERT(func->returnValue()->toString(),QString("12.56"));
+*/
+}
+
+void CommonTests::testQStringFunction()
+{
+//TODO: CLEANUP!!!!!!
+/*
+ kdDebug()<<"===================== testQStringFunction() ======================" << endl;
+
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+
+ //set "Function"-content in QDocument
+ domdocument.setContent(QString(
+ "<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const QString &amp;)\">"
+ "<argument>Some string</argument>"
+ "</function>"
+ ));
+
+ //create an KomacroFunction with our data, and put it into a KSharedPtr
+ KSharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //Cast data to function
+ KoMacro::Function* func = dynamic_cast<KoMacro::Function*>( functionptr.data() );
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) func, 0);
+ //execute the function func->activate();
+ //Check returnvalue is same value we entered
+ //KOMACROTEST_ASSERT(func->returnValue()->toString(),QString("Some string"));
+*/
+}
+
+void CommonTests::testMacro()
+{
+//TODO: CLEANUP!!!!!!
+ kdDebug()<<"===================== testMacro() ======================" << endl;
+
+ QDomElement const domelement = d->doomdocument->documentElement();
+
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ //Is our XML parseable ?
+ KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
+
+// //create a QDomDocument
+// QDomDocument domdocument = QDomDocument();
+//
+// //Fully fleged content this time with macro,function and action
+// domdocument.setContent(QString(
+// "<macro name=\"mymacro\" icon=\"myicon\" text=\"My Macro\" comment=\"Some comment to describe the Macro.\">"
+// "<action name=\"myaction\" text=\"My Action\" comment=\"Just some comment\" />"
+// "<function name=\"myfunc\" text=\"My Function\" comment=\"Describe what the function does\" receiver=\"TestObject\" slot=\"myslot(const QString &amp;)\">"
+// "<argument>The myfunc argument string</argument>"
+// "</function>"
+// "</macro>"
+// ));
+//
+// //create Macro
+// // KSharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+// //cast data to Macro
+// KoMacro::Macro* macro = dynamic_cast<KoMacro::Macro*>( macroptr.data() );
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(macro.data()), sizetype(0));
+ //check that domeElement given to manager is the sam as in the macro
+// KOMACROTEST_ASSERT( macro->toXML(), d->doomdocument->documentElement() );
+ //check the name
+ KOMACROTEST_ASSERT( QString(macro->name()), QString("testMacro") );
+
+ /**
+ @deprecated values no longer exist
+
+ //check the text
+ KOMACROTEST_ASSERT( macro->text(), QString("My Macro") );
+ //check iconname
+ KOMACROTEST_ASSERT( QString(macro->icon()), QString("myicon") );
+ //check comment
+ KOMACROTEST_ASSERT( macro->comment(), QString("Some comment to describe the Macro.") );
+ */
+
+ //create list of KsharedPtr from the childs of the macro
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = macro->items();
+ //check that there is one
+ KOMACROTEST_ASSERT( items.count(), sizetype(1) );
+ //fetch the first one
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+ //How do we know that an action exist ?
+ //-> check that it is not null
+ KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
+ //check that it has the right name
+ KOMACROTEST_ASSERT( QString(actionptr->name()), QString("testaction") );
+ //check that it has the right text
+ KOMACROTEST_ASSERT( actionptr->text(), QString("Test") );
+ //check that it has the right comment
+// KOMACROTEST_ASSERT( actionptr->comment(), QString("") );
+/*
+ //fetch the second one
+ KSharedPtr<KoMacro::Action> myfuncptr = children[1];
+ //cast it to function
+
+ KoMacro::Function* myfunc = dynamic_cast<KoMacro::Function*>( myfuncptr.data() );
+ //check that it isn?t null
+ KOMACROTEST_XASSERT((int) myfunc, 0);
+
+ //check it?s name
+ KOMACROTEST_ASSERT( QString(myfunc->name()), QString("myfunc"));
+
+ //check it?s text
+ KOMACROTEST_ASSERT( myfunc->text(), QString("My Function") );
+ //check it?s comment
+ KOMACROTEST_ASSERT( myfunc->comment(), QString("Describe what the function does") );
+ //check it?s receiver object
+ KOMACROTEST_ASSERT( myfunc->receiver(), QString("TestObject") );
+ //check it?s slot
+ KOMACROTEST_ASSERT( myfunc->slot(), QString("myslot(const QString&)") );
+
+ //exceute it
+ myfunc->activate();
+*/
+ //create another macro
+ KSharedPtr<KoMacro::Macro> yanMacro = KoMacro::Manager::self()->createMacro("testMacro2");
+
+ KOMACROTEST_ASSERT(yanMacro->parseXML(domelement),true);
+ //create two more macros
+ //KSharedPtr<KoMacro::Action> yanActionptr2 = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //KSharedPtr<KoMacro::Action> yanActionptr3 = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+
+ //check that they aren?t null
+ KOMACROTEST_XASSERT(sizetype(yanMacro.data()), sizetype(0));
+ //KOMACROTEST_XASSERT((int) yanActionptr2.data(), 0);
+ //KOMACROTEST_XASSERT((int) yanActionptr3.data(), 0);
+
+ //create a list of the children from yanMacro
+ //QValueList< KSharedPtr<KoMacro::Action> > yanChildren = yanMacro->children();
+ //check that there are two
+ //KOMACROTEST_ASSERT(yanChildren.count(), uint(2));
+/*
+ {
+ //keep oldsize
+ const int oldsize = yanChildren.count();
+ //add a new child to the macro
+ yanMacro->addChild(yanActionptr2);
+ //get the children
+ yanChildren = yanMacro->children();
+ //get count of children
+ const int size = yanChildren.count();
+ //check count has changed
+ KOMACROTEST_XASSERT(size, oldsize);
+ }
+
+ {
+ //keep oldsize
+ const int oldsize = yanChildren.count();
+ //add a new child to the macro
+ yanMacro->addChild(yanActionptr3);
+ //get the children
+ yanChildren = yanMacro->children();
+ //get count of children
+ const int size = yanChildren.count();
+ //check count has changed
+ KOMACROTEST_XASSERT(size, oldsize);
+ //check the hasChildren function
+ KOMACROTEST_ASSERT(yanMacro->hasChildren(), true);
+ }
+*/
+
+}
+
+void CommonTests::testDom() {
+//TODO: CLEANUP!!!!!!
+ kdDebug()<<"===================== testDom() ======================" << endl;
+/*
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+ //create data for various documents
+ QString const comment = "Describe what the function does";
+ QString const name = "myfunc";
+ QString const text = "My Function";
+ QString const receiver1 = "TestObject";
+ QString const receiver2 = "GibtsNich";
+
+ //create wrong Argument tag
+ domdocument.setContent(QString(
+ "<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const QString &amp; , int)\">"
+ "<Arg0ment>Some string</Arg0ment>"
+ "<Arg0ment>12345</Arg0ment>"
+ "</function>"
+ ));
+ //create functiom
+ KSharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //try to execute function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
+
+ //create wrong receiver
+ domdocument.setContent(QString(
+ "<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver2 + "\" slot=\"myslot(const QString &amp; , int)\">"
+ "<argument>Some string</argument>"
+ "<argument>12345</argument>"
+ "</function>"
+ ));
+ //create function
+ macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //try to execute function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
+
+ //create "wrong" number of parameters
+ domdocument.setContent(QString(
+ "<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const QString &amp; , int, double)\">"
+ "<argument>Some string</argument>"
+ "<argument>12345</argument>"
+ "<argument>12345.25</argument>"
+ "</function>"
+ ));
+ //create function
+ macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //try to execute function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
+
+ //create wrong function tag
+ domdocument.setContent(QString(
+ "<NoFunction name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const QString &amp; , int, double)\">"
+ "<argument>Some string</argument>"
+ "<argument>12345</argument>"
+ "<argument>12345.25</argument>"
+ "</NoFunction>"
+ ));
+ //try to create function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() ));
+
+ //create empty function
+ domdocument.setContent(QString(
+ "<function name=\"\" text=\"\" comment=\"\" receiver=\"\" slot=\"\">"
+ "<argument> </argument>"
+ "<argument> </argument>"
+ "<argument> </argument>"
+ "</function>"
+ ));
+ //create function
+ macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //try to execute function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
+
+
+ //create empty function
+ domdocument.setContent(QString(
+ "<function>"
+ "</function>"
+ ));
+ //create function
+ macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //try to execute function and catch exception
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, macroptr->activate());
+*/
+}
+
+void CommonTests::testVariables()
+{
+//TODO: CLEANUP!!!!!!
+ kdDebug()<<"===================== testVariables() ======================" << endl;
+/*
+ //create a QDomDocument
+ QDomDocument domdocument = QDomDocument();
+ //create data
+ domdocument.setContent(QString(
+ "<macro name=\"mymacro123\" text=\"My Macro 123\">"
+ "<function name=\"func1\" text=\"Function1\" receiver=\"TestObject\" slot=\"myslot(const QString &amp;)\" >"
+ "<argument>$MyArgumentVariable</argument>"
+ "<return>$MyReturnVariable</return>"
+ "</function>"
+ "</macro>"
+ ));
+
+ //create an macro
+ KSharedPtr<KoMacro::Action> macroptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
+ //cast data to macro
+ KoMacro::Macro* macro = dynamic_cast<KoMacro::Macro*>( macroptr.data() );
+ //check that it is not null
+ KOMACROTEST_XASSERT((int) macro, 0);
+
+ //create a list of its children
+ QValueList< KSharedPtr<KoMacro::Action> > children = macro->children();
+ //Check that there are two children. The first child is always the returnvalue.
+ KOMACROTEST_ASSERT( children.count(), uint(2) );
+ //fetch the children
+ KSharedPtr<KoMacro::Action> func1ptr = children[1];
+
+ //create new context
+ KSharedPtr<KoMacro::Context> context = new KoMacro::Context(macroptr);
+
+ {
+ //try to execute function with non-functional variable
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, func1ptr->activate(context));
+
+ KOMACROTEST_ASSERTEXCEPTION(KoMacro::Exception&, context->variable("$MyReturnVariable333"));
+ }
+
+ {
+ //set variable to be a QString
+ context->setVariable("$MyArgumentVariable", new KoMacro::Variable("Some string"));
+ //execute function
+ func1ptr->activate(context);
+ //fetch return value
+ KSharedPtr<KoMacro::Variable> returnvariable = context->variable("$MyReturnVariable");
+ //check that it is not null
+ KOMACROTEST_XASSERT( (int) returnvariable.data(), 0);
+ //check that it is "Some String"
+ KOMACROTEST_ASSERT(returnvariable->toString(),QString("Some string"));
+ }
+
+ {
+ //set variable to be an Int
+ context->setVariable("$MyArgumentVariable", new KoMacro::Variable( 12345 ));
+ //execute function
+ func1ptr->activate(context);
+ //fetch return value
+ KSharedPtr<KoMacro::Variable> returnvariable = context->variable("$MyReturnVariable");
+ //check that it is not null
+ KOMACROTEST_XASSERT( (int) returnvariable.data(), 0);
+ //check that it is 12345
+ KOMACROTEST_ASSERT(returnvariable->toInt(),12345);
+ }
+*/
+}
+
+#include "commontests.moc"
diff --git a/kexi/plugins/macros/tests/commontests.h b/kexi/plugins/macros/tests/commontests.h
new file mode 100644
index 00000000..a3199ce2
--- /dev/null
+++ b/kexi/plugins/macros/tests/commontests.h
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_COMMONTESTS_H
+#define KOMACROTEST_COMMONTESTS_H
+
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class CommonTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ CommonTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~CommonTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Test the @a KoMacro::Manager functionality.
+ */
+ void testManager();
+
+ /**
+ * Test the @a KoMacro::Action functionality.
+ */
+ //void testAction();
+
+ /**
+ * Test the @a KoMacro::XmlHandler functionality.
+ */
+ void testXmlhandler();
+
+ /**
+ * Test the @a KoMacro::Function functionality.
+ */
+ void testFunction();
+
+ /**
+ * Test the @a KoMacro::Function functionality with an int.
+ */
+ void testIntFunction();
+
+ /**
+ * Test the @a KoMacro::Function functionality with a double.
+ */
+ void testDoubleFunction();
+
+ /**
+ * Test the @a KoMacro::Function functionality with a QString.
+ */
+ void testQStringFunction();
+
+ /**
+ * Test the @a KoMacro::Macro functionality.
+ */
+ void testMacro();
+
+ /**
+ * Test the @a KoMacro::Dom functionality.
+ */
+ void testDom();
+ /**
+ * Test the @a KoMacro::Variable functionality.
+ */
+ void testVariables();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/komacrotest.cpp b/kexi/plugins/macros/tests/komacrotest.cpp
new file mode 100644
index 00000000..55d017a9
--- /dev/null
+++ b/kexi/plugins/macros/tests/komacrotest.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#include <kunittest/runner.h>
+
+static const char description[] =
+ I18N_NOOP("KoMacroTester");
+static const char version[] = "0.1";
+static KCmdLineOptions options[] =
+{
+ KCmdLineLastOption
+};
+
+int main( int argc, char** argv )
+{
+ try {
+ KAboutData about("KoMacroTester",
+ I18N_NOOP("KoMacroTester"),
+ version,
+ description,
+ KAboutData::License_LGPL,
+ "(C) 2005 Sebastian Sauer", 0, 0, "mail@dipe.org");
+
+ KCmdLineArgs::init(argc, argv, &about);
+ KCmdLineArgs::addCmdLineOptions( options );
+ KApplication app;
+
+ //create an new "Console"-runner
+ KUnitTest::Runner * runner = KUnitTest::Runner::self();
+ //start our Testsuite
+ runner->runTests();
+ //done
+ return 0;
+ }
+ // mmh seems we forgot to catch an exception...
+ catch(...) {
+ qFatal("Unhandled Exception!");
+ }
+}
diff --git a/kexi/plugins/macros/tests/komacrotestbase.h b/kexi/plugins/macros/tests/komacrotestbase.h
new file mode 100644
index 00000000..d423e086
--- /dev/null
+++ b/kexi/plugins/macros/tests/komacrotestbase.h
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+#ifndef KOMACROTEST_BASE_H
+#define KOMACROTEST_BASE_H
+
+//Our own extended Macros from KUnittest
+/**
+* Macro to perform an equality check and exits the method if the check failed.
+*
+* @param actual The actual value.
+* @param expected The expected value.
+*/
+#define KOMACROTEST_ASSERT(actual, expected) \
+ { \
+ std::cout << QString("Testing: %1 == %2").arg(#actual).arg(#expected).latin1() << std::endl; \
+ check( __FILE__, __LINE__, #actual, actual, expected, false ); \
+ if(actual != expected) \
+ { \
+ kdWarning() << QString("==============> FAILED") << endl; \
+ return; \
+ } \
+ }
+
+/**
+* Macro to perform a check that is expected to fail and that exits the method if the check failed.
+*
+* @param actual The actual value.
+* @param notexpected The not expected value.
+*/
+#define KOMACROTEST_XASSERT(actual, notexpected) \
+ { \
+ std::cout << QString("Testing: %1 != %2").arg(#actual).arg(#notexpected).latin1() << std::endl; \
+ check( __FILE__, __LINE__, #actual, actual, notexpected, true ); \
+ if(actual == notexpected) \
+ { \
+ kdWarning() << QString("==============> FAILED") << endl; \
+ return; \
+ } \
+ }
+
+/**
+* Macro to test that @p expression throws an exception that is catched with the
+* @p exceptionCatch exception.
+*
+* @param exceptionCatch The exception that is expected to be thrown.
+* @param expression The expression that is executed within a try-catch block to
+* check for the @p exceptionCatch .
+*/
+#define KOMACROTEST_ASSERTEXCEPTION(exceptionCatch, expression) \
+ { \
+ try { \
+ expression; \
+ } \
+ catch(exceptionCatch) { \
+ setExceptionRaised(true); \
+ } \
+ if(exceptionRaised()) { \
+ success(QString(__FILE__) + "[" + QString::number(__LINE__) + "]: passed " + #expression); \
+ setExceptionRaised(false); \
+ } \
+ else { \
+ failure(QString(__FILE__) + "[" + QString::number(__LINE__) + QString("]: failed to throw an exception on: ") + #expression); \
+ return; \
+ } \
+ }
+
+#endif
+
+//Used more tha once at various places
+//names of variables from testaction
+namespace KoMacroTest {
+ static const QString TESTSTRING = "teststring";
+ static const QString TESTINT = "testint";
+ static const QString TESTBOOL = "testbool";
+}
diff --git a/kexi/plugins/macros/tests/komacrotestgui.cpp b/kexi/plugins/macros/tests/komacrotestgui.cpp
new file mode 100644
index 00000000..abf4459d
--- /dev/null
+++ b/kexi/plugins/macros/tests/komacrotestgui.cpp
@@ -0,0 +1,60 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+
+#include "kunittest/runnergui.h"
+
+static const char description[] =
+ I18N_NOOP("KoMacroTestgui.");
+
+static const char version[] = "0.1";
+
+static const KCmdLineOptions options[] =
+{
+ KCmdLineLastOption
+};
+
+int main( int argc, char** argv )
+{
+ try {
+ KAboutData const about("KomacroTests", I18N_NOOP("KomacroTests"), version, description,
+ KAboutData::License_LGPL, "(C) 2005 Tobi Krebs", 0, 0,
+ "Tobi.Krebs@gmail.com");
+
+ KCmdLineArgs::init(argc, argv, &about);
+ KCmdLineArgs::addCmdLineOptions( options );
+ //create new kapplication
+ KApplication app;
+ //create new kunitrunnergui
+ KUnitTest::RunnerGUI runner(0);
+ //show the ui
+ runner.show();
+ //set ui mainwidget
+ app.setMainWidget(&runner);
+ //return exitcode of ui
+ return app.exec();
+ }
+ // mmh seems we forgot to catch an exception...
+ catch(...) {
+ qFatal("Unhandled Exception!");
+ }
+}
diff --git a/kexi/plugins/macros/tests/macroitemtests.cpp b/kexi/plugins/macros/tests/macroitemtests.cpp
new file mode 100644
index 00000000..366318e1
--- /dev/null
+++ b/kexi/plugins/macros/tests/macroitemtests.cpp
@@ -0,0 +1,243 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "macroitemtests.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/metaobject.h"
+#include "../lib/metamethod.h"
+#include "../lib/metaparameter.h"
+#include "../lib/exception.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+
+#include <qstringlist.h>
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+
+ KUNITTEST_SUITE("KoMacroTestSuite");
+ KUNITTEST_REGISTER_TESTER(MacroitemTests);
+
+
+ class MacroitemTests::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ TestAction* testaction;
+
+ QDomDocument* doomdocument;
+
+ KSharedPtr<KoMacro::Macro> macro;
+
+ Private()
+ : xmlguiclient(0)
+ , testaction(0)
+ , doomdocument(0)
+ , macro(0)
+ {
+ }
+ };
+}
+
+typedef QValueList< KSharedPtr<KoMacro::MacroItem> >::size_type sizetype;
+
+MacroitemTests::MacroitemTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+MacroitemTests::~MacroitemTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+void MacroitemTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+
+ d->doomdocument = new QDomDocument();
+
+ QString const xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\" >"
+ "<item action=\"testaction\" >"
+ "</item>"
+ "</macro>");
+
+ d->doomdocument->setContent(xml);
+ d->macro = KoMacro::Manager::self()->createMacro("testMacro");
+ d->macro->parseXML(d->doomdocument->documentElement());
+ d->macro->execute(this);
+}
+
+void MacroitemTests::tearDown()
+{
+ delete d->macro;
+ delete d->doomdocument;
+ delete d->xmlguiclient;
+}
+
+
+void MacroitemTests::testMacro()
+{
+ kdDebug()<<"===================== testMacroitem() ======================" << endl;
+ kdDebug()<<"===================== testMacro() ======================" << endl;
+
+ //fetch Items and ..
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+
+ //... check that there is one
+ KOMACROTEST_XASSERT( items.count(), sizetype(0) );
+}
+
+void MacroitemTests::testMacroItemString()
+{
+
+
+ kdDebug()<<"===================== testMacroItemString() ======================" << endl;
+
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+ KSharedPtr<KoMacro::Variable> variableptr = actionptr->variable(TESTSTRING);
+
+ //create new macroitem for testing
+ KoMacro::MacroItem* macroitem = new KoMacro::MacroItem();
+ //set the action
+ macroitem->setAction(d->testaction);
+
+ //append the macroitem to testitems
+ items.append(macroitem);
+
+ //increased ??
+ KOMACROTEST_ASSERT( items.count(), sizetype(2) );
+
+ //Manipulate the macroitem
+ macroitem->setVariable(TESTSTRING, "TeStString");
+ variableptr = macroitem->variable(TESTSTRING);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("TeStString"));
+
+
+ //secondway for appending an macroitem
+ //add the manipulated macroitem
+ d->macro->addItem(macroitem);
+
+ //increased ??
+ KOMACROTEST_ASSERT( items.count(), sizetype(3));
+
+}
+
+void MacroitemTests::testMacroItemInt()
+{
+
+
+ kdDebug()<<"===================== testMacroItemInt() ======================" << endl;
+
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //create new macroitem for testing
+ KoMacro::MacroItem* macroitem = new KoMacro::MacroItem();
+ //set the action
+ macroitem->setAction(d->testaction);
+ items.append(macroitem);
+
+ macroitem->setVariable(TESTINT,INT_MIN);
+ KSharedPtr<KoMacro::Variable> variableptr = macroitem->variable(TESTINT);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MIN));
+
+ macroitem->setVariable(TESTINT,-1);
+ variableptr = macroitem->variable(TESTINT);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(-1));
+
+ macroitem->setVariable(TESTINT,QVariant(0));
+ variableptr = macroitem->variable(TESTINT);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(0));
+
+ macroitem->setVariable(TESTINT,1);
+ variableptr = macroitem->variable(TESTINT);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(1));
+
+ macroitem->setVariable(TESTINT,INT_MAX);
+ variableptr = macroitem->variable(TESTINT);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
+}
+
+void MacroitemTests::testMacroItemBool()
+{
+
+
+ kdDebug()<<"===================== testMacroItemBool() ======================" << endl;
+
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //create new macroitem for testing
+ KoMacro::MacroItem* macroitem = new KoMacro::MacroItem();
+ //set the action
+ macroitem->setAction(d->testaction);
+ items.append(macroitem);
+
+ macroitem->setVariable(TESTBOOL,"false");
+ KSharedPtr<KoMacro::Variable> variableptr = macroitem->variable(TESTBOOL);
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
+}
+#include "macroitemtests.moc"
diff --git a/kexi/plugins/macros/tests/macroitemtests.h b/kexi/plugins/macros/tests/macroitemtests.h
new file mode 100644
index 00000000..3e44eebd
--- /dev/null
+++ b/kexi/plugins/macros/tests/macroitemtests.h
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_ACTIONTESTS_H
+#define KOMACROTEST_ACTIONTESTS_H
+
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class MacroitemTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ MacroitemTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~MacroitemTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacro();
+
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacroItemString();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacroItemInt();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacroItemBool();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/macrotests.cpp b/kexi/plugins/macros/tests/macrotests.cpp
new file mode 100644
index 00000000..ed222df2
--- /dev/null
+++ b/kexi/plugins/macros/tests/macrotests.cpp
@@ -0,0 +1,192 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "macrotests.h"
+#include "testobject.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/function.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/metaobject.h"
+#include "../lib/metamethod.h"
+#include "../lib/metaparameter.h"
+#include "../lib/exception.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+
+#include <qstringlist.h>
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+ KUNITTEST_SUITE("KoMacroTestSuite")
+ KUNITTEST_REGISTER_TESTER(MacroTests);
+
+ class MacroTests::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ TestObject* testobject;
+
+ TestAction* testaction;
+
+ QDomDocument* doomdocument;
+
+ Private()
+ : xmlguiclient(0)
+ , testobject(0)
+ , testaction(0)
+ , doomdocument(0)
+ {
+ }
+ };
+}
+
+typedef QValueList< KSharedPtr<KoMacro::MacroItem> >::size_type sizetype;
+
+
+MacroTests::MacroTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+MacroTests::~MacroTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+
+void MacroTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+ //::KoMacro::Manager::init( d->xmlguiclient );
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+ d->testobject = new TestObject( this );
+ ::KoMacro::Manager::self()->publishObject("TestObject", d->testobject);
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+
+ d->doomdocument = new QDomDocument();
+
+ QString const xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\" >"
+ "<item action=\"testaction\" >"
+ "</item>"
+ "</macro>");
+
+ d->doomdocument->setContent(xml);
+}
+
+void MacroTests::tearDown()
+{
+ delete d->doomdocument;
+ delete d->testobject;
+ delete d->xmlguiclient;
+}
+
+void MacroTests::testMacro()
+{
+ kdDebug()<<"===================== testMacro() ======================" << endl;
+
+ QDomElement const domelement = d->doomdocument->documentElement();
+
+ KSharedPtr<KoMacro::Macro> macro1 = KoMacro::Manager::self()->createMacro("testMacro");
+ KSharedPtr<KoMacro::Macro> macro2 = KoMacro::Manager::self()->createMacro("testMacro");
+ //Is our XML parseable ?
+ KOMACROTEST_ASSERT(macro1->parseXML(domelement),true);
+ KOMACROTEST_ASSERT(macro2->parseXML(domelement),true);
+
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(macro1.data()), sizetype(0));
+ KOMACROTEST_XASSERT(sizetype(macro2.data()), sizetype(0));
+
+ //check macro1 == macro2
+ KOMACROTEST_ASSERT(macro1->name(), macro2->name() );
+
+ //create list of KsharedPtr from the childs of the macro
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items1 = macro1->items();
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items2 = macro2->items();
+
+ //check that there is one
+ KOMACROTEST_XASSERT( items1.count(), sizetype(0) );
+ KOMACROTEST_XASSERT( items2.count(), sizetype(0) );
+
+ //check macro1 == macro2
+ KOMACROTEST_ASSERT( items1.count(), items2.count() );
+
+ //check the name
+ KOMACROTEST_ASSERT( QString(macro1->name()), QString("testMacro") );
+
+ {
+ const QString tmp1 = QString("test");
+ macro1->setName(tmp1);
+
+ //check the name changed
+ KOMACROTEST_XASSERT( QString(macro1->name()), QString("testMacro") );
+ //check the name
+ KOMACROTEST_ASSERT( QString(macro1->name()), QString("test") );
+ }
+
+ //fetch the first one
+ KSharedPtr<KoMacro::Action> actionptr = items1[0]->action();
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(actionptr.data()), sizetype(0));
+ //check that it has the right name
+ KOMACROTEST_ASSERT( QString(actionptr->name()), QString("testaction") );
+ //check that it has the right text
+ KOMACROTEST_ASSERT( actionptr->text(), QString("Test") );
+
+ //try to clear items
+ macro1->clearItems();
+ //get items
+ items1 = macro1->items();
+ //check that they are deleted
+ KOMACROTEST_ASSERT( items1.count(), sizetype(0) );
+}
+#include "macrotests.moc"
diff --git a/kexi/plugins/macros/tests/macrotests.h b/kexi/plugins/macros/tests/macrotests.h
new file mode 100644
index 00000000..ed8d0f21
--- /dev/null
+++ b/kexi/plugins/macros/tests/macrotests.h
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_MACROTESTS_H
+#define KOMACROTEST_MACROTESTS_H
+
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class MacroTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ MacroTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~MacroTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Test the @a KoMacro::Action functionality.
+ */
+ void testMacro();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/testaction.cpp b/kexi/plugins/macros/tests/testaction.cpp
new file mode 100644
index 00000000..4063aa1b
--- /dev/null
+++ b/kexi/plugins/macros/tests/testaction.cpp
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "testaction.h"
+
+#include "../lib/action.h"
+#include "../lib/context.h"
+#include "../lib/macroitem.h"
+#include "../lib/variable.h"
+
+#include <klocale.h>
+#include <kdebug.h>
+
+using namespace KoMacroTest;
+
+TestAction::TestAction()
+ : KoMacro::Action("testaction", "Test")
+{
+ setVariable("teststring", "Stringtest", QString("testString"));
+ setVariable("testint", "Inttest", int(0));
+ setVariable("testdouble", "Doubletest", double(0.5));
+ setVariable("testbool", "Booltest", QVariant(true,0));
+}
+
+TestAction::~TestAction()
+{
+}
+
+bool TestAction::notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name)
+{
+ Q_UNUSED(macroitem);
+ Q_UNUSED(name);
+ return true;
+}
+
+void TestAction::activate(KSharedPtr<KoMacro::Context> context)
+{
+ kdDebug() << "TestAction::activate(KSharedPtr<Context>)" << endl;
+ const QString teststring = context->variable("teststring")->variant().toString();
+ const int testint = context->variable("testint")->variant().toInt();
+ const bool testbool = context->variable("testbool")->variant().toBool();
+}
+
+#include "testaction.moc"
diff --git a/kexi/plugins/macros/tests/testaction.h b/kexi/plugins/macros/tests/testaction.h
new file mode 100644
index 00000000..9eebff3c
--- /dev/null
+++ b/kexi/plugins/macros/tests/testaction.h
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_TESTACTION_H
+#define KOMACROTEST_TESTACTION_H
+
+#include <ksharedptr.h>
+
+#include "../lib/action.h"
+
+namespace KoMacro {
+ class Context;
+ class MacroItem;
+}
+
+namespace KoMacroTest {
+
+ /**
+ * This TestAction implements a @a KoMacro::Action to
+ * test the functionality provided by this class.
+ */
+ class TestAction : public KoMacro::Action
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ TestAction();
+
+ /**
+ * Destructor.
+ */
+ virtual ~TestAction();
+
+ /**
+ * This function is called, when the @a KoMacro::Variable
+ * with name @p name used within the @a KoMacro::MacroItem
+ * @p macroitem got changed.
+ *
+ * @param macroitem The @a KoMacro::MacroItem instance where
+ * the variable defined with @p name is located in.
+ * @param name The name the @a KoMacro::Variable has.
+ * @return true if the update was successfully else false
+ * is returned.
+ */
+ virtual bool notifyUpdated(KSharedPtr<KoMacro::MacroItem> macroitem, const QString& name);
+
+ public slots:
+
+ /**
+ * Called if the @a Action should be executed within the
+ * defined @p context .
+ */
+ virtual void activate(KSharedPtr<KoMacro::Context> context);
+
+ };
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/testobject.cpp b/kexi/plugins/macros/tests/testobject.cpp
new file mode 100644
index 00000000..39cadb7a
--- /dev/null
+++ b/kexi/plugins/macros/tests/testobject.cpp
@@ -0,0 +1,117 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "testobject.h"
+
+//#include "../lib/manager.h"
+//#include "../lib/action.h"
+//#include "../lib/function.h"
+//#include "../lib/macro.h"
+//#include "../lib/metaobject.h"
+
+//#include <qstringlist.h>
+//#include <qdom.h>
+
+#include <kdebug.h>
+//#include <kxmlguiclient.h>
+
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * @internal d-pointer class to be more flexible on future extension of the
+ * functionality without to much risk to break the binary compatibility.
+ */
+ class TestObject::Private
+ {
+ public:
+
+ /**
+ * The @a KUnitTest::Tester instance that likes to test
+ * our TestObject instance.
+ */
+ KUnitTest::Tester* const tester;
+ Private(KUnitTest::Tester* const tester)
+ : tester(tester)
+ {
+ }
+ };
+
+}
+
+TestObject::TestObject(KUnitTest::Tester* const tester)
+ : QObject()
+ , d( new Private(tester) ) // create the private d-pointer instance.
+{
+ setName("TestObject");
+}
+
+TestObject::~TestObject()
+{
+ delete d;
+}
+
+//testObject without arguments
+void TestObject::myslot()
+{
+ QString s = "CALLED => TestObject::myslot()";
+ //be loud
+ kdDebug() << s << endl;
+ //add some extra Debuginfos to TestResults see tester.h
+ d->tester->results()->addDebugInfo(s);
+}
+
+//testobject with QString and int argument
+//int is returnvalue
+int TestObject::myslot(const QString&, int i)
+{
+ QString s = "CALLED => TestObject::myslot(const QString&, int)";
+ //be loud
+ kdDebug() << s << endl;
+ //add some extra debuginfos to TestResults
+ d->tester->results()->addDebugInfo(s);
+ return i;
+}
+
+//testobject with QString argument
+//QString is returnvalue
+QString TestObject::myslot(const QString& s)
+{
+ QString t = QString("CALLED => TestObject::myslot(const QString& s) s=%1").arg(s);
+ //be loud
+ kdDebug() << t << endl;
+ //add some extra Debuginfos to TestResults
+ d->tester->results()->addDebugInfo(t);
+ return s;
+}
+
+//testobject with QString and double argument
+//double is returnvalue
+double TestObject::myslot(const QString&, double d)
+{
+ QString s = "CALLED => TestObject::myslot(const QString&, double)";
+ //be loud
+ kdDebug() << s << endl;
+ //add some extra Debuginfos to TestResults
+ this->d->tester->results()->addDebugInfo(s);
+ return d;
+}
+
+#include "testobject.moc"
diff --git a/kexi/plugins/macros/tests/testobject.h b/kexi/plugins/macros/tests/testobject.h
new file mode 100644
index 00000000..da5e8ae2
--- /dev/null
+++ b/kexi/plugins/macros/tests/testobject.h
@@ -0,0 +1,85 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_TESTOBJECT_H
+#define KOMACROTEST_TESTOBJECT_H
+
+#include <qobject.h>
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The TestObject class is used to test handling and communication
+ * of external from QObject inheritated classes.
+ */
+ class TestObject : public QObject
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ *
+ * @param tester The @a KUnitTest::Tester instance
+ * that likes to test our TestObject instance.
+ */
+ TestObject(KUnitTest::Tester* const tester);
+
+ /**
+ * Destructor.
+ */
+ virtual ~TestObject();
+
+ public slots:
+
+ /**
+ * This slot got published to the KoMacro-framework
+ * and will be called to test the functionality.
+ */
+ void myslot();
+
+ /**
+ * This slot got published to the KoMacro-framework
+ * and will be called to test the functionality.
+ */
+ int myslot(const QString&, int);
+
+ /**
+ * This slot got published to the KoMacro-framework
+ * and will be called to test the functionality.
+ */
+ QString myslot(const QString&);
+
+ /**
+ * This slot got published to the KoMacro-framework
+ * and will be called to test the functionality.
+ * @return is @param d
+ */
+ double myslot(const QString&, double d);
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/variabletests.cpp b/kexi/plugins/macros/tests/variabletests.cpp
new file mode 100644
index 00000000..8bc8d9c7
--- /dev/null
+++ b/kexi/plugins/macros/tests/variabletests.cpp
@@ -0,0 +1,236 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Sebastian Sauer (mail@dipe.org)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "variabletests.h"
+#include "testobject.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/function.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/metaobject.h"
+#include "../lib/metamethod.h"
+#include "../lib/metaparameter.h"
+#include "../lib/exception.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+
+#include <qstringlist.h>
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+
+ KUNITTEST_SUITE("KoMacroTestSuite");
+ KUNITTEST_REGISTER_TESTER(VariableTests);
+
+
+ class VariableTests::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ TestAction* testaction;
+
+ QDomDocument* doomdocument;
+
+ KSharedPtr<KoMacro::Macro> macro;
+
+ Private()
+ : xmlguiclient(0)
+ , testaction(0)
+ , doomdocument(0)
+ , macro(0)
+ {
+ }
+ };
+}
+
+typedef QValueList< KSharedPtr<KoMacro::MacroItem> >::size_type sizetype;
+
+/******************************************************************************
+* This is an xtra big TODO:
+* - get rid of all double declarations
+* - create xtra-class for Variable/Macroitem tests
+* - add comments
+******************************************************************************/
+VariableTests::VariableTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+VariableTests::~VariableTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+
+void VariableTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+
+ d->doomdocument = new QDomDocument();
+
+ QString const xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\" >"
+ "<item action=\"testaction\" >"
+ "</item>"
+ "</macro>");
+
+ d->doomdocument->setContent(xml);
+ d->macro = KoMacro::Manager::self()->createMacro("testMacro");
+ d->macro->parseXML(d->doomdocument->documentElement());
+ d->macro->execute(this);
+}
+
+void VariableTests::tearDown()
+{
+ delete d->macro;
+ delete d->doomdocument;
+ delete d->xmlguiclient;
+}
+
+void VariableTests::testMacro()
+{
+ kdDebug()<<"===================== testVariable() ===================" << endl;
+ kdDebug()<<"===================== testMacro() ======================" << endl;
+
+ //fetch Items and ..
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+
+ //... check that there is one
+ KOMACROTEST_XASSERT( items.count(), sizetype(0) );
+}
+
+void VariableTests::testVariableString() {
+ kdDebug()<<"===================== testVariableString() ======================" << endl;
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //fetch the "teststring"-variable
+ KSharedPtr<KoMacro::Variable> variableptr = actionptr->variable(TESTSTRING);
+ //So there is a variable, does hasVariable() work ?
+ KOMACROTEST_ASSERT(actionptr->hasVariable(TESTSTRING),true);
+ //check count of variables
+ KOMACROTEST_ASSERT(sizetype(actionptr->variableNames().count()),sizetype(4));
+ //remove one
+ actionptr->removeVariable(TESTSTRING);
+ //Decreased ??
+ KOMACROTEST_ASSERT(sizetype(actionptr->variableNames().count()),sizetype(3));
+ //add one
+ actionptr->setVariable(variableptr);
+ //increased ??
+ KOMACROTEST_ASSERT(sizetype(actionptr->variableNames().count()),sizetype(4));
+
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is "testString"
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("testString"));
+
+ actionptr->setVariable("teststring", "STRINGTEST", "TestString");
+ variableptr = actionptr->variable("teststring");
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toString(),QString("TestString"));
+}
+
+void VariableTests::testVariableInt() {
+ kdDebug()<<"===================== testVariableInt() ======================" << endl;
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //fetch the "testint"-variable
+ KSharedPtr<KoMacro::Variable> variableptr = actionptr->variable(TESTINT);
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is 0
+ KOMACROTEST_ASSERT(variableptr->variant().toInt(),int(0));
+
+ actionptr->setVariable(TESTINT,"INTTEST",INT_MAX);
+ variableptr = actionptr->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX));
+
+ actionptr->setVariable(TESTINT,"INTTEST",INT_MAX+1);
+ variableptr = actionptr->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MAX+1));
+
+ actionptr->setVariable(TESTINT,"INTTEST",INT_MIN);
+ variableptr = actionptr->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MIN));
+
+ actionptr->setVariable(TESTINT,"INTTEST",INT_MIN-1);
+ variableptr = actionptr->variable("testint");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(sizetype(variableptr->variant().toInt()),sizetype(INT_MIN-1));
+}
+
+void VariableTests::testVariableBool() {
+ kdDebug()<<"===================== testVariableBool() ======================" << endl;
+ QValueList< KSharedPtr<KoMacro::MacroItem> >& items = d->macro->items();
+ KSharedPtr<KoMacro::Action> actionptr = items[0]->action();
+
+ //fetch the "testbool"-variable
+ KSharedPtr<KoMacro::Variable> variableptr = actionptr->variable(TESTBOOL);
+ //check that it is not null
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ //check that it is " "
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),true);
+
+ actionptr->setVariable("testbool","BOOLTEST", "false");
+ variableptr = actionptr->variable("testbool");
+ KOMACROTEST_XASSERT(sizetype(variableptr.data()), sizetype(0));
+ KOMACROTEST_ASSERT(variableptr->variant().toBool(),false);
+}
+#include "variabletests.moc"
diff --git a/kexi/plugins/macros/tests/variabletests.h b/kexi/plugins/macros/tests/variabletests.h
new file mode 100644
index 00000000..5bc7f144
--- /dev/null
+++ b/kexi/plugins/macros/tests/variabletests.h
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
+ * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_VARIABLETESTS_H
+#define KOMACROTEST_VARIABLETESTS_H
+
+#include <kunittest/tester.h>
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class VariableTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ VariableTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~VariableTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testMacro();
+
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testVariableString();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testVariableInt();
+ /**
+ * Subtest for the @a KoMacro::Action functionality.
+ */
+ void testVariableBool();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+ };
+
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/xmlhandlertests.cpp b/kexi/plugins/macros/tests/xmlhandlertests.cpp
new file mode 100644
index 00000000..9a0ebcb1
--- /dev/null
+++ b/kexi/plugins/macros/tests/xmlhandlertests.cpp
@@ -0,0 +1,619 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "xmlhandlertests.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+#include <cfloat>
+
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+ KUNITTEST_SUITE("KoMacroTestSuite")
+ KUNITTEST_REGISTER_TESTER(XMLHandlerTests);
+
+ class XMLHandlerTests::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ KSharedPtr<KoMacro::Action> testaction;
+
+ Private()
+ : xmlguiclient(0)
+ , testaction(0)
+ {
+ }
+ };
+}
+
+XMLHandlerTests::XMLHandlerTests()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+XMLHandlerTests::~XMLHandlerTests()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+
+void XMLHandlerTests::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+
+ //Singelton more or less ...
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+
+ d->testaction = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+}
+
+void XMLHandlerTests::tearDown()
+{
+ delete d->xmlguiclient;
+}
+
+/**
+* Test the @a KoMacro::XMLHandler parseXML() and toXML()-function.
+*/
+void XMLHandlerTests::testParseAndToXML()
+{
+ kdDebug()<<"===================== testParseAndToXML() ======================" << endl;
+
+ // 1.Test - Correct DomElement.
+ testCorrectDomElement();
+ // 2.Test - XML-document with bad root element.
+ testBadRoot();
+ // 3.Test - XML-document with a missing Variable.
+ testMissingVariable();
+ // 4.Test - One more Variable in XML-Document.
+ testMoreVariables();
+ // 5.Test - XML-document with wrong macro-xmlversion.
+ testWrongVersion();
+ // 6.Test - XML-document if it has a wrong structure like wrong parathesis
+ // or missing end tag.
+ testWrongXMLStruct();
+ // 7.Test-XML-document with maximum field-size.
+ testMaxNum();
+ // 8.Test-XML-document with maximum+1 field-size.
+ testMaxNum2();
+ // 9.Test-XML-document with minimum field-size.
+ testMinNum();
+ // 10.Test-XML-document with minimum-1 field-size.
+ testMinNum2();
+ // 11.Test - With a to big number.
+ testBigNumber();
+ // 12.Test - With two MacroItems.
+ testTwoMacroItems();
+}
+
+/***************************************************************************
+* Begin of Sub-methos of testParseXML().
+***************************************************************************/
+// 1.Test - Correct DomElement.
+void XMLHandlerTests::testCorrectDomElement()
+{
+ // Local Init
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ // Is our XML parseable by calling parseXML()?
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ // Is the parsen content in the Macro correct ?
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ // Transform back by calling toXML().
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+
+ // Test the Compare-method when a Variable will change, it must fail.
+ macro->items().first()->variable("teststring")->setVariant("bla");
+ isvariableok.replace("teststring",false);
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+}
+
+// 2.Test - XML-document with bad root element.
+void XMLHandlerTests::testBadRoot()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<maro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</maro>");
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_XASSERT(macro->parseXML(elem),true);
+
+ //no assertMacroContentEqToXML(), because parsing failed.
+ assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
+}
+
+// 3.Test - XML-document with a missing Variable.
+void XMLHandlerTests::testMissingVariable()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 4.Test - One more Variable in XML-Document.
+void XMLHandlerTests::testMoreVariables()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "<variable name=\"testbla\" >somethingwrong</variable>"
+ "</item>"
+ "</macro>");
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ isvariableok["testbla"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 5.Test - XML-document with wrong macro-xmlversion.
+void XMLHandlerTests::testWrongVersion()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"2\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_XASSERT(macro->parseXML(elem),true);
+
+ //no assertMacroContentEqToXML(), because parsing failed.
+ assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
+}
+
+// 6.Test - XML-document if it has a wrong structure like wrong parathesis
+// or missing end tag.
+void XMLHandlerTests::testWrongXMLStruct()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "macro xmlversion=\"1\">>"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "</item>"
+ "</macro>");
+ KOMACROTEST_XASSERT(doomdocument.setContent(xml),true);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_XASSERT(macro->parseXML(elem),true);
+
+ //no assertMacroContentEqToXML(), because parsing failed.
+ assertMacroContentEqToXML(macro,elem,true,false,QMap<QString,bool>());
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,true,false,QMap<QString,bool>());
+}
+
+// 7.Test-XML-document with maximum field-size.
+void XMLHandlerTests::testMaxNum()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MAX).arg(DBL_MAX);
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 8.Test-XML-document with maximum+1 field-size.
+void XMLHandlerTests::testMaxNum2()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MAX+1).arg(DBL_MAX+1);
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 9.Test-XML-document with minimum field-size.
+void XMLHandlerTests::testMinNum()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MIN).arg(DBL_MIN);
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 10.Test-XML-document with minimum+1 field-size.
+void XMLHandlerTests::testMinNum2()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MIN-1).arg(DBL_MIN-1);
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 11.Test - With a to big number.
+void XMLHandlerTests::testBigNumber()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > 0123456789012345678901234567890123456789 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %1 </variable>"
+ "</item>"
+ "</macro>").arg(DBL_MAX+1);
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+
+// 12.Test - With two MacroItems.
+void XMLHandlerTests::testTwoMacroItems()
+{
+ KSharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
+ QDomDocument doomdocument;
+
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "<variable name=\"testbla\" >somethingwrong</variable>"
+ "</item>"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testBBstring2</variable>"
+ "<variable name=\"testint\" >4</variable>"
+ "<variable name=\"testbool\" >false</variable>"
+ "<variable name=\"testdouble\" >0.7</variable>"
+ "<variable name=\"testbla\" >somethingwrong2</variable>"
+ "</item>"
+ "</macro>");
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+ KOMACROTEST_ASSERT(macro->parseXML(elem),true);
+
+ QMap<QString,bool> isvariableok;
+ isvariableok["teststring"] = true;
+ isvariableok["testint"] = true;
+ isvariableok["testbool"] = true;
+ isvariableok["testdouble"] = true;
+ assertMacroContentEqToXML(macro,elem,false,true,isvariableok);
+
+ const QDomElement elem2 = macro->toXML();
+ assertMacroContentEqToXML(macro,elem2,false,true,isvariableok);
+}
+/***************************************************************************
+* End of Sub-methos of testParseAndToXML().
+***************************************************************************/
+
+/**
+* Compares a XML-Element with a Macro. Call sub-asserts.
+* @p macro The parsen @a Macro.
+* @p elem The given @a QDomElement which is parsen.
+* @p isitemsempty Bool for expectation of an empty @a MacroItem -List.
+* @p isactionset Bool for expectation that the @a Action -names are equal.
+* @p isvariableok QMap of Bools for comparing each @a Variable .
+*/
+void XMLHandlerTests::assertMacroContentEqToXML(const KSharedPtr<KoMacro::Macro> macro,
+ const QDomElement& elem,
+ const bool isitemsempty,
+ const bool isactionset,
+ const QMap<QString, bool> isvariableok)
+{
+ // Make an Iterator over the MacroItems of the Macro.
+ const QValueList<KSharedPtr<KoMacro::MacroItem > > macroitems = macro->items();
+ QValueList<KSharedPtr<KoMacro::MacroItem > >::ConstIterator
+ mit(macroitems.constBegin()), end(macroitems.constEnd());
+
+ //1.comparison - Is the MacroItem-list empty?
+ {
+ if( isitemsempty ) {
+ KOMACROTEST_XASSERT(macroitems.empty(),false);
+ kdDebug() << "There is no correct MacroItem parsen." << endl;
+ return;
+ }
+ else {
+ KOMACROTEST_ASSERT(macroitems.empty(),false);
+ }
+ }
+
+ // Got to the first item-elements of the elem (there is only one in the tests).
+ QDomNode itemnode = elem.firstChild();
+
+ // Iterate over the MacroItems and item-elements.
+ while(mit != end && ! itemnode.isNull()) {
+ const KSharedPtr<KoMacro::MacroItem> macroitem = *mit;
+ const QDomElement itemelem = itemnode.toElement();
+
+ //2.comparison - Is the Action-name equal?
+ {
+ if( ! isactionset) {
+ KOMACROTEST_XASSERT(macroitem->action()->name() == itemelem.attribute("action"),true);
+ kdDebug() << "Action-name not equal: "
+ << macroitem->action()->name()
+ << " != " << itemelem.attribute("action") << endl;
+ return;
+ }
+ else {
+ KOMACROTEST_ASSERT(macroitem->action()->name() == itemelem.attribute("action"),true);
+ }
+ }
+
+ // Go down to MacroItem->Variable and item->variable and compare them.
+ QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables = macroitem->variables();
+ QDomNode varnode = itemelem.firstChild();
+
+ while ( ! varnode.isNull()) {
+ const QDomElement varelem = varnode.toElement();
+ const KSharedPtr<KoMacro::Variable> varitem = mvariables.find(varelem.attribute("name")).data();
+
+ //3.comparison - Is the content of the Variable
+ // in the MacroItem and and item equal?
+ {
+ const bool var = *isvariableok.find(varelem.attribute("name"));
+ if( ! var ) {
+ KOMACROTEST_XASSERT(varitem->variant() == QVariant(varelem.text()), !var);
+ kdDebug() << "The content of the Variable: " << varitem->name()
+ << " is not equal." << varitem->variant()
+ << "!=" << varelem.text() << endl;
+ }
+ else {
+ KOMACROTEST_ASSERT(varitem->variant() == QVariant(varelem.text()), var);
+ }
+
+ }
+
+ // Erase the MacroItem from the map, because it is parsen correctly.
+ mvariables.erase(varitem->name());
+ // Go to next Variable in node-tree.
+ varnode = varnode.nextSibling();
+ }
+
+ //4.comparison - Is every MacroItem parsen?
+ {
+ KOMACROTEST_ASSERT(mvariables.empty(),true);
+ kdDebug() << "There are non-filled variable in the MacroItem: " << mvariables.count() <<endl;
+ }
+
+ // Go to next MacroItem and next item-element.
+ mit++;
+ itemnode = itemnode.nextSibling();
+ }
+}
+
+// Prints a QMap of Variables to kdDebug().
+void XMLHandlerTests::printMvariables(const QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables, const QString s)
+{
+ //QValueList<QString>::ConstIterator kit (keys.constBegin()), end(keys.constEnd());
+ QMap<QString, KSharedPtr<KoMacro::Variable > >::ConstIterator mvit (mvariables.constBegin()), end(mvariables.constEnd());
+ while(mvit != end){
+ const KoMacro::Variable * v = *mvit;
+ kdDebug() << s << ": " << v->name() << endl;
+ mvit++;
+ }
+}
+
+#include "xmlhandlertests.moc"
diff --git a/kexi/plugins/macros/tests/xmlhandlertests.h b/kexi/plugins/macros/tests/xmlhandlertests.h
new file mode 100644
index 00000000..c78a8c79
--- /dev/null
+++ b/kexi/plugins/macros/tests/xmlhandlertests.h
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_XMLHandlerTests_H
+#define KOMACROTEST_XMLHandlerTests_H
+
+#include <kunittest/tester.h>
+#include "../lib/macro.h"
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class XMLHandlerTests : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ XMLHandlerTests();
+
+ /**
+ * Destructor.
+ */
+ virtual ~XMLHandlerTests();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Test the @a KoMacro::XMLHandler parseXML()-function.
+ */
+ void testParseAndToXML();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+
+ /**
+ * Compares a XML-Element with a Macro. Call sub-asserts.
+ * @p macro The parsen @a Macro.
+ * @p domelement The given @a QDomElement which is parsen.
+ * @p isitemsempty Bool for expectation of an empty @a MacroItem -List.
+ * @p isactionset Bool for expectation that the @a Action -names are equal.
+ * @p isvariableok QMap of Bools for comparing each @a Variable .
+ */
+ void assertMacroContentEqToXML(const KSharedPtr<KoMacro::Macro> macro,
+ const QDomElement& elem,
+ const bool isitemsempty,
+ const bool isactionset,
+ const QMap<QString, bool> isvariableok);
+
+ // Prints a QMap of Variables to kdDebug().
+ void printMvariables(const QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables, const QString s);
+
+ /**
+ * Sub-methods of testParseXML() and testToXML().
+ * Test the correct parsing of a @a QDomElement into a @a Macro
+ * respectively expected failure of parsing. Then transform it
+ * back and compare it.
+ */
+ // 1.Test - Correct DomElement.
+ void testCorrectDomElement();
+ // 2.Test - XML-document with bad root element.
+ void testBadRoot();
+ // 3.Test - XML-document with a missing Variable.
+ void testMissingVariable();
+ // 4.Test - One more Variable in XML-Document.
+ void testMoreVariables();
+ // 5.Test - XML-document with wrong macro-xmlversion.
+ void testWrongVersion();
+ // 6.Test - XML-document if it has a wrong structure like
+ // wrong parathesis or missing end tag.
+ void testWrongXMLStruct();
+ // 7.Test-XML-document with maximum field-size.
+ void testMaxNum();
+ // 8.Test-XML-document with maximum+1 field-size.
+ void testMaxNum2();
+ // 9.Test-XML-document with minimum field-size.
+ void testMinNum();
+ // 10.Test-XML-document with minimum-1 field-size.
+ void testMinNum2();
+ // 11.Test - With a to big number.
+ void testBigNumber();
+ // 12.Test - With two MacroItems.
+ void testTwoMacroItems();
+ };
+}
+
+#endif
diff --git a/kexi/plugins/macros/tests/xmlhandlertests2.cpp b/kexi/plugins/macros/tests/xmlhandlertests2.cpp
new file mode 100644
index 00000000..2234eaae
--- /dev/null
+++ b/kexi/plugins/macros/tests/xmlhandlertests2.cpp
@@ -0,0 +1,1161 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#include "xmlhandlertests2.h"
+#include "testaction.h"
+#include "komacrotestbase.h"
+
+#include "../lib/action.h"
+#include "../lib/manager.h"
+#include "../lib/macro.h"
+#include "../lib/variable.h"
+#include "../lib/macroitem.h"
+
+#include <ostream>
+#include <cfloat>
+
+#include <qdom.h>
+
+#include <kdebug.h>
+#include <kunittest/runner.h>
+#include <kxmlguiclient.h>
+
+using namespace KUnitTest;
+using namespace KoMacroTest;
+
+namespace KoMacroTest {
+
+ /**
+ * Register KoMacroTest::CommonTests as TestSuite.
+ */
+ KUNITTEST_SUITE("KoMacroTestSuite")
+ KUNITTEST_REGISTER_TESTER(XMLHandlerTests2);
+
+ class XMLHandlerTests2::Private
+ {
+ public:
+ /**
+ * An KXMLGUIClient instance created on @a setUp() and
+ * passed to the @a KoMacro::Manager to bridge to the
+ * app-functionality.
+ */
+ KXMLGUIClient* xmlguiclient;
+
+ /**
+ * @a Macro instance as a container for the macroitems;
+ */
+ KSharedPtr<KoMacro::Macro> macro; // container for manually created items
+ KSharedPtr<KoMacro::Macro> macro2; // container for parsen items
+ KSharedPtr<KoMacro::Macro> macro3; // container for parsen items after back-converting by toXML() and again parseXML()
+
+ /**
+ * An @a TestObject instance used internaly to test
+ * handling and communication with from QObject
+ * inheritated instances.
+ */
+ KSharedPtr<KoMacro::Action> testaction;
+ KSharedPtr<KoMacro::Action> action2; // action of the parsen macro2
+ KSharedPtr<KoMacro::Action> action3; // action of the parsen macro3
+ KSharedPtr<KoMacro::Action> testaction_2; // for test12
+ KSharedPtr<KoMacro::Action> action2_2; // action of the parsen macro2, for test12
+ KSharedPtr<KoMacro::Action> action3_2; // action of the parsen macro3, for test12
+
+ /**
+ * Represents a @a QValuList of @a MacroItem which are parsen in the
+ * correspondig @a Macro .
+ */
+ QValueList<KSharedPtr<KoMacro::MacroItem > > macroitems2; // items of macro2
+ QValueList<KSharedPtr<KoMacro::MacroItem > > macroitems3; // items of macro3
+
+ /**
+ * @a MacroItem instances which ist fillen manually from the given XML
+ * and parsen by the @a XMLHandler over the XML.
+ */
+ KSharedPtr<KoMacro::MacroItem> macroitem; // created manually from XML
+ KSharedPtr<KoMacro::MacroItem> macroitem2; // parsen from XML in macro2
+ KSharedPtr<KoMacro::MacroItem> macroitem3; // parsen from XML in macro3
+ KSharedPtr<KoMacro::MacroItem> macroitem_2; // created manually from XML, for test12
+ KSharedPtr<KoMacro::MacroItem> macroitem2_2;// parsen from XML in macro2, for test12
+ KSharedPtr<KoMacro::MacroItem> macroitem3_2;// parsen from XML in macro3, for test12
+
+ Private()
+ : xmlguiclient(0)
+ , testaction(0)
+ {
+ }
+ };
+}
+
+XMLHandlerTests2::XMLHandlerTests2()
+ : KUnitTest::SlotTester()
+ , d( new Private() ) // create the private d-pointer instance.
+{
+}
+
+XMLHandlerTests2::~XMLHandlerTests2()
+{
+ delete d->xmlguiclient;
+ delete d;
+}
+
+
+void XMLHandlerTests2::setUp()
+{
+ d->xmlguiclient = new KXMLGUIClient();
+
+ //Singelton more or less ...
+ if (::KoMacro::Manager::self() == 0) {
+ ::KoMacro::Manager::init( d->xmlguiclient );
+ }
+
+ d->macro = KoMacro::Manager::self()->createMacro("testMacro");
+ d->macro2 = KoMacro::Manager::self()->createMacro("testMacro");
+ d->macro3 = KoMacro::Manager::self()->createMacro("testMacro");
+
+ d->testaction = new TestAction();
+ d->testaction_2 = new TestAction();
+ ::KoMacro::Manager::self()->publishAction(d->testaction);
+ ::KoMacro::Manager::self()->publishAction(d->testaction_2);
+}
+
+void XMLHandlerTests2::tearDown()
+{
+ delete d->xmlguiclient;
+}
+
+/**
+* Test the @a KoMacro::XMLHandler parseXML() and toXML()-function.
+*/
+void XMLHandlerTests2::testParseAndToXML()
+{
+ kdDebug()<<"===================== testParseAndToXML2() ======================" << endl;
+
+ // 1.Test - Correct DomElement.
+ testCorrectDomElement();
+ // 2.Test - XML-document with bad root element.
+ testBadRoot();
+ // 3.Test - XML-document with a missing Variable.
+ testMissingVariable();
+ // 4.Test - One more Variable in XML-Document.
+ testMoreVariables();
+ // 5.Test - XML-document with wrong macro-xmlversion.
+ testWrongVersion();
+ // 6.Test - XML-document if it has a wrong structure like wrong parathesis
+ // or missing end tag.
+ testWrongXMLStruct();
+ // 7.Test-XML-document with maximum field-size.
+ testMaxNum();
+ // 8.Test-XML-document with maximum+1 field-size.
+ testMaxNum2();
+ // 9.Test-XML-document with minimum field-size.
+ testMinNum();
+ // 10.Test-XML-document with minimum-1 field-size.
+ testMinNum2();
+ // 11.Test - With a to big number.
+ testBigNumber();
+ // 12.Test - With two MacroItems.
+ testTwoMacroItems();
+}
+
+
+/***************************************************************************
+* Begin of Sub-methos of testParseXML().
+***************************************************************************/
+// 1.Test - Correct DomElement.
+void XMLHandlerTests2::testCorrectDomElement()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")), true);
+ }
+ }
+ // Change varint and the belonging Variable in the parsen macro2test
+ // and test it in the macro3 below
+ varint->setVariant(117);
+ d->macroitem2->variable("testint")->setVariant(117);
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")), true);
+ }
+ }
+}
+
+
+// 2.Test - XML-document with bad root element.
+void XMLHandlerTests2::testBadRoot()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<maro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</maro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_XASSERT(d->macro2->parseXML(elem),true);
+}
+
+// 3.Test - XML-document with a missing Variable.
+void XMLHandlerTests2::testMissingVariable()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)3);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")), true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)3);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")), true);
+ }
+ }
+}
+
+// 4.Test - One more Variable in XML-Document.
+void XMLHandlerTests2::testMoreVariables()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "<variable name=\"testbla\" >somethingwrong</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+ KSharedPtr<KoMacro::Variable> varbla = d->macroitem->addVariable("testbla","somethingwrong");
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)5);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla, d->macroitem2->variable("testbla")), true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)5);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla, d->macroitem3->variable("testbla")), true);
+ }
+ }
+}
+
+
+// 5.Test - XML-document with wrong macro-xmlversion.
+void XMLHandlerTests2::testWrongVersion()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<maro xmlversion=\"2\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</maro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_XASSERT(d->macro2->parseXML(elem),true);
+}
+
+
+// 6.Test - XML-document if it has a wrong structure like wrong parathesis
+// or missing end tag.
+void XMLHandlerTests2::testWrongXMLStruct()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "maro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</maro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_XASSERT(d->macro2->parseXML(elem),true);
+}
+
+// 7.Test-XML-document with maximum field-size.
+void XMLHandlerTests2::testMaxNum()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MAX).arg(DBL_MAX);
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(INT_MAX));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(DBL_MAX));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")), true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")),true);
+ }
+ }
+}
+
+// 8.Test-XML-document with maximum+1 field-size.
+void XMLHandlerTests2::testMaxNum2()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MAX+1).arg(DBL_MAX+1);
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(INT_MAX+1));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(DBL_MAX+1));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")),true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")),true);
+ }
+ }
+}
+
+// 9.Test-XML-document with minimum field-size.
+void XMLHandlerTests2::testMinNum()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MIN).arg(DBL_MIN);
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(INT_MIN));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(DBL_MIN));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")),true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")),true);
+ }
+ }
+}
+
+// 10.Test-XML-document with minimum+1 field-size.
+void XMLHandlerTests2::testMinNum2()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" > %1 </variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" > %2 </variable>"
+ "</item>"
+ "</macro>").arg(INT_MIN-1).arg(DBL_MIN-1);
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(INT_MIN-1));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(DBL_MIN-1));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")),true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+// KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")),true);
+ }
+ }
+}
+
+// 11.Test - With a to big number.
+void XMLHandlerTests2::testBigNumber()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0123456789012345678901234567890123456789</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+
+ d->macroitem->setAction(d->testaction);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ //TODO //KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0123456789012345678901234567890123456789));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)1);
+
+ {
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *d->macroitems2.constBegin();
+ d->action2 = d->macroitem2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)4);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")), true);
+ //KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")), true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)1);
+
+ {
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *d->macroitems3.constBegin();
+ d->action3 = d->macroitem3->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)4);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")), true);
+ //KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")), true);
+ }
+ }
+}
+
+// 12.Test - With two MacroItems.
+void XMLHandlerTests2::testTwoMacroItems()
+{
+ // Clear macroitems in the macros.
+ d->macro->clearItems();
+ d->macro2->clearItems();
+ d->macro3->clearItems();
+
+ // Part 1: From XML to a Macro.
+ // Test-XML-document with normal allocated variables.
+ const QString xml = QString("<!DOCTYPE macros>"
+ "<macro xmlversion=\"1\">"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >test_string</variable>"
+ "<variable name=\"testint\" >0</variable>"
+ "<variable name=\"testbool\" >true</variable>"
+ "<variable name=\"testdouble\" >0.6</variable>"
+ "<variable name=\"testbla\" >somethingwrong</variable>"
+ "</item>"
+ "<item action=\"testaction\" >"
+ "<variable name=\"teststring\" >testString2</variable>"
+ "<variable name=\"testint\" >4</variable>"
+ "<variable name=\"testbool\" >false</variable>"
+ "<variable name=\"testdouble\" >0.7</variable>"
+ "<variable name=\"testbla\" >somethingwrong2</variable>"
+ "</item>"
+ "</macro>");
+ // Set the XML-document with the above string.
+ QDomDocument doomdocument;
+ doomdocument.setContent(xml);
+ const QDomElement elem = doomdocument.documentElement();
+
+ // Create a MacroItem with the TestAction for macro2 and add it to macro.
+ d->macroitem = new KoMacro::MacroItem();
+ d->macroitem_2 = new KoMacro::MacroItem();
+ d->macro->addItem(d->macroitem);
+ d->macro->addItem(d->macroitem_2);
+
+ d->macroitem->setAction(d->testaction);
+ d->macroitem_2->setAction(d->testaction_2);
+
+ // Push the Variables into the macroitem.
+ KSharedPtr<KoMacro::Variable> varstring = d->macroitem->addVariable("teststring",QVariant("test_string"));
+ KSharedPtr<KoMacro::Variable> varint = d->macroitem->addVariable("testint",QVariant(0));
+ KSharedPtr<KoMacro::Variable> varbool = d->macroitem->addVariable("testbool",QVariant(true));
+ KSharedPtr<KoMacro::Variable> vardouble = d->macroitem->addVariable("testdouble",QVariant(0.6));
+ KSharedPtr<KoMacro::Variable> varbla = d->macroitem->addVariable("testbla","somethingwrong");
+
+ // Push the Variables into the macroitem4.
+ KSharedPtr<KoMacro::Variable> varstring_2 = d->macroitem_2->addVariable("teststring",QVariant("testString2"));
+ KSharedPtr<KoMacro::Variable> varint_2 = d->macroitem_2->addVariable("testint",QVariant(4));
+ KSharedPtr<KoMacro::Variable> varbool_2 = d->macroitem_2->addVariable("testbool",QVariant(false));
+ KSharedPtr<KoMacro::Variable> vardouble_2 = d->macroitem_2->addVariable("testdouble",QVariant(0.7));
+ KSharedPtr<KoMacro::Variable> varbla_2 = d->macroitem_2->addVariable("testbla","somethingwrong2");
+
+ // Is our XML parseable into a 2. Macro by calling parseXML()?
+ KOMACROTEST_ASSERT(d->macro2->parseXML(elem),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems2 = d->macro2->items();
+ // 1a.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems2.size(),(sizetypelist)2);
+
+ {
+ QValueList<KSharedPtr<KoMacro::MacroItem > >::ConstIterator mit2(d->macroitems2.constBegin());
+ // 2a.comparison - Test if the Action is correct?
+ d->macroitem2 = *mit2;
+ mit2++;
+ d->macroitem2_2 = *mit2;
+ d->action2 = d->macroitem2->action();
+ d->action2_2 = d->macroitem2_2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action2),true);
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction_2,d->action2_2),true);
+
+ // 3a.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem2->variables().size(),(sizetypemap)5);
+ KOMACROTEST_ASSERT(d->macroitem2_2->variables().size(),(sizetypemap)5);
+ {
+ // 4a.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem2->variable("teststring")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem2->variable("testdouble")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla, d->macroitem2->variable("testbla")),true);
+
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring_2,d->macroitem2_2->variable("teststring")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint_2, d->macroitem2_2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool_2, d->macroitem2_2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble_2,d->macroitem2_2->variable("testdouble")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla_2, d->macroitem2_2->variable("testbla")),true);
+ }
+ }
+
+ // Now convert the parsen macro2 back to a QDomElement and again into macro3 for a better comparison.
+ const QDomElement elem2 = d->macro2->toXML();
+ KOMACROTEST_ASSERT(d->macro3->parseXML(elem2),true);
+
+ // Go down to the MacroItem of macro2.
+ d->macroitems3 = d->macro3->items();
+ // 1b.comparison - Test if the MacroItems have the correct number?
+ KOMACROTEST_ASSERT(d->macroitems3.size(),(sizetypelist)2);
+
+ {
+ QValueList<KSharedPtr<KoMacro::MacroItem > >::ConstIterator mit3(d->macroitems3.constBegin());
+ // 2b.comparison - Test if the Action is correct?
+ d->macroitem3 = *mit3;
+ mit3++;
+ d->macroitem3_2 = *mit3;
+ d->action3 = d->macroitem3->action();
+ d->action3_2 = d->macroitem3_2->action();
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3),true);
+ KOMACROTEST_ASSERT(assertActionsEqual(d->testaction,d->action3_2),true);
+
+ // 3b.comparison - Test if the Variables have the correct number?
+ KOMACROTEST_ASSERT(d->macroitem3->variables().size(),(sizetypemap)5);
+ KOMACROTEST_ASSERT(d->macroitem3_2->variables().size(),(sizetypemap)5);
+ {
+ // 4b.comparison - Test if the Variables are equal.
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring, d->macroitem3->variable("teststring")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint, d->macroitem3->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool, d->macroitem3->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble, d->macroitem3->variable("testdouble")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla, d->macroitem3->variable("testbla")),true);
+
+ KOMACROTEST_ASSERT(assertVariablesEqual(varstring_2,d->macroitem3_2->variable("teststring")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varint_2, d->macroitem3_2->variable("testint")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbool_2, d->macroitem3_2->variable("testbool")), true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(vardouble_2,d->macroitem3_2->variable("testdouble")),true);
+ KOMACROTEST_ASSERT(assertVariablesEqual(varbla_2, d->macroitem3_2->variable("testbla")),true);
+ }
+ }
+}
+
+/***************************************************************************
+* End of Sub-methos of testParseAndToXML2().
+***************************************************************************/
+
+bool XMLHandlerTests2::assertActionsEqual(KSharedPtr<KoMacro::Action> action,
+ KSharedPtr<KoMacro::Action> action2)
+{
+ return action->name() == action2->name();
+}
+
+bool XMLHandlerTests2::assertVariablesEqual(KSharedPtr<KoMacro::Variable> var,
+ KSharedPtr<KoMacro::Variable> var2)
+{
+ if ( var->variant() != var2->variant() ) kdDebug() << "Variable1: " << var->variant() << " and Variable2: " << var2->variant() << endl;
+ return var->variant() == var2->variant();
+}
+
+#include "xmlhandlertests2.moc"
diff --git a/kexi/plugins/macros/tests/xmlhandlertests2.h b/kexi/plugins/macros/tests/xmlhandlertests2.h
new file mode 100644
index 00000000..0a3fee3a
--- /dev/null
+++ b/kexi/plugins/macros/tests/xmlhandlertests2.h
@@ -0,0 +1,132 @@
+/***************************************************************************
+ * This file is part of the KDE project
+ * copyright (C) 2006 by Bernd Steindorff (bernd@itii.de)
+ *
+ * This program 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 program 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 program; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ ***************************************************************************/
+
+#ifndef KOMACROTEST_XMLHandlerTests2_H
+#define KOMACROTEST_XMLHandlerTests2_H
+
+#include <kunittest/tester.h>
+#include "../lib/macro.h"
+
+namespace KoMacroTest {
+
+ /**
+ * The common testsuite used to test common @a KoMacro
+ * functionality.
+ */
+ class XMLHandlerTests2 : public KUnitTest::SlotTester
+ {
+ Q_OBJECT
+ public:
+
+ /**
+ * Constructor.
+ */
+ XMLHandlerTests2();
+
+ /**
+ * Destructor.
+ */
+ virtual ~XMLHandlerTests2();
+
+ public slots:
+
+ /**
+ * This slot got called by KUnitTest before testing
+ * starts.
+ */
+ void setUp();
+
+ /**
+ * This slot got called by KUnitTest after all tests
+ * are done.
+ */
+ void tearDown();
+
+ /**
+ * Test the @a KoMacro::XMLHandler parseXML()-function.
+ */
+ void testParseAndToXML();
+
+ private:
+ /// @internal d-pointer class.
+ class Private;
+ /// @internal d-pointer instance.
+ Private* const d;
+
+ typedef QMap<QString,KoMacro::Variable>::size_type sizetypemap;
+ typedef QValueList<KSharedPtr<KoMacro::MacroItem > >::size_type sizetypelist;
+
+ /**
+ * Compares a XML-Element with a Macro. Call sub-asserts.
+ * @p macro The parsen @a Macro.
+ * @p domelement The given @a QDomElement which is parsen.
+ * @p isitemsempty Bool for expectation of an empty @a MacroItem -List.
+ * @p isactionset Bool for expectation that the @a Action -names are equal.
+ * @p isvariableok QMap of Bools for comparing each @a Variable .
+ */
+/* void assertMacroContentEqToXML(const KSharedPtr<KoMacro::Macro> macro,
+ const QDomElement& elem,
+ const bool isitemsempty,
+ const bool isactionset,
+ const QMap<QString, bool> isvariableok);
+
+ // Prints a QMap of Variables to kdDebug().
+ void printMvariables(const QMap<QString, KSharedPtr<KoMacro::Variable > > mvariables, const QString s);
+*/
+ /**
+ * Sub-methods of testParseXML() and testToXML().
+ * Test the correct parsing of a @a QDomElement into a @a Macro
+ * respectively expected failure of parsing. Then transform it
+ * back and compare it.
+ */
+ // 1.Test - Correct DomElement.
+ void testCorrectDomElement();
+ // 2.Test - XML-document with bad root element.
+ void testBadRoot();
+ // 3.Test - XML-document with a missing Variable.
+ void testMissingVariable();
+ // 4.Test - One more Variable in XML-Document.
+ void testMoreVariables();
+ // 5.Test - XML-document with wrong macro-xmlversion.
+ void testWrongVersion();
+ // 6.Test - XML-document if it has a wrong structure like
+ // wrong parathesis or missing end tag.
+ void testWrongXMLStruct();
+ // 7.Test-XML-document with maximum field-size.
+ void testMaxNum();
+ // 8.Test-XML-document with maximum+1 field-size.
+ void testMaxNum2();
+ // 9.Test-XML-document with minimum field-size.
+ void testMinNum();
+ // 10.Test-XML-document with minimum-1 field-size.
+ void testMinNum2();
+ // 11.Test - With a to big number.
+ void testBigNumber();
+ // 12.Test - With two MacroItems.
+ void testTwoMacroItems();
+
+
+ bool assertActionsEqual(KSharedPtr<KoMacro::Action> action,
+ KSharedPtr<KoMacro::Action> action2);
+
+ bool assertVariablesEqual(KSharedPtr<KoMacro::Variable> var,
+ KSharedPtr<KoMacro::Variable> var2);
+ };
+}
+
+#endif