00001 /*************************************************************************** 00002 * Copyright (C) 2007 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 <omggraph.h> 00022 #include <omgdataseries.h> 00023 #include <QImage> 00024 #include <QList> 00025 00026 class OmgGraphTest: public QObject 00027 { 00028 Q_OBJECT; 00029 private slots: 00030 void testRemoveSeries(); 00031 void testRenderGraph(); 00032 void initTestCase();// will be called before the first testfunction is executed. 00033 void cleanupTestCase();// will be called after the last testfunction was executed. 00034 void init(){};// will be called before each testfunction is executed. 00035 void cleanup(){};// will be called after every testfunction. 00036 private: 00037 //some dummy data 00038 OmgDataSeries mSeries1; 00039 OmgDataSeries mSeries2; 00040 OmgDataSeries mSeries3; 00041 QImage mImage; 00042 QPainter * mpPainter; 00043 }; 00044 00045 void OmgGraphTest::initTestCase() 00046 { 00047 //prepare some dummy data for charting 00048 QList <double> myList1; 00049 myList1 << -0.5 << 0.8 << 1.0 << 0.8 << 1.0 << 0.6; 00050 mSeries1.setLabel( "Test Series 1" ); 00051 mSeries1.setYValuesList( myList1 ); 00052 QVERIFY(mSeries1.xAt(0)==0); 00053 mSeries1.setFillColor(Qt::red); 00054 mSeries1.setLineColor(Qt::darkRed); 00055 // 00056 mSeries2 << -0.3 << 0.1 << 0.5 << 0.3 << 0.1 << 0.9; 00057 mSeries2.setLabel ( "Test Series 2" ); 00058 mSeries2.setFillColor(Qt::green); 00059 mSeries2.setLineColor(Qt::darkGreen); 00060 // 00061 mSeries3 << -0.7 << 0.5 << 0.3 << 0.4 << 0.3 << 0.6; 00062 mSeries3.setLabel( "Test Series 3" ); 00063 mSeries3.setFillColor(Qt::blue); 00064 mSeries3.setLineColor(Qt::darkBlue); 00065 // 00066 //make an image to draw the graph onto 00067 mImage = QImage( 800,800,QImage::Format_ARGB32 ); 00068 mImage.fill(Qt::white); 00069 mpPainter = new QPainter ( &mImage ); 00070 } 00071 void OmgGraphTest::cleanupTestCase() 00072 { 00073 delete mpPainter; 00074 } 00075 void OmgGraphTest::testRemoveSeries() 00076 { 00077 //qDebug(mSeries1.first); 00078 //qDebug(QString::number(mSeries1.second.count())); 00079 OmgGraph myGraph(mpPainter); 00080 myGraph.addSeries(mSeries1); 00081 myGraph.addSeries(mSeries2); 00082 myGraph.addSeries(mSeries3); 00083 //qDebug("Series count:"); 00084 //qDebug(QString::number(myGraph.seriesCount())); 00085 QVERIFY(myGraph.seriesCount()==3); 00086 //try to remove a non existing series 00087 QVERIFY(!myGraph.removeSeriesAt(10)); 00088 //try to remove all series 00089 QVERIFY(myGraph.removeSeriesAt(1)); 00090 //two is now one 00091 QVERIFY(myGraph.removeSeriesAt(1)); 00092 QVERIFY(myGraph.removeSeriesAt(0)); 00093 //qDebug("Series count:"); 00094 //qDebug(QString::number(myGraph.seriesCount())); 00095 QVERIFY(myGraph.seriesCount()==0); 00096 } 00097 void OmgGraphTest::testRenderGraph() 00098 { 00099 OmgGraph myGraph(mpPainter); 00100 myGraph.clear(); 00101 myGraph.addSeries(mSeries1); 00102 myGraph.addSeries(mSeries2); 00103 myGraph.addSeries(mSeries3); 00104 //qDebug("Series count:"); 00105 //qDebug(QString::number(myGraph.seriesCount())); 00106 myGraph.render(); 00107 QVERIFY(mImage.save("/tmp/graphtest1.png")!=false); 00108 myGraph.clear(); 00109 //turn on all the bells & whistles - except splining 00110 myGraph.setVerticesEnabled(true); 00111 myGraph.setVertexLabelsEnabled(true); 00112 myGraph.setAreaFillEnabled(true); 00113 myGraph.setSpliningEnabled(false); 00114 myGraph.setGridLinesEnabled(true); 00115 myGraph.render(); 00116 QVERIFY(mImage.save("/tmp/graphtest2.png")!=false); 00117 myGraph.clear(); 00118 myGraph.setVerticesEnabled(true); 00119 myGraph.setVertexLabelsEnabled(true); 00120 myGraph.setAreaFillEnabled(true); 00121 myGraph.setSpliningEnabled(true); 00122 myGraph.setGridLinesEnabled(false); 00123 myGraph.removeSeriesAt(0); 00124 myGraph.removeSeriesAt(0); 00125 myGraph.render(); 00126 QVERIFY(mImage.save("/tmp/graphtest3.png")!=false); 00127 } 00128 00129 QTEST_MAIN(OmgGraphTest) 00130 #include "moc_omggraphtest.cxx"