PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/src/core/testqgsvectorlayer.cpp

https://github.com/linz/Quantum-GIS
C++ | 653 lines | 467 code | 141 blank | 45 comment | 3 complexity | 317fc33926b9323f0eb27a310fd93b1a MD5 | raw file
  1. /***************************************************************************
  2. test_template.cpp
  3. --------------------------------------
  4. Date : Sun Sep 16 12:22:23 AKDT 2007
  5. Copyright : (C) 2007 by Gary E. Sherman
  6. Email : sherman at mrcc dot com
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include <QtTest>
  16. #include <QObject>
  17. #include <QString>
  18. #include <QStringList>
  19. #include <QObject>
  20. #include <QApplication>
  21. #include <QFileInfo>
  22. #include <QDir>
  23. #include <QDesktopServices>
  24. #include <iostream>
  25. //qgis includes...
  26. #include <qgsmaprenderer.h>
  27. #include <qgsmaplayer.h>
  28. #include <qgsvectordataprovider.h>
  29. #include <qgsvectorlayer.h>
  30. #include <qgsapplication.h>
  31. #include <qgsproviderregistry.h>
  32. #include <qgsmaplayerregistry.h>
  33. //qgis test includes
  34. #include "qgsrenderchecker.h"
  35. /** \ingroup UnitTests
  36. * This is a unit test for the vector layer class.
  37. */
  38. class TestQgsVectorLayer: public QObject
  39. {
  40. Q_OBJECT;
  41. private:
  42. bool mTestHasError;
  43. QgsMapRenderer * mpMapRenderer;
  44. QgsMapLayer * mpPointsLayer;
  45. QgsMapLayer * mpLinesLayer;
  46. QgsMapLayer * mpPolysLayer;
  47. QgsVectorLayer * mpNonSpatialLayer;
  48. QString mTestDataDir;
  49. QString mReport;
  50. private slots:
  51. // will be called before the first testfunction is executed.
  52. void initTestCase()
  53. {
  54. mTestHasError = false;
  55. // init QGIS's paths - true means that all path will be inited from prefix
  56. QString qgisPath = QCoreApplication::applicationDirPath();
  57. QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
  58. QgsApplication::showSettings();
  59. // Instantiate the plugin directory so that providers are loaded
  60. QgsProviderRegistry::instance( QgsApplication::pluginPath() );
  61. //create some objects that will be used in all tests...
  62. std::cout << "Prefix PATH: " << QgsApplication::prefixPath().toLocal8Bit().data() << std::endl;
  63. std::cout << "Plugin PATH: " << QgsApplication::pluginPath().toLocal8Bit().data() << std::endl;
  64. std::cout << "PkgData PATH: " << QgsApplication::pkgDataPath().toLocal8Bit().data() << std::endl;
  65. std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;
  66. //
  67. //create a non spatial layer that will be used in all tests...
  68. //
  69. QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
  70. mTestDataDir = myDataDir + QDir::separator();
  71. QString myDbfFileName = mTestDataDir + "nonspatial.dbf";
  72. QFileInfo myDbfFileInfo( myDbfFileName );
  73. mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(),
  74. myDbfFileInfo.completeBaseName(), "ogr" );
  75. // Register the layer with the registry
  76. QgsMapLayerRegistry::instance()->addMapLayer( mpNonSpatialLayer );
  77. //
  78. //create a point layer that will be used in all tests...
  79. //
  80. QString myPointsFileName = mTestDataDir + "points.shp";
  81. QFileInfo myPointFileInfo( myPointsFileName );
  82. mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
  83. myPointFileInfo.completeBaseName(), "ogr" );
  84. // Register the layer with the registry
  85. QgsMapLayerRegistry::instance()->addMapLayer( mpPointsLayer );
  86. //
  87. //create a poly layer that will be used in all tests...
  88. //
  89. QString myPolysFileName = mTestDataDir + "polys.shp";
  90. QFileInfo myPolyFileInfo( myPolysFileName );
  91. mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
  92. myPolyFileInfo.completeBaseName(), "ogr" );
  93. // Register the layer with the registry
  94. QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer );
  95. //
  96. // Create a line layer that will be used in all tests...
  97. //
  98. QString myLinesFileName = mTestDataDir + "lines.shp";
  99. QFileInfo myLineFileInfo( myLinesFileName );
  100. mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
  101. myLineFileInfo.completeBaseName(), "ogr" );
  102. // Register the layer with the registry
  103. QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer );
  104. //
  105. // We only need maprender instead of mapcanvas
  106. // since maprender does not require a qui
  107. // and is more light weight
  108. //
  109. mpMapRenderer = new QgsMapRenderer();
  110. QStringList myLayers;
  111. myLayers << mpPointsLayer->id();
  112. myLayers << mpPolysLayer->id();
  113. myLayers << mpLinesLayer->id();
  114. mpMapRenderer->setLayerSet( myLayers );
  115. mReport += "<h1>Vector Renderer Tests</h1>\n";
  116. }
  117. // will be called after the last testfunction was executed.
  118. void cleanupTestCase()
  119. {
  120. QString myReportFile = QDir::tempPath() + QDir::separator() + "renderertest.html";
  121. QFile myFile( myReportFile );
  122. if ( myFile.open( QIODevice::WriteOnly ) )
  123. {
  124. QTextStream myQTextStream( &myFile );
  125. myQTextStream << mReport;
  126. myFile.close();
  127. QDesktopServices::openUrl( "file://" + myReportFile );
  128. }
  129. }
  130. void init() {};// will be called before each testfunction is executed.
  131. void cleanup() {};// will be called after every testfunction.
  132. void QgsVectorLayerNonSpatialIterator()
  133. {
  134. QgsVectorDataProvider * myProvider = mpNonSpatialLayer->dataProvider();
  135. QgsFeature f;
  136. QgsAttributeList myList;
  137. myList << 0 << 1 << 2 << 3;
  138. int myCount = 0;
  139. myProvider->select( myList );
  140. while ( myProvider->nextFeature( f ) )
  141. {
  142. qDebug( "Getting feature from provider" );
  143. myCount++;
  144. }
  145. QVERIFY( myCount == 3 );
  146. };
  147. void QgsVectorLayerstorageType()
  148. {
  149. };
  150. void QgsVectorLayercapabilitiesString()
  151. {
  152. };
  153. void QgsVectorLayerdataComment()
  154. {
  155. };
  156. void QgsVectorLayerproviderType()
  157. {
  158. };
  159. void QgsVectorLayersetDisplayField()
  160. {
  161. };
  162. void QgsVectorLayerdrawLabels()
  163. {
  164. };
  165. void QgsVectorLayerdrawLineString()
  166. {
  167. };
  168. void QgsVectorLayerdrawPolygon()
  169. {
  170. };
  171. void QgsVectorLayerdrawRendererV2()
  172. {
  173. };
  174. void QgsVectorLayerdrawRendererV2Levels()
  175. {
  176. };
  177. void QgsVectorLayerreload()
  178. {
  179. };
  180. void QgsVectorLayerdraw()
  181. {
  182. };
  183. void QgsVectorLayerdeleteCachedGeometries()
  184. {
  185. };
  186. void QgsVectorLayerdrawVertexMarker()
  187. {
  188. };
  189. void QgsVectorLayerselect()
  190. {
  191. };
  192. void QgsVectorLayerinvertSelection()
  193. {
  194. };
  195. void QgsVectorLayerinvertSelectionInRectangle()
  196. {
  197. };
  198. void QgsVectorLayerremoveSelection()
  199. {
  200. };
  201. void QgsVectorLayertriggerRepaint()
  202. {
  203. };
  204. void QgsVectorLayerdataProvider()
  205. {
  206. };
  207. void QgsVectorLayersetProviderEncoding()
  208. {
  209. };
  210. void QgsVectorLayerrenderer()
  211. {
  212. };
  213. void QgsVectorLayersetRenderer()
  214. {
  215. };
  216. void QgsVectorLayergeometryType()
  217. {
  218. };
  219. void QgsVectorLayerwkbType()
  220. {
  221. };
  222. void QgsVectorLayerboundingBoxOfSelected()
  223. {
  224. };
  225. void QgsVectorLayerfeatureCount()
  226. {
  227. };
  228. void QgsVectorLayerupdateFeatureCount()
  229. {
  230. };
  231. void QgsVectorLayerupdateExtents()
  232. {
  233. };
  234. void QgsVectorLayersubsetString()
  235. {
  236. };
  237. void QgsVectorLayersetSubsetString()
  238. {
  239. };
  240. void QgsVectorLayerupdateFeatureAttributes()
  241. {
  242. };
  243. void QgsVectorLayerupdateFeatureGeometry()
  244. {
  245. };
  246. void QgsVectorLayernextFeature()
  247. {
  248. };
  249. void QgsVectorLayerfeatureAtId()
  250. {
  251. };
  252. void QgsVectorLayeraddFeature()
  253. {
  254. };
  255. void QgsVectorLayerinsertVertex()
  256. {
  257. };
  258. void QgsVectorLayermoveVertex()
  259. {
  260. };
  261. void QgsVectorLayerdeleteVertex()
  262. {
  263. };
  264. void QgsVectorLayerdeleteSelectedFeatures()
  265. {
  266. };
  267. void QgsVectorLayeraddRing()
  268. {
  269. };
  270. void QgsVectorLayeraddIsland()
  271. {
  272. };
  273. void QgsVectorLayertranslateFeature()
  274. {
  275. };
  276. void QgsVectorLayersplitFeatures()
  277. {
  278. };
  279. void QgsVectorLayerremovePolygonIntersections()
  280. {
  281. };
  282. void QgsVectorLayeraddTopologicalPoints()
  283. {
  284. };
  285. void QgsVectorLayerlabel()
  286. {
  287. };
  288. void QgsVectorLayerenableLabels()
  289. {
  290. };
  291. void QgsVectorLayerhasLabelsEnabled()
  292. {
  293. };
  294. void QgsVectorLayerstartEditing()
  295. {
  296. };
  297. void QgsVectorLayerreadXml()
  298. {
  299. };
  300. void QgsVectorLayersetDataProvider()
  301. {
  302. };
  303. void QgsVectorLayerwriteXml()
  304. {
  305. };
  306. void QgsVectorLayerreadSymbology()
  307. {
  308. };
  309. void QgsVectorLayerwriteSymbology()
  310. {
  311. };
  312. void QgsVectorLayerchangeGeometry()
  313. {
  314. };
  315. void QgsVectorLayerchangeAttributeValue()
  316. {
  317. };
  318. void QgsVectorLayeraddAttribute()
  319. {
  320. };
  321. void QgsVectorLayeraddAttributeAlias()
  322. {
  323. };
  324. void QgsVectorLayerattributeAlias()
  325. {
  326. };
  327. void QgsVectorLayerattributeDisplayName()
  328. {
  329. };
  330. void QgsVectorLayerdeleteAttribute()
  331. {
  332. };
  333. void QgsVectorLayerdeleteFeature()
  334. {
  335. };
  336. void QgsVectorLayerpendingFields()
  337. {
  338. };
  339. void QgsVectorLayerpendingAllAttributesList()
  340. {
  341. };
  342. void QgsVectorLayerpendingFeatureCount()
  343. {
  344. };
  345. void QgsVectorLayercommitChanges()
  346. {
  347. };
  348. void QgsVectorLayercommitErrors()
  349. {
  350. };
  351. void QgsVectorLayerrollBack()
  352. {
  353. };
  354. void QgsVectorLayersetSelectedFeatures()
  355. {
  356. };
  357. void QgsVectorLayerselectedFeatureCount()
  358. {
  359. };
  360. void QgsVectorLayerselectedFeaturesIds()
  361. {
  362. };
  363. void QgsVectorLayerselectedFeatures()
  364. {
  365. };
  366. void QgsVectorLayeraddFeatures()
  367. {
  368. };
  369. void QgsVectorLayercopySymbologySettings()
  370. {
  371. };
  372. void QgsVectorLayerhasCompatibleSymbology()
  373. {
  374. };
  375. void QgsVectorLayersnapPoint()
  376. {
  377. };
  378. void QgsVectorLayersnapWithContext()
  379. {
  380. };
  381. void QgsVectorLayersnapToGeometry()
  382. {
  383. };
  384. void QgsVectorLayerinsertSegmentVerticesForSnap()
  385. {
  386. };
  387. void QgsVectorLayerboundingBoxFromPointList()
  388. {
  389. };
  390. void QgsVectorLayercurrentVertexMarkerType()
  391. {
  392. };
  393. void QgsVectorLayercurrentVertexMarkerSize()
  394. {
  395. };
  396. void QgsVectorLayerdrawFeature()
  397. {
  398. };
  399. void QgsVectorLayersetCoordinateSystem()
  400. {
  401. };
  402. void QgsVectorLayertransformPoint()
  403. {
  404. };
  405. void QgsVectorLayertransformPoints()
  406. {
  407. };
  408. void QgsVectorLayerdisplayField()
  409. {
  410. };
  411. void QgsVectorLayerisEditable()
  412. {
  413. };
  414. void QgsVectorLayerisModified()
  415. {
  416. };
  417. void QgsVectorLayersetModified()
  418. {
  419. };
  420. void QgsVectorLayereditType()
  421. {
  422. };
  423. void QgsVectorLayersetEditType()
  424. {
  425. };
  426. void QgsVectorLayereditForm()
  427. {
  428. };
  429. void QgsVectorLayersetEditForm()
  430. {
  431. };
  432. void QgsVectorLayersetAnnotationForm()
  433. {
  434. };
  435. void QgsVectorLayereditFormInit()
  436. {
  437. };
  438. void QgsVectorLayersetEditFormInit()
  439. {
  440. };
  441. void QgsVectorLayervalueMap()
  442. {
  443. };
  444. void QgsVectorLayerrange()
  445. {
  446. };
  447. void QgsVectorLayeraddOverlay()
  448. {
  449. };
  450. void QgsVectorLayerremoveOverlay()
  451. {
  452. };
  453. void QgsVectorLayervectorOverlays()
  454. {
  455. };
  456. void QgsVectorLayerfindOverlayByType()
  457. {
  458. };
  459. void QgsVectorLayerrendererV2()
  460. {
  461. };
  462. void QgsVectorLayersetRendererV2()
  463. {
  464. };
  465. void QgsVectorLayerisUsingRendererV2()
  466. {
  467. };
  468. void QgsVectorLayersetUsingRendererV2()
  469. {
  470. };
  471. void QgsVectorLayereditGeometryChange()
  472. {
  473. };
  474. void QgsVectorLayereditFeatureAdd()
  475. {
  476. };
  477. void QgsVectorLayereditFeatureDelete()
  478. {
  479. };
  480. void QgsVectorLayereditAttributeChange()
  481. {
  482. };
  483. void QgsVectorLayerbeginEditCommand()
  484. {
  485. };
  486. void QgsVectorLayerendEditCommand()
  487. {
  488. };
  489. void QgsVectorLayerdestroyEditCommand()
  490. {
  491. };
  492. void QgsVectorLayerredoEditCommand()
  493. {
  494. };
  495. void QgsVectorLayerundoEditCommand()
  496. {
  497. };
  498. void QgsVectorLayersetCheckedState()
  499. {
  500. };
  501. void QgsVectorLayercheckedState()
  502. {
  503. };
  504. void QgsVectorLayerfieldNameIndex()
  505. {
  506. };
  507. void QgsVectorLayerstopRendererV2()
  508. {
  509. };
  510. };
  511. QTEST_MAIN( TestQgsVectorLayer )
  512. #include "moc_testqgsvectorlayer.cxx"