00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00062 QString myFileName(QString(TEST_DATA_DIR) + "/model.xml");
00063 qDebug(myFileName);
00064 OmgModel myModel;
00065 myModel.fromXmlFile(myFileName);
00066
00067
00068
00069
00070
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
00104 QVERIFY(!myResult.isEmpty());
00105 myModel.parseModelResult(myResult);
00106 mypModellerPlugin->projectModel(&myModel);
00107
00108 }
00109
00110 void OmgModelTest::loadLocalities()
00111 {
00112
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