00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Tim Sutton * 00003 * tim@linfiniti.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 #include <QtTest/QtTest> 00021 #include <QCoreApplication> 00022 #include <omgexperiment.h> 00023 #include <omgmodellerpluginregistry.h> 00024 #include <omgmodellerplugininterface.h> 00025 #include <omgui.h> 00026 #include <QString> 00027 #include <QDir> 00028 class OmgExperimentTest: public QObject 00029 { 00030 Q_OBJECT; 00031 private slots: 00032 void createExperiment(); 00033 void loadAndGraph(); 00034 void run(); 00035 void isAborted(); 00036 void saveAndLoadExperiment(); 00037 void printMessage(QString); //used for connecting to logMessage 00038 }; 00039 00040 void OmgExperimentTest::isAborted() 00041 { 00042 OmgExperiment myExperiment; 00043 QVERIFY(myExperiment.isAborted()==false); 00044 myExperiment.abort(); 00045 QVERIFY(myExperiment.isAborted()==true); 00046 } 00047 void OmgExperimentTest::createExperiment() 00048 { 00049 OmgExperiment myExperiment; 00050 } 00051 void OmgExperimentTest::saveAndLoadExperiment() 00052 { 00053 OmgExperiment myExperiment; 00054 myExperiment.setName("Test 1234"); 00055 QString myFileName; 00056 //@TODO make this OS agnostic... 00057 myFileName = "/tmp/" + myExperiment.guid() + ".xml"; 00058 Omgui::createTextFile( myFileName , myExperiment.toXml()); 00059 OmgExperiment myExperiment2; 00060 myExperiment2.fromXmlFile(myFileName); 00061 QVERIFY(myExperiment2.name()=="Test 1234"); 00062 } 00063 void OmgExperimentTest::loadAndGraph() 00064 { 00065 QString myFileName (TEST_DATA_DIR); //defined in top CmakeLists.txt 00066 myFileName += "/experiment.xml"; 00067 OmgExperiment myExperiment; 00068 myExperiment.fromXmlFile(myFileName); 00069 QVERIFY(myExperiment.name()=="Test"); 00070 myExperiment.makeAlgorithmSummaryGraphs("/tmp"); 00071 } 00072 void OmgExperimentTest::run() 00073 { 00074 //TEST_DATA_DIR is a compiler define set by cmake 00075 QString myFileName(QString(TEST_DATA_DIR) + "/experiment.xml"); 00076 //we need to replace [PREFIX] in teh file paths in the 00077 //model we just loaded so our test can actually find the model 00078 //data. To do that I temporarily get the xml for the model 00079 //search and replace the xml and then reinstate the model 00080 //from the updated xml... 00081 OmgExperiment myExperiment; 00082 myExperiment.fromXmlFile(myFileName); 00083 QString myExperimentXml = myExperiment.toXml(); 00084 myExperimentXml.replace("[PREFIX]",TEST_DATA_DIR); 00085 OmgExperiment myExperiment2; 00086 myExperiment2.fromXml(myExperimentXml); 00087 QVERIFY(myExperiment2.name()=="Test"); 00088 connect(&myExperiment2, SIGNAL(logMessage(QString)), 00089 this, SLOT(printMessage(QString))); 00090 QStringList myList = OmgModellerPluginRegistry::instance()->names(); 00091 qDebug( 00092 myList.join(" -- ") 00093 ); 00094 QVERIFY(myList.count() > 0); 00095 OmgModellerPluginInterface * mypModellerPlugin = 00096 OmgModellerPluginRegistry::instance()->getPlugin(); 00097 QVERIFY(!mypModellerPlugin->getName().isEmpty()); 00098 myExperiment2.setModellerPlugin(mypModellerPlugin); 00099 myExperiment2.reset(); 00100 myExperiment2.setWorkDir("/tmp"); 00101 myExperiment2.run(); 00102 myExperiment2.makeAlgorithmSummaryGraphs("/tmp"); 00103 00104 } 00105 void OmgExperimentTest::printMessage(QString theMessage) 00106 { 00107 qDebug(theMessage); 00108 } 00109 00110 QTEST_MAIN(OmgExperimentTest) 00111 #include "moc_omgexperimenttest.cxx" 00112