Skip to content

Commit 4b644b7

Browse files
author
wonder
committed
merge from trunk r12100:12135
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@12136 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 94c5bc2 commit 4b644b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3243
-3116
lines changed

CODING

+90-56
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ Developers guide for QGIS
5454
3.1. The QGIS testing framework - an overview
5555
3.2. Creating a unit test
5656
3.3. Adding your unit test to CMakeLists.txt
57-
3.4. Building your unit test
58-
3.5. Run your tests
57+
3.4. The ADD_QGIS_TEST macro explained
58+
3.5. Building your unit test
59+
3.6. Run your tests
5960
4. HIG (Human Interface Guidelines)
6061
5. Authors
6162

@@ -1136,28 +1137,50 @@ line is the include for the MOC generated sources. You should replace
11361137

11371138
Adding your unit test to the build system is simply a matter of editing the
11381139
CMakeLists.txt in the test directory, cloning one of the existing test blocks,
1139-
and then search and replacing your test class name into it. For example:
1140+
and then replacing your test class name into it. For example:
11401141

11411142

1142-
#
11431143
# QgsRasterLayer test
1144-
#
1145-
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
1146-
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
1147-
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
1148-
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
1149-
ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS})
1150-
ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
1151-
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
1152-
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
1153-
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
1144+
ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp)
11541145

11551146

1156-
I'll run through these lines briefly to explain what they do, but if you are
1157-
not interested, just clone the block, search and replace e.g.
11581147

1148+
3.4. The ADD_QGIS_TEST macro explained
1149+
======================================
11591150

1160-
:'<,'>s/rasterlayer/mynewtest/g
1151+
I'll run through these lines briefly to explain what they do, but if you are
1152+
not interested, just do the step explained in the above section and section.
1153+
1154+
1155+
MACRO (ADD_QGIS_TEST testname testsrc)
1156+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
1157+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
1158+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
1159+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
1160+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
1161+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
1162+
TARGET_LINK_LIBRARIES(qgis_${testname} ${QT_LIBRARIES} qgis_core)
1163+
SET_TARGET_PROPERTIES(qgis_${testname}
1164+
PROPERTIES
1165+
# skip the full RPATH for the build tree
1166+
SKIP_BUILD_RPATH TRUE
1167+
# when building, use the install RPATH already
1168+
# (so it doesn't need to relink when installing)
1169+
BUILD_WITH_INSTALL_RPATH TRUE
1170+
# the RPATH to be used when installing
1171+
INSTALL_RPATH ${QGIS_LIB_DIR}
1172+
# add the automatically determined parts of the RPATH
1173+
# which point to directories outside the build tree to the install RPATH
1174+
INSTALL_RPATH_USE_LINK_PATH true)
1175+
IF (APPLE)
1176+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
1177+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
1178+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/qgis_${testname})
1179+
ELSE (APPLE)
1180+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
1181+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/bin/qgis_${testname})
1182+
ENDIF (APPLE)
1183+
ENDMACRO (ADD_QGIS_TEST)
11611184

11621185

11631186
Lets look a little more in detail at the individual lines. First we define the
@@ -1166,16 +1189,16 @@ methodology I described above where class declaration and definition are in the
11661189
same file) its a simple statement:
11671190

11681191

1169-
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
1192+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
11701193

11711194

11721195
Since our test class needs to be run through the Qt meta object compiler (moc)
11731196
we need to provide a couple of lines to make that happen too:
11741197

11751198

1176-
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
1177-
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
1178-
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
1199+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
1200+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
1201+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
11791202

11801203

11811204
Next we tell cmake that it must make an executeable from the test class.
@@ -1185,8 +1208,8 @@ included the moc outputs directly into our test class, so that will give it
11851208
executeable:
11861209

11871210

1188-
ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS})
1189-
ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
1211+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
1212+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
11901213

11911214

11921215
Next we need to specify any library dependencies. At the moment classes have
@@ -1196,38 +1219,49 @@ only. Of course you also need to link to the relevant qgis libraries as
11961219
required by your unit test.
11971220

11981221

1199-
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
1200-
1201-
1202-
Next I tell cmake to the same place as the qgis binaries itself. This is
1203-
something I plan to remove in the future so that the tests can run directly
1204-
from inside the source tree.
1205-
1206-
1207-
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
1208-
1209-
1210-
Finally here is where the best magic happens - we register the class with
1211-
ctest. If you recall in the overview I gave in the beginning of this section we
1212-
are using both QtTest and CTest together. To recap, QtTest adds a main
1213-
method to your test unit and handles calling your test methods within the
1214-
class. It also provides some macros like QVERIFY that you can use as to test
1215-
for failure of the tests using conditions. The output from a QtTest unit test
1216-
is an executeable which you can run from the command line. However when you
1217-
have a suite of tests and you want to run each executeable in turn, and
1218-
better yet integrate running tests into the build process, the CTest is
1219-
what we use. The next line registers the unit test with CMake / CTest.
1220-
1221-
1222-
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
1223-
1224-
1225-
The last thing I should add is that if your test requires optional parts of the
1226-
build process (e.g. Postgresql support, GSL libs, GRASS etc.), you should take
1227-
care to enclose you test block inside a IF () block in the CMakeLists.txt file.
1228-
1229-
1230-
3.4. Building your unit test
1222+
TARGET_LINK_LIBRARIES(qgis_${testname} ${QT_LIBRARIES} qgis_core)
1223+
1224+
1225+
Next I tell cmake to install the tests to the same place as the qgis binaries
1226+
itself. This is something I plan to remove in the future so that the tests can
1227+
run directly from inside the source tree.
1228+
1229+
1230+
SET_TARGET_PROPERTIES(qgis_${testname}
1231+
PROPERTIES
1232+
# skip the full RPATH for the build tree
1233+
SKIP_BUILD_RPATH TRUE
1234+
# when building, use the install RPATH already
1235+
# (so it doesn't need to relink when installing)
1236+
BUILD_WITH_INSTALL_RPATH TRUE
1237+
# the RPATH to be used when installing
1238+
INSTALL_RPATH ${QGIS_LIB_DIR}
1239+
# add the automatically determined parts of the RPATH
1240+
# which point to directories outside the build tree to the install RPATH
1241+
INSTALL_RPATH_USE_LINK_PATH true)
1242+
IF (APPLE)
1243+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
1244+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
1245+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/qgis_${testname})
1246+
ELSE (APPLE)
1247+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
1248+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/bin/qgis_${testname})
1249+
ENDIF (APPLE)
1250+
1251+
1252+
Finally the above uses ADD_TEST to register the test with cmake / ctest . Here
1253+
is where the best magic happens - we register the class with ctest. If you
1254+
recall in the overview I gave in the beginning of this section we are using
1255+
both QtTest and CTest together. To recap, QtTest adds a main method to your
1256+
test unit and handles calling your test methods within the class. It also
1257+
provides some macros like QVERIFY that you can use as to test for failure of
1258+
the tests using conditions. The output from a QtTest unit test is an
1259+
executeable which you can run from the command line. However when you have a
1260+
suite of tests and you want to run each executeable in turn, and better yet
1261+
integrate running tests into the build process, the CTest is what we use.
1262+
1263+
1264+
3.5. Building your unit test
12311265
============================
12321266

12331267
To build the unit test you need only to make sure that ENABLE_TESTS=true in the
@@ -1240,7 +1274,7 @@ cmake configuration. There are two ways to do this:
12401274
Other than that, just build QGIS as per normal and the tests should build too.
12411275

12421276

1243-
3.5. Run your tests
1277+
3.6. Run your tests
12441278
===================
12451279

12461280
The simplest way to run the tests is as part of your normal build process:

doc/CODING.t2t

+82-51
Original file line numberDiff line numberDiff line change
@@ -1026,28 +1026,48 @@ line is the include for the MOC generated sources. You should replace
10261026

10271027
Adding your unit test to the build system is simply a matter of editing the
10281028
CMakeLists.txt in the test directory, cloning one of the existing test blocks,
1029-
and then search and replacing your test class name into it. For example:
1029+
and then replacing your test class name into it. For example:
10301030

10311031
```
1032-
#
10331032
# QgsRasterLayer test
1034-
#
1035-
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
1036-
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
1037-
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
1038-
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
1039-
ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS})
1040-
ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
1041-
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
1042-
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
1043-
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
1033+
ADD_QGIS_TEST(rasterlayertest testqgsrasterlayer.cpp)
10441034
```
10451035

1046-
I'll run through these lines briefly to explain what they do, but if you are
1047-
not interested, just clone the block, search and replace e.g.
1036+
== The ADD_QGIS_TEST macro explained ==
10481037

1049-
```
1050-
:'<,'>s/rasterlayer/mynewtest/g
1038+
I'll run through these lines briefly to explain what they do, but if you are
1039+
not interested, just do the step explained in the above section and section.
1040+
1041+
```
1042+
MACRO (ADD_QGIS_TEST testname testsrc)
1043+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
1044+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
1045+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
1046+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
1047+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
1048+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
1049+
TARGET_LINK_LIBRARIES(qgis_${testname} ${QT_LIBRARIES} qgis_core)
1050+
SET_TARGET_PROPERTIES(qgis_${testname}
1051+
PROPERTIES
1052+
# skip the full RPATH for the build tree
1053+
SKIP_BUILD_RPATH TRUE
1054+
# when building, use the install RPATH already
1055+
# (so it doesn't need to relink when installing)
1056+
BUILD_WITH_INSTALL_RPATH TRUE
1057+
# the RPATH to be used when installing
1058+
INSTALL_RPATH ${QGIS_LIB_DIR}
1059+
# add the automatically determined parts of the RPATH
1060+
# which point to directories outside the build tree to the install RPATH
1061+
INSTALL_RPATH_USE_LINK_PATH true)
1062+
IF (APPLE)
1063+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
1064+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
1065+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/qgis_${testname})
1066+
ELSE (APPLE)
1067+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
1068+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/bin/qgis_${testname})
1069+
ENDIF (APPLE)
1070+
ENDMACRO (ADD_QGIS_TEST)
10511071
```
10521072

10531073
Lets look a little more in detail at the individual lines. First we define the
@@ -1056,16 +1076,16 @@ methodology I described above where class declaration and definition are in the
10561076
same file) its a simple statement:
10571077

10581078
```
1059-
SET(qgis_rasterlayertest_SRCS testqgsrasterlayer.cpp)
1079+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
10601080
```
10611081

10621082
Since our test class needs to be run through the Qt meta object compiler (moc)
10631083
we need to provide a couple of lines to make that happen too:
10641084

10651085
```
1066-
SET(qgis_rasterlayertest_MOC_CPPS testqgsrasterlayer.cpp)
1067-
QT4_WRAP_CPP(qgis_rasterlayertest_MOC_SRCS ${qgis_rasterlayertest_MOC_CPPS})
1068-
ADD_CUSTOM_TARGET(qgis_rasterlayertestmoc ALL DEPENDS ${qgis_rasterlayertest_MOC_SRCS})
1086+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
1087+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
1088+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
10691089
```
10701090

10711091
Next we tell cmake that it must make an executeable from the test class.
@@ -1075,8 +1095,8 @@ included the moc outputs directly into our test class, so that will give it
10751095
executeable:
10761096

10771097
```
1078-
ADD_EXECUTABLE(qgis_rasterlayertest ${qgis_rasterlayertest_SRCS})
1079-
ADD_DEPENDENCIES(qgis_rasterlayertest qgis_rasterlayertestmoc)
1098+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
1099+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
10801100
```
10811101

10821102
Next we need to specify any library dependencies. At the moment classes have
@@ -1086,35 +1106,46 @@ only. Of course you also need to link to the relevant qgis libraries as
10861106
required by your unit test.
10871107

10881108
```
1089-
TARGET_LINK_LIBRARIES(qgis_rasterlayertest ${QT_LIBRARIES} qgis_core)
1090-
```
1091-
1092-
Next I tell cmake to the same place as the qgis binaries itself. This is
1093-
something I plan to remove in the future so that the tests can run directly
1094-
from inside the source tree.
1095-
1096-
```
1097-
INSTALL(TARGETS qgis_rasterlayertest RUNTIME DESTINATION ${QGIS_BIN_DIR})
1098-
```
1099-
1100-
Finally here is where the best magic happens - we register the class with
1101-
ctest. If you recall in the overview I gave in the beginning of this section we
1102-
are using both QtTest and CTest together. To recap, **QtTest** adds a main
1103-
method to your test unit and handles calling your test methods within the
1104-
class. It also provides some macros like QVERIFY that you can use as to test
1105-
for failure of the tests using conditions. The output from a QtTest unit test
1106-
is an executeable which you can run from the command line. However when you
1107-
have a suite of tests and you want to run each executeable in turn, and
1108-
better yet integrate running tests into the build process, the **CTest** is
1109-
what we use. The next line registers the unit test with CMake / CTest.
1110-
1111-
```
1112-
ADD_TEST(qgis_rasterlayertest ${QGIS_BIN_DIR}/qgis_rasterlayertest)
1113-
```
1114-
1115-
The last thing I should add is that if your test requires optional parts of the
1116-
build process (e.g. Postgresql support, GSL libs, GRASS etc.), you should take
1117-
care to enclose you test block inside a IF () block in the CMakeLists.txt file.
1109+
TARGET_LINK_LIBRARIES(qgis_${testname} ${QT_LIBRARIES} qgis_core)
1110+
```
1111+
1112+
Next I tell cmake to install the tests to the same place as the qgis binaries
1113+
itself. This is something I plan to remove in the future so that the tests can
1114+
run directly from inside the source tree.
1115+
1116+
```
1117+
SET_TARGET_PROPERTIES(qgis_${testname}
1118+
PROPERTIES
1119+
# skip the full RPATH for the build tree
1120+
SKIP_BUILD_RPATH TRUE
1121+
# when building, use the install RPATH already
1122+
# (so it doesn't need to relink when installing)
1123+
BUILD_WITH_INSTALL_RPATH TRUE
1124+
# the RPATH to be used when installing
1125+
INSTALL_RPATH ${QGIS_LIB_DIR}
1126+
# add the automatically determined parts of the RPATH
1127+
# which point to directories outside the build tree to the install RPATH
1128+
INSTALL_RPATH_USE_LINK_PATH true)
1129+
IF (APPLE)
1130+
# For Mac OS X, the executable must be at the root of the bundle's executable folder
1131+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
1132+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/qgis_${testname})
1133+
ELSE (APPLE)
1134+
INSTALL(TARGETS qgis_${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
1135+
ADD_TEST(qgis_${testname} ${CMAKE_INSTALL_PREFIX}/bin/qgis_${testname})
1136+
ENDIF (APPLE)
1137+
```
1138+
1139+
Finally the above uses ADD_TEST to register the test with cmake / ctest . Here
1140+
is where the best magic happens - we register the class with ctest. If you
1141+
recall in the overview I gave in the beginning of this section we are using
1142+
both QtTest and CTest together. To recap, **QtTest** adds a main method to your
1143+
test unit and handles calling your test methods within the class. It also
1144+
provides some macros like QVERIFY that you can use as to test for failure of
1145+
the tests using conditions. The output from a QtTest unit test is an
1146+
executeable which you can run from the command line. However when you have a
1147+
suite of tests and you want to run each executeable in turn, and better yet
1148+
integrate running tests into the build process, the **CTest** is what we use.
11181149

11191150

11201151
== Building your unit test ==

0 commit comments

Comments
 (0)