You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
koffice/kexi/plugins/macros/tests/commontests.cpp

908 lines
33 KiB

/***************************************************************************
* 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 <tqstringlist.h>
#include <tqdom.h>
#include <kdebug.h>
#include <tdeunittest/runner.h>
#include <kxmlguiclient.h>
using namespace KUnitTest;
using namespace KoMacroTest;
namespace KoMacroTest {
/**
* Register KoMacroTest::CommonTests as TestSuite.
*/
TDEUNITTEST_SUITE("CommonTestsSuite")
TDEUNITTEST_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 TQObject
* inheritated instances.
*/
TestObject* testobject;
TestAction* testaction;
TQDomDocument* doomdocument;
/**
* Constructor.
*/
Private()
: xmlguiclient(0)
, testobject(0)
, testaction(0)
, doomdocument(0)
{
}
};
}
12 years ago
typedef TQValueList< TDESharedPtr<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 TQDomDocument();
TQString const xml = TQString("<!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*>( (TQObject*)::KoMacro::Manager::self()->object("TestObject") ), d->testobject );
}
/*
void CommonTests::testAction()
{
const TQString testString = "teststring";
const TQString testInt = "testint";
const TQString testBool = "testbool";
//TODO: CLEANUP!!!!!!
//TODO: test manipulation of action and macroitem and context.
kdDebug()<<"===================== testAction() ======================" << endl;
//Publish TestAction for the first time.
TQDomElement const domelement = d->doomdocument->documentElement();
12 years ago
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
//Is our XML parseable ?
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
//??
macro->execute(this);
12 years ago
//create list of TDESharedPtr from the childs of the macro
TQValueList< TDESharedPtr<KoMacro::MacroItem> >& items = macro->items();
//check that there is one
KOMACROTEST_ASSERT( items.count(), sizetype(1) );
//fetch the first one
12 years ago
TDESharedPtr<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
12 years ago
TDESharedPtr<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(),TQString("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(),TQString("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(),TQString("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
12 years ago
//../lib/macroitem.h:131: note: candidates are: TQStringList KoMacro::MacroItem::setVariable(const TQString&, TDESharedPtr<KoMacro::Variable>)
//../lib/macroitem.h:137: note: TQStringList KoMacro::MacroItem::setVariable(const TQString&, const TQVariant&)
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
12 years ago
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
TQDomElement domelement;
// Save old doomdocument
TQString xmlOld = d->doomdocument->toString();
// Part 1: From XML to a Macro.
// Test-XML-document with normal allocated variables.
TQString xml = TQString("<!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 = TQString("<!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 = TQString("<!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 = TQString("<!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 = TQString("<!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 = TQString("<!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 = TQString("<!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 TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create some data
TQString const comment = "Describe what the function does";
TQString const name = "myfunc";
TQString const text = "My Function";
TQString const receiver = "TestObject";
TQString const argument1 = "Some string";
int const argument2 = 12345;
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver + "\" slot=\"myslot(const TQString &amp; , int)\">"
"<argument>" + argument1 + "</argument>"
"<argument>" + TQString("%1").arg(argument2) + "</argument>"
"</function>"
));
12 years ago
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<KoMacro::Action> functionptr = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//cast TDESharedPtr 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( TQString(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( TQString(func->slot()), TQString("myslot(const TQString&,int)") );
//create KoMacro-MetaObject from receiverObject
12 years ago
TDESharedPtr<KoMacro::MetaObject> receivermetaobject = func->receiverObject();
//check that receivermetaobject.data is not null
KOMACROTEST_XASSERT((int) receivermetaobject.data(), 0);
//create KoMacro-MetaMethod from receiverObject
12 years ago
TDESharedPtr<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 TQString, secondrun we have an int
switch(i) {
case 0: { // returnvalue
12 years ago
KOMACROTEST_ASSERT(*it, TDESharedPtr<KoMacro::Variable>(NULL));
} break;
case 1: { // first parameter
//check first variable of func is the same as argument1
//TQString 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
12 years ago
KOMACROTEST_ASSERT( funcvariables[0], TDESharedPtr<KoMacro::Variable>(NULL) );
//create a KoMacro-Variable-Ptr from first func argument
12 years ago
TDESharedPtr<KoMacro::Variable> stringvar = funcvariables[1];
//check that it is not null
KOMACROTEST_XASSERT((int) stringvar.data(),0);
//check via TQVariant 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(), TQVariant::String );
//chech that stringvar equals argument1
KOMACROTEST_ASSERT( stringvar->toString(), argument1 );
//create a KoMacro-Variable-Ptr from second func argument
12 years ago
TDESharedPtr<KoMacro::Variable> intvar = funcvariables[2];
//check that it is not null
KOMACROTEST_XASSERT((int) intvar.data(), 0);
//check via TQVariant 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(), TQVariant::String );
//check that intvar equals argument2
KOMACROTEST_ASSERT( intvar->toInt(), argument2 );
//returnvalue see testobject ....
12 years ago
TDESharedPtr<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(), TQString("54321") );
*/
}
void CommonTests::testIntFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testIntFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString &amp; , int)\">"
"<argument>Some string</argument>"
"<argument>12345</argument>"
"</function>"
));
12 years ago
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<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(),TQString("12345"));
*/
}
void CommonTests::testDoubleFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testDoubleFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString &amp; , double)\">"
"<argument>Some string</argument>"
"<argument>12.56</argument>"
"</function>"
));
12 years ago
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<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(),TQString("12.56"));
*/
}
void CommonTests::testTQStringFunction()
{
//TODO: CLEANUP!!!!!!
/*
kdDebug()<<"===================== testTQStringFunction() ======================" << endl;
//create a TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//set "Function"-content in TQDocument
domdocument.setContent(TQString(
"<function name=\"myfunc\" text=\"My Function\" comment=\"comment\" receiver=\"TestObject\" slot=\"myslot(const TQString &amp;)\">"
"<argument>Some string</argument>"
"</function>"
));
12 years ago
//create an KomacroFunction with our data, and put it into a TDESharedPtr
TDESharedPtr<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(),TQString("Some string"));
*/
}
void CommonTests::testMacro()
{
//TODO: CLEANUP!!!!!!
kdDebug()<<"===================== testMacro() ======================" << endl;
TQDomElement const domelement = d->doomdocument->documentElement();
12 years ago
TDESharedPtr<KoMacro::Macro> macro = KoMacro::Manager::self()->createMacro("testMacro");
//Is our XML parseable ?
KOMACROTEST_ASSERT(macro->parseXML(domelement),true);
// //create a TQDomDocument
// TQDomDocument domdocument = TQDomDocument();
//
// //Fully fleged content this time with macro,function and action
// domdocument.setContent(TQString(
// "<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 TQString &amp;)\">"
// "<argument>The myfunc argument string</argument>"
// "</function>"
// "</macro>"
// ));
//
// //create Macro
12 years ago
// // TDESharedPtr<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( TQString(macro->name()), TQString("testMacro") );
/**
@deprecated values no longer exist
//check the text
KOMACROTEST_ASSERT( macro->text(), TQString("My Macro") );
//check iconname
KOMACROTEST_ASSERT( TQString(macro->icon()), TQString("myicon") );
//check comment
KOMACROTEST_ASSERT( macro->comment(), TQString("Some comment to describe the Macro.") );
*/
//create list of KsharedPtr from the childs of the macro
12 years ago
TQValueList< TDESharedPtr<KoMacro::MacroItem> >& items = macro->items();
//check that there is one
KOMACROTEST_ASSERT( items.count(), sizetype(1) );
//fetch the first one
12 years ago
TDESharedPtr<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( TQString(actionptr->name()), TQString("testaction") );
//check that it has the right text
KOMACROTEST_ASSERT( actionptr->text(), TQString("Test") );
//check that it has the right comment
// KOMACROTEST_ASSERT( actionptr->comment(), TQString("") );
/*
//fetch the second one
12 years ago
TDESharedPtr<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( TQString(myfunc->name()), TQString("myfunc"));
//check it?s text
KOMACROTEST_ASSERT( myfunc->text(), TQString("My Function") );
//check it?s comment
KOMACROTEST_ASSERT( myfunc->comment(), TQString("Describe what the function does") );
//check it?s receiver object
KOMACROTEST_ASSERT( myfunc->receiver(), TQString("TestObject") );
//check it?s slot
KOMACROTEST_ASSERT( myfunc->slot(), TQString("myslot(const TQString&)") );
//exceute it
myfunc->activate();
*/
//create another macro
12 years ago
TDESharedPtr<KoMacro::Macro> yanMacro = KoMacro::Manager::self()->createMacro("testMacro2");
KOMACROTEST_ASSERT(yanMacro->parseXML(domelement),true);
//create two more macros
12 years ago
//TDESharedPtr<KoMacro::Action> yanActionptr2 = ::KoMacro::Manager::self()->createAction( domdocument.documentElement() );
//TDESharedPtr<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
12 years ago
//TQValueList< TDESharedPtr<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 TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create data for various documents
TQString const comment = "Describe what the function does";
TQString const name = "myfunc";
TQString const text = "My Function";
TQString const receiver1 = "TestObject";
TQString const receiver2 = "GibtsNich";
//create wrong Argument tag
domdocument.setContent(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString &amp; , int)\">"
"<Arg0ment>Some string</Arg0ment>"
"<Arg0ment>12345</Arg0ment>"
"</function>"
));
//create functiom
12 years ago
TDESharedPtr<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(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver2 + "\" slot=\"myslot(const TQString &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(TQString(
"<function name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString &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(TQString(
"<NoFunction name=\"" + name + "\" text=\"" + text + "\" comment=\"" + comment + "\" receiver=\"" + receiver1 + "\" slot=\"myslot(const TQString &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(TQString(
"<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(TQString(
"<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 TQDomDocument
TQDomDocument domdocument = TQDomDocument();
//create data
domdocument.setContent(TQString(
"<macro name=\"mymacro123\" text=\"My Macro 123\">"
"<function name=\"func1\" text=\"Function1\" receiver=\"TestObject\" slot=\"myslot(const TQString &amp;)\" >"
"<argument>$MyArgumentVariable</argument>"
"<return>$MyReturnVariable</return>"
"</function>"
"</macro>"
));
//create an macro
12 years ago
TDESharedPtr<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
12 years ago
TQValueList< TDESharedPtr<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
12 years ago
TDESharedPtr<KoMacro::Action> func1ptr = children[1];
//create new context
12 years ago
TDESharedPtr<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 TQString
context->setVariable("$MyArgumentVariable", new KoMacro::Variable("Some string"));
//execute function
func1ptr->activate(context);
//fetch return value
12 years ago
TDESharedPtr<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(),TQString("Some string"));
}
{
//set variable to be an Int
context->setVariable("$MyArgumentVariable", new KoMacro::Variable( 12345 ));
//execute function
func1ptr->activate(context);
//fetch return value
12 years ago
TDESharedPtr<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"