00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "../main/manager.h"
00021
00022 #include "../api/object.h"
00023 #include "../api/class.h"
00024 #include "../api/module.h"
00025
00026 #include "../api/interpreter.h"
00027
00028 #include "../main/scriptcontainer.h"
00029
00030
00031
00032 #include "testobject.h"
00033 #include "testaction.h"
00034 #include "testwindow.h"
00035 #include "testplugin.h"
00036
00037
00038 #include <qstring.h>
00039 #include <qfile.h>
00040
00041
00042 #include <kdebug.h>
00043 #include <kinstance.h>
00044 #include <kapplication.h>
00045 #include <kcmdlineargs.h>
00046 #include <kaboutdata.h>
00047 #include <ksharedptr.h>
00048
00049
00050 #include <string>
00051 #include <iostream>
00052
00053 KApplication *app = 0;
00054
00055 static KCmdLineOptions options[] =
00056 {
00057 { "interpreter <interpretername>", I18N_NOOP("Name of the interpreter being used"), "python" },
00058 { "scriptfile <filename>", I18N_NOOP("Script file to execute with the defined interpreter"), "testcase.py" },
00059 { "gui", I18N_NOOP("Start the GUI; otherwise the command line application is used."), 0 },
00060
00061
00062
00063 { 0, 0, 0 }
00064 };
00065
00066 void runInterpreter(const QString& interpretername, const QString& scriptcode)
00067 {
00068 try {
00069
00070
00071
00072 Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager();
00073 if(! manager)
00074 Kross::Api::Exception::Ptr( new Kross::Api::Exception("Failed to get Kross::Api::Manager instance!") );
00075
00076
00077
00078
00079
00080
00081 manager->addModule( new TestPluginModule("krosstestpluginmodule") );
00082
00083
00084
00085
00086 Kross::Api::ScriptContainer::Ptr scriptcontainer = manager->getScriptContainer("MyScriptName");
00087
00088
00089
00090 scriptcontainer->setInterpreterName(interpretername);
00091 scriptcontainer->setCode(scriptcode);
00092
00093
00094 TestObject* testobject = new TestObject(app, scriptcontainer);
00095 manager->addQObject( testobject );
00096
00097 new TestAction(scriptcontainer);
00098
00099
00100 scriptcontainer->execute();
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 }
00127 catch(Kross::Api::Exception::Ptr e) {
00128 std::cout << QString("EXCEPTION %1").arg(e->toString()).latin1() << std::endl;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 std::string s; std::cin >> s;
00145 }
00146
00147 int main(int argc, char **argv)
00148 {
00149 int result = 0;
00150
00151 KAboutData about("krosstest",
00152 "KrossTest",
00153 "0.1",
00154 "KDE application to test the Kross framework.",
00155 KAboutData::License_LGPL,
00156 "(C) 2005 Sebastian Sauer",
00157 "Test the Kross framework!",
00158 "http://www.dipe.org/kross",
00159 "kross@dipe.org");
00160 about.addAuthor("Sebastian Sauer", "Author", "mail@dipe.org");
00161
00162 KCmdLineArgs::init(argc, argv, &about);
00163 KCmdLineArgs::addCmdLineOptions(options);
00164
00165 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00166 QString interpretername = args->getOption("interpreter");
00167 QString scriptfilename = args->getOption("scriptfile");
00168
00169 QFile f(QFile::encodeName(scriptfilename));
00170 if(f.exists() && f.open(IO_ReadOnly)) {
00171 QString scriptcode = f.readAll();
00172 f.close();
00173
00174 if( args->isSet("gui") ) {
00175 app = new KApplication();
00176 TestWindow *mainWin = new TestWindow(interpretername, scriptcode);
00177 app->setMainWidget(mainWin);
00178 mainWin->show();
00179 args->clear();
00180 result = app->exec();
00181 }
00182 else {
00183 app = new KApplication(true, true);
00184 runInterpreter(interpretername, scriptcode);
00185 }
00186 }
00187 else {
00188 kdWarning() << "Failed to load scriptfile: " << scriptfilename << endl;
00189 result = -1;
00190 }
00191
00192 delete app;
00193 return result;
00194 }