Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omgmodeltest.cpp

Go to the documentation of this file.
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 <omgpluginmessenger.h>
00026 #include <omgui.h>
00027 #include <QString>
00028 #include <QDir>
00029 class OmgModelTest: public QObject
00030 {
00031   Q_OBJECT;
00032       private slots:
00033       void run();
00034       void saveAndLoadModel();
00035       void loadLocalities();
00036       public slots:
00037       void showMessage(QString,QString);
00038 };
00039 
00040 void OmgModelTest::showMessage(QString theModelId,QString theMessage)
00041 {
00042   qDebug(theMessage);
00043 }
00044 
00045 void OmgModelTest::saveAndLoadModel()
00046 {
00047   OmgModel myModel;
00048   QString myFileName = "/tmp/" + myModel.guid() + ".xml";
00049   qDebug("Writing Model 1 to: " + myFileName.toLocal8Bit());
00050   Omgui::createTextFile( myFileName , myModel.toXml());
00051   OmgModel myModel2;
00052   QVERIFY(myModel2.fromXmlFile(myFileName));
00053   qDebug("Model 1 GUID: " + myModel.guid().toLocal8Bit());
00054   qDebug("Model 2 GUID: " + myModel2.guid().toLocal8Bit());
00055   QVERIFY(myModel2.guid()==myModel.guid());
00056 }
00057 void OmgModelTest::run()
00058 {
00059   qDebug("Current dir:");
00060   qDebug(QDir::current().absolutePath().toLocal8Bit());
00061   //TEST_DATA_DIR is a compiler define set by cmake
00062   QString myFileName(QString(TEST_DATA_DIR) + "/model.xml");
00063   qDebug(myFileName);
00064   OmgModel myModel;
00065   myModel.fromXmlFile(myFileName);
00066   //we need to replace [PREFIX] in teh file paths in the 
00067   //model we just loaded so our test can actually find the model 
00068   //data. To do that I temporarily get the xml for the model
00069   //search and replace the xml and then reinstate the model
00070   //from the updated xml...
00071   QString myModelXml = myModel.toXml();
00072 
00073   myModelXml.replace("[PREFIX]",TEST_DATA_DIR);
00074   myModel.fromXml(myModelXml);
00075   QString myFileName2 = "/tmp/replacedmodel.xml";
00076   Omgui::createTextFile( myFileName2 , myModel.toModelCreationXml());
00077   
00078   qDebug("\nCreation Layers:");
00079   qDebug("\n" + myModel.creationLayerNames().join("\n").toLocal8Bit());
00080   
00081   qDebug("\nProjection Layers:");
00082   qDebug("\n" + myModel.projectionLayerNames().join("\n").toLocal8Bit());
00083   
00084   QString myPluginsPath=Omgui::pluginDirPath() + QDir::separator() + "modeller";
00085   qDebug("Searching for modeller plugins at:");
00086   qDebug(myPluginsPath.toLocal8Bit());
00087   QStringList myList = OmgModellerPluginRegistry::instance()->names();
00088   qDebug("\nAvailable modeller plugins:");
00089   qDebug( "\n" + myList.join("\n").toLocal8Bit() );
00090   QVERIFY(myList.count() > 0);
00091   
00092   myModel.setWorkDir("/tmp");
00093   
00094   OmgModellerPluginInterface * mypModellerPlugin = 
00095   OmgModellerPluginRegistry::instance()->getPlugin();
00096   QVERIFY(!mypModellerPlugin->getName().isEmpty());
00097   const OmgPluginMessenger * mypMessenger = mypModellerPlugin->getMessenger();
00098   connect(mypMessenger, SIGNAL(modelMessage(QString,QString )),
00099       this, SLOT(showMessage(QString,QString)));
00100   connect(mypMessenger, SIGNAL(modelError(QString,QString )),
00101       this, SLOT(showMessage(QString,QString)));
00102   QString myResult = mypModellerPlugin->createModel(&myModel);
00103   //qDebug(myResult);
00104   QVERIFY(!myResult.isEmpty());
00105   myModel.parseModelResult(myResult);
00106   mypModellerPlugin->projectModel(&myModel);
00107 
00108 }
00109 
00110 void OmgModelTest::loadLocalities()
00111 {
00112   //TEST_DATA_DIR is a compiler define set by cmake
00113   QString myFileName(QString(TEST_DATA_DIR) + "/Trifolium_repens.txt");
00114   OmgModel myModel;
00115   myModel.setSpeciesFile(myFileName);
00116   myModel.setTaxonName("Trifolium repens");
00117   unsigned int myCount = myModel.loadLocalities();
00118   qDebug(QString::number(myCount).toLocal8Bit() + " records loaded");
00119   QVERIFY(myCount==24527);
00120 }
00121 
00122 QTEST_MAIN(OmgModelTest) 
00123 #include "moc_omgmodeltest.cxx"
00124   
00125 

Generated on Mon Apr 28 15:09:50 2008 for openModellerDesktop by  doxygen 1.4.1-20050210