diff options
Diffstat (limited to 'lib/kross/test')
-rw-r--r-- | lib/kross/test/Makefile.am | 17 | ||||
-rw-r--r-- | lib/kross/test/main.cpp | 190 | ||||
-rw-r--r-- | lib/kross/test/testaction.cpp | 49 | ||||
-rw-r--r-- | lib/kross/test/testaction.h | 50 | ||||
-rw-r--r-- | lib/kross/test/testcase.py | 144 | ||||
-rw-r--r-- | lib/kross/test/testcase.rb | 15 | ||||
-rw-r--r-- | lib/kross/test/testgui.py | 149 | ||||
-rw-r--r-- | lib/kross/test/testkexidb.py | 214 | ||||
-rw-r--r-- | lib/kross/test/testobject.cpp | 96 | ||||
-rw-r--r-- | lib/kross/test/testobject.h | 64 | ||||
-rwxr-xr-x | lib/kross/test/testperformance.py | 75 | ||||
-rw-r--r-- | lib/kross/test/testplugin.cpp | 126 | ||||
-rw-r--r-- | lib/kross/test/testplugin.h | 75 | ||||
-rw-r--r-- | lib/kross/test/testscripting.rc | 33 | ||||
-rw-r--r-- | lib/kross/test/testwindow.cpp | 110 | ||||
-rw-r--r-- | lib/kross/test/testwindow.h | 55 |
16 files changed, 1462 insertions, 0 deletions
diff --git a/lib/kross/test/Makefile.am b/lib/kross/test/Makefile.am new file mode 100644 index 000000000..ddf235c37 --- /dev/null +++ b/lib/kross/test/Makefile.am @@ -0,0 +1,17 @@ +include $(top_srcdir)/lib/kross/Makefile.global + +noinst_PROGRAMS = krosstest + +krosstest_SOURCES = testobject.cpp testaction.cpp testplugin.cpp testwindow.cpp main.cpp + +krosstest_LDADD = \ + $(LIB_QT) \ + $(LIB_KDECORE) \ + $(LIB_KDEUI) \ + ../api/libkrossapi.la \ + ../main/libkrossmain.la + +INCLUDES = $(KROSS_INCLUDES) $(all_includes) +krosstest_LDFLAGS = $(all_libraries) $(KDE_RPATH) +SUBDIRS = . +METASOURCES = AUTO diff --git a/lib/kross/test/main.cpp b/lib/kross/test/main.cpp new file mode 100644 index 000000000..31b4f579a --- /dev/null +++ b/lib/kross/test/main.cpp @@ -0,0 +1,190 @@ +/*************************************************************************** + * main.cpp + * This file is part of the KDE project + * copyright (C)2004-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. + ***************************************************************************/ + +#include "../main/manager.h" + +#include "../api/object.h" +#include "../api/class.h" +#include "../api/module.h" +//#include "../api/script.h" +#include "../api/interpreter.h" + +#include "../main/scriptcontainer.h" + +//#include "../kexidb/kexidbmodule.h" + +#include "testobject.h" +#include "testaction.h" +#include "testwindow.h" +#include "testplugin.h" + +// Qt +#include <qstring.h> +#include <qfile.h> + +// KDE +#include <kinstance.h> +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <kaboutdata.h> +#include <ksharedptr.h> + +// for std namespace +#include <string> +#include <iostream> + +KApplication *app = 0; + + + +static KCmdLineOptions options[] = +{ + { "interpreter <interpretername>", I18N_NOOP("Name of the interpreter being used"), "python" }, + { "scriptfile <filename>", I18N_NOOP("Script file to execute with the defined interpreter"), "testcase.py" }, + { "gui", I18N_NOOP("Start the GUI; otherwise the command line application is used."), 0 }, + + //{ "functionname <functioname>", I18N_NOOP("Execute the function in the defined script file."), "" }, + //{ "functionargs <functioarguments>", I18N_NOOP("List of arguments to pass to the function on execution."), "" }, + { 0, 0, 0 } +}; + +void runInterpreter(const QString& interpretername, const QString& scriptcode) +{ + try { + + // Return the scriptingmanager instance. The manager is used as main + // entry point to work with Kross. + Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager(); + + // Add modules that should be accessible by scripting. Those + // modules are wrappers around functionality you want to be + // able to access from within scripts. You don't need to take + // care of freeing them cause that will be done by Kross. + // Modules are shared between the ScriptContainer instances. + manager->addModule( new TestPluginModule("krosstestpluginmodule") ); + + // To represent a script that should be executed Kross uses + // the Script container class. You are able to fill them with + // what is needed and just execute them. + Kross::Api::ScriptContainer::Ptr scriptcontainer = manager->getScriptContainer("MyScriptName"); + + //scriptcontainer->enableModule("KexiDB"); + + scriptcontainer->setInterpreterName(interpretername); + scriptcontainer->setCode(scriptcode); + + //TESTCASE + TestObject* testobject = new TestObject(app, scriptcontainer); + manager->addQObject( testobject ); + + /*TestAction* testaction =*/ new TestAction(scriptcontainer); + //manager->addQObject( testaction ); + + /*Kross::Api::Object* o =*/ scriptcontainer->execute(); + + // Call a function. + //scriptcontainer->callFunction("testobjectCallback" /*, Kross::Api::List* functionarguments */); + + // Call a class. + /* + Kross::Api::Object* testclassinstance = scriptcontainer->classInstance("testClass"); + if(testclassinstance) { + QValueList<Kross::Api::Object*> ll; + Kross::Api::Object* instancecallresult = testclassinstance->call("testClassFunction1", Kross::Api::List::create(ll)); + //krossdebug( QString("testClass.testClassFunction1 returnvalue => '%1'").arg( instancecallresult.toString() ) ); + } + */ + + +/* + // Connect QObject signal with scriptfunction. + scriptcontainer->connect(testobject, SIGNAL(testSignal()), "testobjectCallback"); + scriptcontainer->connect(testobject, SIGNAL(testSignalString(const QString&)), "testobjectCallbackWithParams"); + // Call the testSlot to emit the testSignal. + testobject->testSlot(); +*/ + } + catch(Kross::Api::Exception::Ptr e) { + std::cout << QString("EXCEPTION %1").arg(e->toString()).latin1() << std::endl; + } + +/*TESTCASE + Kross::Api::ScriptContainer* sc2 = manager->getScriptContainer("MyScriptName222"); + sc2->setInterpreterName(interpretername); + sc2->setCode(scriptcode); + try { + sc2->execute(); + } + catch(Kross::Api::Exception& e) { + krossdebug( QString("EXCEPTION type='%1' description='%2'").arg(e.type()).arg(e.description()) ); + } + //delete sc2; +*/ + + std::string s; std::cin >> s; // just wait. +} + +int main(int argc, char **argv) +{ + int result = 0; + + KAboutData about("krosstest", + "KrossTest", + "0.1", + "KDE application to test the Kross framework.", + KAboutData::License_LGPL, + "(C) 2005 Sebastian Sauer", + "Test the Kross framework!", + "http://www.dipe.org/kross", + "kross@dipe.org"); + about.addAuthor("Sebastian Sauer", "Author", "mail@dipe.org"); + + KCmdLineArgs::init(argc, argv, &about); + KCmdLineArgs::addCmdLineOptions(options); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + QString interpretername = args->getOption("interpreter"); + QString scriptfilename = args->getOption("scriptfile"); + + QFile f(QFile::encodeName(scriptfilename)); + if(f.exists() && f.open(IO_ReadOnly)) { + QString scriptcode = f.readAll(); + f.close(); + + if( args->isSet("gui") ) { + app = new KApplication(); + TestWindow *mainWin = new TestWindow(interpretername, scriptcode); + app->setMainWidget(mainWin); + mainWin->show(); + args->clear(); + result = app->exec(); + } + else { + app = new KApplication(true, true); + runInterpreter(interpretername, scriptcode); + } + } + else { + Kross::krosswarning( QString("Failed to load scriptfile: %1").arg(scriptfilename) ); + result = -1; + } + + delete app; + return result; +} diff --git a/lib/kross/test/testaction.cpp b/lib/kross/test/testaction.cpp new file mode 100644 index 000000000..93c32090a --- /dev/null +++ b/lib/kross/test/testaction.cpp @@ -0,0 +1,49 @@ +/*************************************************************************** + * testaction.cpp + * This file is part of the KDE project + * copyright (C)2004-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. + ***************************************************************************/ + +#include "testaction.h" + +TestAction::TestAction(Kross::Api::ScriptContainer::Ptr scriptcontainer) + : QWidget() +{ + m_actioncollection = new KActionCollection(this, this); + + m_action1 = new KAction("Action1_Text", 0, this, SLOT(activatedAction1()), m_actioncollection, "Action1"); + m_actionlist.append(m_action1); + scriptcontainer->addKAction(m_action1); + + m_action2 = new KAction("Action2_Text", 0, this, SLOT(activatedAction2()), m_actioncollection, "Action2"); + m_actionlist.append(m_action2); + scriptcontainer->addKAction(m_action2); +} + +TestAction::~TestAction() +{ +} + +void TestAction::activatedAction1() +{ + Kross::krossdebug("TestAction::activatedAction1()"); +} + +void TestAction::activatedAction2() +{ + Kross::krossdebug("TestAction::activatedAction2()"); +} + diff --git a/lib/kross/test/testaction.h b/lib/kross/test/testaction.h new file mode 100644 index 000000000..03ea95fe6 --- /dev/null +++ b/lib/kross/test/testaction.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * testaction.h + * This file is part of the KDE project + * copyright (C)2004-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 KROSS_TEST_TESTACTION_H +#define KROSS_TEST_TESTACTION_H + +#include "../main/scriptcontainer.h" + +#include <qobject.h> +#include <qwidget.h> +#include <qstring.h> + +#include <kaction.h> +#include <kactioncollection.h> + +class TestAction : public QWidget +{ + Q_OBJECT + public: + TestAction(Kross::Api::ScriptContainer::Ptr scriptcontainer); + ~TestAction(); + + private slots: + void activatedAction1(); + void activatedAction2(); + + private: + KAction* m_action1; + KAction* m_action2; + KActionCollection* m_actioncollection; + KActionPtrList m_actionlist; +}; + +#endif diff --git a/lib/kross/test/testcase.py b/lib/kross/test/testcase.py new file mode 100644 index 000000000..d3f2ea7b0 --- /dev/null +++ b/lib/kross/test/testcase.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python + +""" + This Python script is used to test the Kross scripting framework. +""" + +#def testobjectCallback(): +# print "function testobjectCallback() called !" +# return "this is the __main__.testobjectCallback() returnvalue!" +#def testobjectCallbackWithParams(argument): +# print "testobjectCallbackWithParams() argument = %s" % str(argument) +# return "this is the __main__.testobjectCallbackWithParams() returnvalue!" +#def testQtObject(self): + ## Get the QtObject instance to access the QObject. + ##testobject = get("TestObject") + #testobject = self.get("TestObject") + #if testobject == None: raise "Object 'TestObject' undefined !!!" + #print "testobject = %s %s" % (str(testobject),dir(testobject)) + ##print "propertyNames = %s" % testobject.propertyNames() + ##print "slotNames = %s" % testobject.slotNames() + ##print "signalNames = %s" % testobject.signalNames() + ## We could just call a slot or a signal. + #print testobject.call("testSlot2()"); + #print testobject.call("testSignal()"); + ##print testobject.call() #KrossTest: List::item index=0 is out of bounds. Raising TypeException. + ## Each slot a QObject spends is a object itself. + #myslot = testobject.get("testSlot()") + #print "myslotevent = %s" % str(myslot) + #print myslot.call() + #print "__name__ = %s" % __name__ + #print "__dir__ = %s" % dir() + ##print "__builtin__ = %s" % __builtin__ + #print "self = %s %s" % (str(self),dir(self)) + ##print "TestCase = %s" % str(TestCase) + #print "self.list = %s" % self.list() + #print "self.dict = %s" % self.dict() + #testobject = self.get("TestObject") + #print "testobject = %s" % testobject + #if not testobject.connect("testSignal()",testobject,"testSlot2()"): + #raise "Failed to connect testSignal() with testSlot2() at object 'TestObject'." + #testobject.signal("testSignal()") + ##testobject.testSlot() + #testobject.slot("testSlot()") + #testobject.disconnect("testSignal()") +#def testActionEvent(self): + ##action1 = get("Action1") + #action1 = self.get("Action1") + #if action1 == None: + #raise "Object 'Action1' undefined !!!" + #print "action1 = %s %s" % (str(action1),dir(action1)) + ##action1.call() + #action1.activate() + +import unittest + +class TestPlugin(unittest.TestCase): + """ Testcase to test the Kross python functionality for regressions. """ + + def setUp(self): + import krosstestpluginmodule + self.pluginobject1 = krosstestpluginmodule.testpluginobject1() + self.assert_( self.pluginobject1 ) + + self.pluginobject2 = krosstestpluginmodule.testpluginobject2() + self.assert_( self.pluginobject2 ) + + self.testqobject1 = krosstestpluginmodule.testqobject1() + self.assert_( self.testqobject1 ) + + def testBasicDataTypes(self): + self.assert_( self.pluginobject1.uintfunc(177321) == 177321 ) + self.assert_( self.pluginobject1.intfunc(93675) == 93675 ) + self.assert_( self.pluginobject1.intfunc(-73673) == -73673 ) + self.assert_( self.pluginobject1.boolfunc(True) == True ) + self.assert_( self.pluginobject1.boolfunc(False) == False ) + self.assert_( self.pluginobject1.doublefunc(4265.3723) == 4265.3723 ) + self.assert_( self.pluginobject1.doublefunc(-4265.68) == -4265.68 ) + self.assert_( self.pluginobject1.cstringfunc(" This is a Test! ") == " This is a Test! " ) + self.assert_( self.pluginobject1.stringfunc(" Another \n\r Test! $%&\"") == " Another \n\r Test! $%&\"" ) + + #TODO + #self.assert_( self.pluginobject1.stringfunc( unicode(" Unicode test ") ) == " Unicode test " ) + #self.assert_( self.pluginobject1.stringfunc(unicode(" Another Test! ")) == unicode(" Another Test! ") ) + + self.assert_( self.pluginobject1.stringstringfunc("MyString1", "MyString2") == "MyString1" ) + self.assert_( self.pluginobject1.uintdoublestringfunc(8529,285.246,"String") == 8529 ) + self.assert_( self.pluginobject1.stringlistbooluintdouble(["s1","s2"],True,6,7.0,"String") == ["s1","s2"] ) + + def testStringList(self): + self.assert_( self.pluginobject1.stringlistfunc( [] ) == [] ) + self.assert_( self.pluginobject1.stringlistfunc( ["First Item"," Second Item "] ) == ["First Item"," Second Item "] ) + self.assert_( self.pluginobject1.stringlistfunc( ("Theird Item"," Forth Item ","Fifth Item") ) == ["Theird Item"," Forth Item ","Fifth Item"] ) + + def testVariant(self): + self.assert_( self.pluginobject1.variantfunc(True) == True ) + self.assert_( self.pluginobject1.variantfunc(False) == False ) + self.assert_( self.pluginobject1.variantfunc(187937) == 187937 ) + self.assert_( self.pluginobject1.variantfunc(-69825) == -69825 ) + self.assert_( self.pluginobject1.variantfunc(8632.274) == 8632.274 ) + self.assert_( self.pluginobject1.variantfunc(-8632.351) == -8632.351 ) + self.assert_( self.pluginobject1.variantfunc(" Test \n\r This String $%&\"") == " Test \n\r This String $%&\"") + + def testObjects(self): + print "-----------------1" + newobjref = self.pluginobject1.objectfunc(self.pluginobject2) + print "-----------------2" + print str(newobjref) + + #self.assert_( newobjref.myuniqueid == self.pluginobject2.myuniqueid ) + #print "===========> %s" % self.pluginobject2.myName() + + print "testqobject1 properties=%s" % self.testqobject1.propertyNames() + print "testqobject1 slots=%s" % self.testqobject1.slotNames() + print "testqobject1 signals=%s" % self.testqobject1.signalNames() + print "-----------------3" + print "DIR=>%s" % dir(self.testqobject1) + + print "===================> slotcall-result: %s" % self.testqobject1.slot("self()") + + #testobject = newobjref.get("TestObject") + #print testobject + print "-----------------9" + + def testDefaultArguments(self): + self.assert_( self.pluginobject1.uintfunc_defarg(98765) == 98765 ) + self.assert_( self.pluginobject1.uintfunc_defarg() == 12345 ) + self.assert_( self.pluginobject1.stringfunc_defarg("MyString") == "MyString" ) + self.assert_( self.pluginobject1.stringfunc_defarg() == "MyDefaultString" ) + self.assert_( self.pluginobject1.stringlistfunc_defarg(["s1","s2","s3"]) == ["s1","s2","s3"] ) + self.assert_( self.pluginobject1.stringlistfunc_defarg() == ["Default1","Default2"] ) + self.assert_( self.pluginobject1.variantfunc_defarg(822.75173) == 822.75173 ) + self.assert_( self.pluginobject1.variantfunc_defarg() == "MyDefaultVariantString" ) + + #def testExpectedFailures(self): + # to less arguments + #self.assertRaises(ValueError, self.pluginobject1.uintfunc) + #self.assert_( self.pluginobject1.uintfunc() != 8465 ) + +print "__name__ = %s" % __name__ +#print "self = %s" % self +#print self.get("TestObject") + +suite = unittest.makeSuite(TestPlugin) +unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/lib/kross/test/testcase.rb b/lib/kross/test/testcase.rb new file mode 100644 index 000000000..71354ea2e --- /dev/null +++ b/lib/kross/test/testcase.rb @@ -0,0 +1,15 @@ +require 'test/unit' + +class TestKross < Test::Unit::TestCase + def setup: + require "krosstestpluginmodule" + testpluginobject1 = Krosstestpluginmodule::get("testpluginobject1") + #Krosskritacore::get("KritaDocument") + #testpluginobject1.func1() + #def test_primitive + # print "---------------- 1\n" + + end +end + +print "3----------------\n" diff --git a/lib/kross/test/testgui.py b/lib/kross/test/testgui.py new file mode 100644 index 000000000..f252184d1 --- /dev/null +++ b/lib/kross/test/testgui.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python + +""" + This Python script demonstrates the usage of the Kross + python-interface to access KexiDB functionality from + within Python. +""" + +class TkTest: + def __init__(self): + import Tkinter + self.root = Tkinter.Tk() + self.root.title("TkTest") + self.root.deiconify() + + self.mainframe = Tkinter.Frame(self.root) + self.mainframe.pack() + + self.button1 = Tkinter.Button(self.mainframe, text="Button1", command=self.callback1) + self.button1.pack(side=Tkinter.LEFT) + + self.button2 = Tkinter.Button(self.mainframe, text="Button2", command=self.callback2) + self.button2.pack(side=Tkinter.LEFT) + + self.exitbutton = Tkinter.Button(self.mainframe, text="Exit", command=self.root.destroy) + self.exitbutton.pack(side=Tkinter.LEFT) + + self.root.mainloop() + + def callback1(self): + import tkMessageBox + tkMessageBox.showinfo("Callback1", "Callback1 called.") + + def callback2(self): + import tkMessageBox + tkMessageBox.showinfo("Callback2", "Callback2 called.") + +class QtTest: + def __init__(self): + import qt + + class Button(qt.QPushButton): + def __init__(self, *args): + apply(qt.QPushButton.__init__, (self,) + args) + + class ComboBox(qt.QHBox): + def __init__(self, parent, caption, items = []): + qt.QHBox.__init__(self, parent) + self.setSpacing(6) + label = qt.QLabel(str(caption), self) + self.combobox = qt.QComboBox(self) + self.setStretchFactor(self.combobox, 1) + label.setBuddy(self.combobox) + for item in items: + self.combobox.insertItem( str(item) ) + + class FileChooser(qt.QHBox): + def __init__(self, *args): + apply(qt.QHBox.__init__, (self,) + args) + self.defaultfilename = "~/output.html" + + self.setSpacing(6) + label = qt.QLabel("File:", self) + self.edit = qt.QLineEdit(self) + self.edit.setText(self.defaultfilename) + self.setStretchFactor(self.edit, 1) + label.setBuddy(self.edit) + + browsebutton = Button("...", self) + qt.QObject.connect(browsebutton, qt.SIGNAL("clicked()"), self.browseButtonClicked) + + def file(self): + return self.edit.text() + + def browseButtonClicked(self): + filename = None + try: + # try to use the kfile module included in pykde + import kfile + filename = kfile.KFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file") + except: + # fallback to Qt filedialog + filename = qt.QFileDialog.getOpenFileName(self.defaultfilename, "*.html", self, "Save to file") + if filename != None and filename != "": + self.edit.setText(filename) + + class Dialog(qt.QDialog): + def __init__(self, parent = None, name = None, modal = 0, fl = 0): + qt.QDialog.__init__(self, parent, name, modal, fl) + qt.QDialog.accept = self.accept + self.setCaption("Export to HTML") + #self.layout() + + self.layout = qt.QVBoxLayout(self) + self.layout.setSpacing(6) + self.layout.setMargin(11) + + infolabel = qt.QLabel("Export the data of a table or a query to a HTML-file.", self) + self.layout.addWidget(infolabel) + + source = ComboBox(self, "Datasource:") + self.layout.addWidget(source) + + self.exporttype = ComboBox(self, "Style:", ["Plain","Paper","Desert","Blues"]) + self.layout.addWidget(self.exporttype) + + self.filechooser = FileChooser(self) + self.layout.addWidget(self.filechooser) + + buttonbox = qt.QHBox(self) + buttonbox.setSpacing(6) + self.layout.addWidget(buttonbox) + + savebutton = Button("Save", buttonbox) + qt.QObject.connect(savebutton, qt.SIGNAL("clicked()"), self, qt.SLOT("accept()")) + #qt.QObject.connect(savebutton, qt.SIGNAL("clicked()"), self.exportButtonClicked) + + cancelbutton = Button("Cancel", buttonbox) + qt.QObject.connect(cancelbutton, qt.SIGNAL("clicked()"), self, qt.SLOT("close()")) + + def accept(self): + print "ACCEPTTTTTTTT !!!!!!!!!!!!!!!!!!!!!!!!!!!!" + + file = qt.QFile( self.filechooser.file() ) + #if not file.exists(): + # print "File '%s' does not exist." % self.filechooser.file() + #else: + # print "File '%s' does exist." % self.filechooser.file() + + def exportButtonClicked(self): + print "Export to HTML !!!!!!!!!!!!!!!!!!!!!!!!!!!!" + + def __getattr__(self, attr): + print "=> Dialog.__getattr__(self,attr)" + #def closeEvent(self, ev): pass + def event(self, e): + print "=> Dialog.event %s" % e + #self.deleteLater() + #support.swapThreadState() # calls appropriate c-function + return qt.QDialog.event(self, e) + + app = qt.qApp + dialog = Dialog(app.mainWidget(), "Dialog", 1) + dialog.show() + +print "################## BEGIN" +#TkTest() +QtTest() +print "################## END" diff --git a/lib/kross/test/testkexidb.py b/lib/kross/test/testkexidb.py new file mode 100644 index 000000000..048b7e19a --- /dev/null +++ b/lib/kross/test/testkexidb.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python + +""" + This Python script demonstrates the usage of the Kross + python-interface to access KexiDB functionality from + within Python. +""" + +# Class to test the KexiDB functionality. +class KexiDBClass: + + # Constructor. + def __init__(self): + # The KexiDB module spends us access to the KexiDB functionality. + #import KexiDB + import krosskexidb + self.kexidbmodule = krosskexidb + print "KrossKexiDB version=%s" % self.kexidbmodule.version() + + # Create and remember the drivermanager. + self.drivermanager = self.kexidbmodule.DriverManager() + + # Print informations about the KexiDB module. + def printKexiDB(self): + print "KexiDB = %s %s" % (str(self.kexidbmodule),dir(self.kexidbmodule)) + # Each object has __name__ and __doc__ + #print "KexiDB.__name__ = %s" % self.kexidbmodule.__name__ + #print "KexiDB.__doc__ = %s" % self.kexidbmodule.__doc__ + # Print some infos about the drivermanager. + print "drivermanager = %s %s" % (self.drivermanager,dir(self.drivermanager)) + # The drivermanager holds a list of drivers he supports. + print "drivermanager.driverNames() = %s" % self.driverNames() + + # Print informations about a driver. + def printDriverManger(self, driver): + print "driver = %s %s" % (driver,dir(driver)) + # Each driver has a version to be able to determinate with what release we are working. + print "driver.versionMajor() = %s" % driver.versionMajor() + print "driver.versionMinor() = %s" % driver.versionMinor() + # Show us what connections are opened right now. + print "driver.connectionsList() = %s" % str(driver.connectionsList()) + + # Print informations about a connection. + def printConnection(self, connection): + print "connection = %s %s" % (str(connection),dir(connection)) + # Print a list of all avaible databasenames this connection has. + print "connection.databaseNames() = %s" % connection.databaseNames() + + # Return a list of drivernames. + def driverNames(self): + return self.drivermanager.driverNames() + + # Return the to drivername matching KexiDBDriver object. + def driver(self, drivername): + return self.drivermanager.driver(drivername) + + # Return a new KexiDBConnectionData object. + def getConnectionData(self): + return self.drivermanager.createConnectionData() + + # Open a connection to a filebased driver. + def connectWithFile(self, driver, filename): + # First we need a new connectiondata object. + connectiondata = self.getConnectionData() + # Fill the new connectiondata object with what we need to connect. + connectiondata.setCaption("myFileConnection") + connectiondata.setFileName(filename) + print "connectiondata.serverInfoString = %s" % connectiondata.serverInfoString() + # Create the connection now. + connection = driver.createConnection(connectiondata) + # Establish the connection. + if not connection.connect(): + raise("ERROR in connectWithDatabase(): Failed to connect!") + # Open database for usage. The filebased driver uses the filename as databasename. + self.useDatabase(connection, filename) + return connection + + # Open database for usage. + def useDatabase(self, connection, dbname): + if not connection.useDatabase(dbname): + raise("ERROR in connectWithDatabase(): Failed to use database!") + + # Create a new database. + def createDatabase(self, connection, dbname): + #print "createDatabase dbname='%s' dbnames='%s'" % (dbname,connection.databaseNames()) + connection.createDatabase(dbname) + #print "createDatabase databaseExists(%s) = %s" % (dbname,connection.databaseExists(dbname)) + #print "createDatabase dbname='%s' dbnames='%s'" % (dbname,connection.databaseNames()) + + # Drop an existing database. + def dropDatabase(self, connection, dbname): + #print "dropDatabase dbname='%s' dbnames='%s'" % (dbname,connection.databaseNames()) + myfileconnection.dropDatabase(dbname) + #print "dropDatabase databaseExists(%s) = %s" % (dbname,connection.databaseExists(dbname)) + #print "dropDatabase dbname='%s' dbnames='%s'" % (dbname,connection.databaseNames()) + + # Test KexiDBParser used to parse SQL-statements. + def testParser(self, connection, sqlstatement): + parser = connection.parser() + if not parser: + raise "ERROR in testParser(): Failed to create parser!" + print "parser.parse = %s" % parser.parse(sqlstatement) + print "parser.statement = %s" % parser.statement() + print "parser.operation = %s" % parser.operation() + print "parser.table = %s" % parser.table() + print "parser.query = %s" % parser.query() + print "parser.connection = %s" % parser.connection() + + # Execute the sql query statement and print the single string result. + def printQuerySingleString(self, connection, sqlstatement): + query = myfileconnection.querySingleString("SELECT * FROM table1", 0) + print "querySingleString = %s" % query + + # Execute the sql query statement and print the single stringlist result. + def printQueryStringList(self, connection, sqlstatement): + query = myfileconnection.queryStringList("SELECT * FROM table1", 0) + print "queryStringList = %s" % query + + # Walk through the KexiDBCursor and print all item values. + def printQueryCursor(self, cursor): + if cursor == None: + raise("ERROR: executeQuery failed!") + #print "printCursor() cursor = %s %s" % (str(cursor), dir(cursor)) + + # Go to the first item of the table. + if not cursor.moveFirst(): + raise("ERROR in printCursor(): cursor.moveFirst() returned False!") + + # Walk through all items in the table. + while(not cursor.eof()): + # Print for each item some infos about the fields and there content. + for i in range( cursor.fieldCount() ): + print "Item='%s' Field='%s' Value='%s'" % (cursor.at(), i, cursor.value(i)) + # Move to the next item + cursor.moveNext() + + # Similar to printQueryCursor + def printQuerySchema(self, connection, queryschema): + return self.printQueryCursor(connection.executeQuerySchema(queryschema)) + + # Similar to printQueryCursor + def printQueryString(self, connection, sqlstring): + return self.printQueryCursor(connection.executeQueryString(sqlstring)) + + # Add a field to the tableschema. + def addField(self, tableschema, name): + field = self.drivermanager.field() + field.setType("Text") + field.setName(name) + tableschema.fieldlist().addField(field) + print "tableschema.fieldlist().fieldCount() = %s" % tableschema.fieldlist().fieldCount() + return field + + # Create a table. + def createTable(self, connection, tablename): + # First we need a new tableschema. + tableschema = self.drivermanager.tableSchema(tablename) + self.addField(tableschema, "myfield") + print "connection.createTable = %s" % connection.createTable(tableschema, True) + return tableschema + + # Drop a table. + def dropTable(self, connection, tablename): + connection.dropTable(tablename) + + # Alter the name of a table. + def alterTableName(self, connection, tablename, newtablename): + tableschema = connection.tableSchema(tablename) + print "alterTableName from=%s to=%s tableschema=%s" % (tablename, newtablename, tableschema) + connection.alterTableName(tableschema, newtablename) + +def testKexiDB(): + global KexiDBClass + mykexidbclass = KexiDBClass() + mykexidbclass.printKexiDB() + + mydriver = mykexidbclass.driver("SQLite3") + mykexidbclass.printDriverManger(mydriver) + + myfileconnection = mykexidbclass.connectWithFile(mydriver, "/home/snoopy/test.kexi") + mykexidbclass.printConnection(myfileconnection) + #mykexidbclass.testParser(myfileconnection, "SELECT * from table1") + + #mykexidbclass.printQuerySingleString(myfileconnection, "SELECT * FROM dept") + #mykexidbclass.printQueryStringList(myfileconnection, "SELECT * FROM dept") + mykexidbclass.printQueryString(myfileconnection, "SELECT * FROM dept") + + #myqueryschema = mykexidbclass.drivermanager.querySchema() + #myqueryschema.setName("myqueryname") + #myqueryschema.setCaption("myquerycaption") + #myqueryschema.setStatement("SELECT * FROM table2") + #print "myqueryschema = %s" % myqueryschema.statement() + #mykexidbclass.printQuerySchema(myfileconnection, myqueryschema) + + #mykexidbclass.createTable(myfileconnection, "mytable123") + #mykexidbclass.dropTable(myfileconnection, "mytable123") + #mykexidbclass.alterTableName(myfileconnection, "table1", "table111") + + #TODO: new table isn't usuable!!! + #ts1 = myfileconnection.tableSchema("table2") + #ts2 = mykexidbclass.drivermanager.tableSchema("table4") + #mykexidbclass.addField(ts2, "MyField 111111111") + #print "myfileconnection.alterTable = %s" % myfileconnection.alterTable(ts1, ts2) + #TEST + #bool Connection::insertRecord(TableSchema &tableSchema, QValueList<QVariant>& values) + #myfileconnection.insertRecord(KexiDBField, ("field1", "field2")) + #del(mycursor) + #del(myfileconnection) + #del(mydriver) + #del(mykexidbclass) + +print "########## BEGIN TEST: KexiDB ##########" +testKexiDB() +print "########## END TEST: KexiDB ##########" diff --git a/lib/kross/test/testobject.cpp b/lib/kross/test/testobject.cpp new file mode 100644 index 000000000..893cccca6 --- /dev/null +++ b/lib/kross/test/testobject.cpp @@ -0,0 +1,96 @@ +/*************************************************************************** + * testobject.cpp + * This file is part of the KDE project + * copyright (C)2004-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. + ***************************************************************************/ + +#include "testobject.h" + +#include <iostream> // for std::out + +TestObject::TestObject() + : QObject(0, "TestObject") +{ +} + +TestObject::TestObject(QObject* parent, Kross::Api::ScriptContainer::Ptr scriptcontainer) + : QObject(parent, "TestObject") +{ + connect(this, SIGNAL(testSignal()), this, SLOT(testSignalSlot())); + connect(this, SIGNAL(stdoutSignal(const QString&)), this, SLOT(stdoutSlot(const QString&))); + connect(this, SIGNAL(stderrSignal(const QString&)), this, SLOT(stderrSlot(const QString&))); + + scriptcontainer->addQObject(this); + +//scriptcontainer->addSignal("stdout", this, SIGNAL(stdoutSignal(const QString&))); +//scriptcontainer->addSlot("stderr", this, SLOT(stderrSlot(const QString&))); + + //scriptcontainer->addSignal("myTestSignal", this, SIGNAL(testSignal())); + //scriptcontainer->addSlot("myTestSlot", this, SLOT(testSlot())); +} + +TestObject::~TestObject() +{ +} + +uint TestObject::func1(uint i) +{ + Kross::krossdebug(QString("CALLED => TestObject::func1 i=%1").arg(i) ); + return i; +} + +void TestObject::func2(QString s, int i) +{ + Kross::krossdebug(QString("CALLED => TestObject::func2 s=%1 i=%2").arg(s).arg(i)); +} + +QString TestObject::func3(QString s, int i) +{ + Kross::krossdebug(QString("CALLED => TestObject::func3 s=%1 i=%2").arg(s).arg(i)); + return s; +} + +const QString& TestObject::func4(const QString& s, int i) const +{ + Kross::krossdebug(QString("CALLED => TestObject::func4 s=%1 i=%2").arg(s).arg(i)); + return s; +} + +void TestObject::testSlot() +{ + Kross::krossdebug("TestObject::testSlot called"); + emit testSignal(); + emit testSignalString("This is the emitted TestObject::testSignalString(const QString&)"); +} + +void TestObject::testSlot2() +{ + Kross::krossdebug("TestObject::testSlot2 called"); +} + +void TestObject::stdoutSlot(const QString& s) +{ + Kross::krossdebug(QString("stdout: %1").arg(s)); + //std::cout << "<stdout> " << s.latin1() << std::endl; +} + +void TestObject::stderrSlot(const QString& s) +{ + Kross::krossdebug(QString("stderr: %1").arg(s)); + //std::cout << "<stderr> " << s.latin1() << std::endl; +} + +//#include "testobject.moc" diff --git a/lib/kross/test/testobject.h b/lib/kross/test/testobject.h new file mode 100644 index 000000000..011b7e545 --- /dev/null +++ b/lib/kross/test/testobject.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * testobject.h + * This file is part of the KDE project + * copyright (C)2004-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 KROSS_TEST_TESTOBJECT_H +#define KROSS_TEST_TESTOBJECT_H + +#include "../main/scriptcontainer.h" + +#include <qobject.h> +#include <qstring.h> + +class TestObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString testProperty READ testProperty WRITE setTestProperty) + + public: + TestObject(); + TestObject(QObject* parent, Kross::Api::ScriptContainer::Ptr scriptcontainer); + ~TestObject(); + + uint func1(uint); + void func2(QString, int); + QString func3(QString, int); + const QString& func4(const QString&, int) const; + + QString testProperty() const { return m_prop; } + void setTestProperty(QString prop) { m_prop = prop; } + + signals: + void testSignal(); + void testSignalString(const QString&); + void stdoutSignal(const QString&); + void stderrSignal(const QString&); + public slots: + void testSlot(); + void testSlot2(); + void stdoutSlot(const QString&); + void stderrSlot(const QString&); + + QObject* self() { return this; } + + private: + QString m_prop; +}; + +#endif diff --git a/lib/kross/test/testperformance.py b/lib/kross/test/testperformance.py new file mode 100755 index 000000000..a76453ed8 --- /dev/null +++ b/lib/kross/test/testperformance.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python + +""" + This Python script is used as performance-tester and profiler + for the Kross scripting framework. +""" + +def runner(): + import krosstestpluginmodule + testobject1 = krosstestpluginmodule.testpluginobject1() + + def testKexiDB(kexidbfile,drivername,sqlstring): + print "test kexidb" + import krosskexidb + drivermanager = krosskexidb.DriverManager() + connectiondata = drivermanager.createConnectionData() + connectiondata.setFileName(kexidbfile) + driver = drivermanager.driver(drivername) + connection = driver.createConnection(connectiondata) + if not connection.connect(): raise "Connect failed" + if not connection.useDatabase(kexidbfile): raise "Use database failed" + for i in range(20000): + cursor = connection.executeQueryString(sqlstring) + if not cursor: raise "Failed to create cursor" + cursor.moveFirst() + while(not cursor.eof()): + for i in range( cursor.fieldCount() ): + (item,field,value) = (cursor.at(), i, cursor.value(i)) + cursor.moveNext() + + def test1(): + print "test1" + for i in range(100000): + testobject1.func1() + testobject1.func1() + testobject1.func1() + + testobject1.func2("f2s1","f2s2") + testobject1.func2("f2s3","f2s4") + testobject1.func2("f2s5","f2s6") + + testobject1.func3("f3s1","f3s2") + testobject1.func3("f3s3","f3s4") + testobject1.func3("f3s5","f3s6") + + testobject1.func4("f4s1","f4s2") + testobject1.func4("f4s3","f4s4") + testobject1.func4("f4s5","f4s6") + + testobject1.func5("f5s1","f5s2") + testobject1.func5("f5s3","f5s4") + testobject1.func5("f5s5","f5s6") + + testobject1.func6( ("One1","Two2"), "haha" ) + testobject1.func6( ("One3","Two4"), 123456789 ) + testobject1.func6( ("One5","Two6"), 12345.67890 ) + + testobject1.func7("f5s1",123) + testobject1.func7("f5s3",456) + testobject1.func7("f5s5",789) + + testobject1.func8(123,456) + testobject1.func8(12,34) + testobject1.func8(1,2) + + testobject1.func9(2.0,1.0) + testobject1.func9(4.0,3.0) + testobject1.func9(6.0,5.0) + + #test1() + testKexiDB("/home/snoopy/test.kexi", "SQLite3", "SELECT * FROM dept") + +import profile +__main__.runner=runner +profile.run("runner()") diff --git a/lib/kross/test/testplugin.cpp b/lib/kross/test/testplugin.cpp new file mode 100644 index 000000000..07fffc6a3 --- /dev/null +++ b/lib/kross/test/testplugin.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + * testplugin.cpp + * 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. + ***************************************************************************/ + +#include "testplugin.h" +#include "testobject.h" + +/************************************************************************ + * TestPluginObject + */ + +TestPluginObject::TestPluginObject(const QString& name) + : Kross::Api::Class<TestPluginObject>(name) +{ + // Functions to test the basic datatypes + this->addFunction1< void, Kross::Api::Variant > + ("voiduintfunc", this, &TestPluginObject::voiduintfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("uintfunc", this, &TestPluginObject::uintfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("intfunc", this, &TestPluginObject::intfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("boolfunc", this, &TestPluginObject::boolfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("doublefunc", this, &TestPluginObject::doublefunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("cstringfunc", this, &TestPluginObject::cstringfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("stringfunc", this, &TestPluginObject::stringfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("stringlistfunc", this, &TestPluginObject::stringlistfunc); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("variantfunc", this, &TestPluginObject::variantfunc); + + // With 2 arguments + this->addFunction2< Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant > + ("stringstringfunc", this, &TestPluginObject::stringstringfunc); + // With 3 arguments + this->addFunction3< Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant > + ("uintdoublestringfunc", this, &TestPluginObject::uintdoublestringfunc); + // With 4 arguments + this->addFunction4< Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant, Kross::Api::Variant > + ("stringlistbooluintdouble", this, &TestPluginObject::stringlistbooluintdouble); + + // With default arguments + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("uintfunc_defarg", this, &TestPluginObject::uintfunc, new Kross::Api::Variant(12345) ); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("stringfunc_defarg", this, &TestPluginObject::stringfunc, new Kross::Api::Variant("MyDefaultString") ); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("stringlistfunc_defarg", this, &TestPluginObject::stringlistfunc, new Kross::Api::Variant(QVariant(QStringList() << "Default1" << "Default2"))); + this->addFunction1< Kross::Api::Variant, Kross::Api::Variant > + ("variantfunc_defarg", this, &TestPluginObject::variantfunc, new Kross::Api::Variant("MyDefaultVariantString") ); + + // Test passing of objects + this->addFunction1<TestPluginObject, TestPluginObject>("objectfunc", this, &TestPluginObject::objectfunc, 0); +} + +TestPluginObject::~TestPluginObject() +{ +} + +const QString TestPluginObject::getClassName() const +{ + return "TestPluginObject"; +} + +uint TestPluginObject::uintfunc(uint i) { return i; } +void TestPluginObject::voiduintfunc(uint) {} +int TestPluginObject::intfunc(int i) { return i; } +bool TestPluginObject::boolfunc(bool b) { return b; } +double TestPluginObject::doublefunc(double d) { return d; } +QCString TestPluginObject::cstringfunc(const QCString& s) { return s; } +QString TestPluginObject::stringfunc(const QString& s) { return s; } +QStringList TestPluginObject::stringlistfunc(const QStringList& sl) { return sl; } +QVariant TestPluginObject::variantfunc(const QVariant& v) { return v; } +TestPluginObject* TestPluginObject::objectfunc(TestPluginObject* obj) { return obj; } +QString TestPluginObject::stringstringfunc(const QString& s, const QString&) { return s; } +uint TestPluginObject::uintdoublestringfunc(uint i, double, const QString&) { return i; } +QStringList TestPluginObject::stringlistbooluintdouble(const QStringList& sl, bool, uint, double) { return sl; } + +/************************************************************************ + * TestPluginModule + */ + +TestPluginModule::TestPluginModule(const QString& name) + : Kross::Api::Module(name) + , m_testobject( new TestObject() ) + +{ + addChild( new TestPluginObject("testpluginobject1") ); + + // Let's wrap a whole instance and it's methodfunctions. + Kross::Api::Event<TestObject> *testobjectclass = + new Kross::Api::Event<TestObject>("testpluginobject2"); + addChild(testobjectclass); + + // Wrap a whole QObject + addChild( new Kross::Api::QtObject( new TestObject() , "testqobject1" ) ); +} + +TestPluginModule::~TestPluginModule() +{ + delete m_testobject; +} + +const QString TestPluginModule::getClassName() const +{ + return "TestPluginModule"; +} + diff --git a/lib/kross/test/testplugin.h b/lib/kross/test/testplugin.h new file mode 100644 index 000000000..5253becfa --- /dev/null +++ b/lib/kross/test/testplugin.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * testplugin.h + * 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 KROSS_TEST_TESTPLUGIN_H +#define KROSS_TEST_TESTPLUGIN_H + +#include "../api/object.h" +#include "../api/list.h" +#include "../api/class.h" +#include "../api/proxy.h" +#include "../api/module.h" +#include "../api/qtobject.h" + +#include <qobject.h> +#include <qstring.h> + +class TestPluginObject : public Kross::Api::Class<TestPluginObject> +{ + public: + TestPluginObject(const QString& name); + virtual ~TestPluginObject(); + virtual const QString getClassName() const; + + private: + uint uintfunc(uint); + void voiduintfunc(uint); + int intfunc(int); + bool boolfunc(bool); + double doublefunc(double); + QCString cstringfunc(const QCString&); + QString stringfunc(const QString&); + QStringList stringlistfunc(const QStringList&); + QVariant variantfunc(const QVariant&); + + TestPluginObject* objectfunc(TestPluginObject* obj); + + QString stringstringfunc(const QString&, const QString&); + uint uintdoublestringfunc(uint, double, const QString&); + QStringList stringlistbooluintdouble(const QStringList&, bool, uint, double); +}; + +class TestObject; + +class TestPluginModule : public Kross::Api::Module +{ + public: + TestPluginModule(const QString& name); + virtual ~TestPluginModule(); + virtual const QString getClassName() const; + + virtual Kross::Api::Object::Ptr get(const QString& /*name*/, void* /*pointer*/ = 0) + { + return 0; + } + private: + TestObject* m_testobject; +}; + +#endif diff --git a/lib/kross/test/testscripting.rc b/lib/kross/test/testscripting.rc new file mode 100644 index 000000000..ee641d15c --- /dev/null +++ b/lib/kross/test/testscripting.rc @@ -0,0 +1,33 @@ +<KrossScripting> + <ScriptAction + name="sa1name" + text="ScriptAction1Text" + description="Some describing text" + interpreter="python" + icon="exec"> +print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +print "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + </ScriptAction> + + <ScriptAction + name="testcase" + text="TestCase" + description="Test some common functionality." + interpreter="python" + file="testcase.py" /> + + <ScriptAction + name="testgui" + text="TestGUI" + description="Test the GUI functionality." + interpreter="python" + file="testgui.py" /> + + <ScriptAction + name="testkexidb" + text="TestKexiDB" + description="Test the kexidb binding." + interpreter="python" + file="testkexidb.py" /> + +</KrossScripting> diff --git a/lib/kross/test/testwindow.cpp b/lib/kross/test/testwindow.cpp new file mode 100644 index 000000000..f60119f00 --- /dev/null +++ b/lib/kross/test/testwindow.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + * testwindow.cpp + * This file is part of the KDE project + * copyright (C)2004-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. + ***************************************************************************/ + +#include "testwindow.h" +#include "testplugin.h" + +#include <qlabel.h> +#include <qvbox.h> +#include <qvgroupbox.h> +//#include <qhgroupbox.h> +#include <qcombobox.h> +#include <qdir.h> +#include <qpopupmenu.h> + +#include <ktextedit.h> +#include <kpushbutton.h> +#include <kpopupmenu.h> +#include <kmenubar.h> +#include <kstandarddirs.h> + +TestWindow::TestWindow(const QString& interpretername, const QString& scriptcode) + : KMainWindow() + , m_interpretername(interpretername) + , m_scriptcode(scriptcode) +{ + Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager(); + manager->addModule( new TestPluginModule("krosstestpluginmodule") ); + m_scriptcontainer = manager->getScriptContainer("test"); + + KPopupMenu *menuFile = new KPopupMenu( this ); + menuBar()->insertItem( "&File", menuFile ); + + m_scriptextension = new Kross::Api::ScriptGUIClient(this, this); + + QString file = KGlobal::dirs()->findResource("appdata", "testscripting.rc"); + if(file.isNull()) + file = QDir(QDir::currentDirPath()).filePath("testscripting.rc"); + else Kross::krossdebug("-------------------------222222"); + + Kross::krossdebug(QString("XML-file: %1").arg(file)); + m_scriptextension->setXMLFile(file); + + //menuFile->insertSeparator(); + + KAction* execaction = m_scriptextension->action("executescriptfile"); + if(execaction) execaction->plug(menuFile); + + KAction* configaction = m_scriptextension->action("configurescripts"); + if(configaction) configaction->plug(menuFile); + + KAction* scriptsaction = m_scriptextension->action("installedscripts"); + if(scriptsaction) scriptsaction->plug(menuFile); + //menuFile->insertItem( ( (KActionMenu*)m_scriptextension->action("scripts") )->popupMenu() ); + + QVBox* mainbox = new QVBox(this); + + QVGroupBox* interpretergrpbox = new QVGroupBox("Interpreter", mainbox); + QStringList interpreters = Kross::Api::Manager::scriptManager()->getInterpreters(); + m_interpretercombo = new QComboBox(interpretergrpbox); + m_interpretercombo->insertStringList(interpreters); + m_interpretercombo->setCurrentText(interpretername); + + QVGroupBox* scriptgrpbox = new QVGroupBox("Scripting code", mainbox); + m_codeedit = new KTextEdit(m_scriptcode, QString::null, scriptgrpbox); + m_codeedit->setWordWrap(QTextEdit::NoWrap); + m_codeedit->setTextFormat(Qt::PlainText); + + QHBox* btnbox = new QHBox(mainbox); + KPushButton* execbtn = new KPushButton("Execute", btnbox); + connect(execbtn, SIGNAL(clicked()), this, SLOT(execute())); + + setCentralWidget(mainbox); + setMinimumSize(600,420); +} + +TestWindow::~TestWindow() +{ +} + +void TestWindow::execute() +{ + m_scriptcontainer->setInterpreterName( m_interpretercombo->currentText() ); + m_scriptcontainer->setCode(m_codeedit->text()); + Kross::Api::Object::Ptr result = m_scriptcontainer->execute(); + if(m_scriptcontainer->hadException()) { + Kross::krossdebug( QString("EXCEPTION => %1").arg(m_scriptcontainer->getException()->toString()) ); + } + else { + QString s = result ? result->toString() : QString::null; + Kross::krossdebug( QString("DONE => %1").arg(s) ); + } +} + +#include "testwindow.moc" diff --git a/lib/kross/test/testwindow.h b/lib/kross/test/testwindow.h new file mode 100644 index 000000000..dbb190b95 --- /dev/null +++ b/lib/kross/test/testwindow.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * testwindow.h + * This file is part of the KDE project + * copyright (C)2004-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 KROSS_TEST_TESTWINDOW_H +#define KROSS_TEST_TESTWINDOW_H + +#include "../main/manager.h" +#include "../main/scriptcontainer.h" +#include "../main/scriptguiclient.h" +#include "../api/object.h" + +//#include <qobject.h> +#include <qstring.h> + +#include <kmainwindow.h> + +class QComboBox; +class KTextEdit; + +class TestWindow : public KMainWindow +{ + Q_OBJECT + public: + TestWindow(const QString& interpretername, const QString& scriptcode); + virtual ~TestWindow(); + private slots: + void execute(); + private: + QString m_interpretername; + QString m_scriptcode; + + Kross::Api::ScriptContainer::Ptr m_scriptcontainer; + Kross::Api::ScriptGUIClient* m_scriptextension; + + QComboBox* m_interpretercombo; + KTextEdit* m_codeedit; +}; + +#endif |