Skip to content

Commit 2f61769

Browse files
author
timlinux
committed
Initial framwork for raster tests
git-svn-id: http://svn.osgeo.org/qgis/trunk@5254 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6b8a5c7 commit 2f61769

File tree

6 files changed

+561
-0
lines changed

6 files changed

+561
-0
lines changed

tests/src/raster/Makefile.am

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (C) 2003 Gary Sherman <sherman at mrcc.com>
2+
#
3+
# This file is free software; as a special exception the author gives
4+
# unlimited permission to copy and/or distribute it, with or without
5+
# modifications, as long as this notice is preserved.
6+
#
7+
# This program is distributed in the hope that it will be useful, but
8+
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
9+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
bin_PROGRAMS = testqgsrasterlayer
12+
13+
#
14+
# Define some global variables that will be used for building each test
15+
#
16+
17+
GLOBALLDADD = $(QT_LDADD) \
18+
$(PG_LIB) \
19+
$(GDAL_LDADD) \
20+
-lproj \
21+
../../../src/core/libqgis_core.la \
22+
../../../src/raster/libqgis_raster.la \
23+
../../../src/gui/libqgis_gui.la
24+
GLOBALCXXFLAGS = $(CXXFLAGS) \
25+
$(EXTRA_CXXFLAGS) \
26+
$(GDAL_CFLAGS) \
27+
$(QT_CXXFLAGS) \
28+
$(PG_INC) \
29+
-I../../../src/raster \
30+
-I../../../src/core \
31+
-I../../../src/widgets/projectionselector \
32+
-I../../../src/ui \
33+
-I../../../src/gui
34+
35+
#
36+
# Instruction for running the qt4 meta object compiler
37+
#
38+
39+
%.moc.cpp: %.cpp
40+
$(MOC) -o $@ $<
41+
42+
BUILT_SOURCES = $(testqgsrasterlayer_MOC)
43+
44+
CLEANFILES = $(BUILT_SOURCES)
45+
46+
#
47+
# Specify the compilation files for each unit test now
48+
#
49+
50+
testqgsrasterlayer_MOC = testqgsrasterlayer.moc.cpp
51+
testqgsrasterlayer_SOURCES = testqgsrasterlayer.cpp
52+
testqgsrasterlayer_LDADD = $(GLOBALLDADD)
53+
testqgsrasterlayer_CXXFLAGS = $(GLOBALCXXFLAGS)

tests/src/raster/runtests.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#set -x
3+
LIST=`ls -lah |grep rwxr-xr-x |grep -v ^d |grep -v pl$ |grep -v ~$ |grep -v .sh$ |awk '{print $8}'|awk '$1=$1' RS=`
4+
5+
TOTALEXES=0
6+
TOTALFAILED=0
7+
TOTALPASSED=0
8+
TOTALSKIPPED=0
9+
for FILE in $LIST;
10+
do
11+
RESULT=`./${FILE} | tail -2 |head -1`
12+
PASSED=`echo ${RESULT} | awk '{print $2}'`
13+
FAILED=`echo ${RESULT} | awk '{print $4}'`
14+
SKIPPED=`echo ${RESULT} | awk '{print $6}'`
15+
TOTALFAILED=`expr $TOTALFAILED + $FAILED`
16+
TOTALPASSED=`expr $TOTALPASSED + $PASSED`
17+
TOTALSKIPPED=`expr $TOTALSKIPPED + $SKIPPED`
18+
TOTALEXES=`expr $TOTALEXES + 1`
19+
done
20+
echo "-------------------------------"
21+
echo "TOTAL TESTS : ${TOTALEXES}"
22+
echo "-------------------------------"
23+
echo "TOTAL TEST CASES PASSED : ${TOTALPASSED}"
24+
echo "TOTAL TEST CASES FAILED : ${TOTALFAILED}"
25+
echo "TOTAL TEST CASES SKIPPED : ${TOTALSKIPPED}"
26+
echo "-------------------------------"

tests/src/raster/test_builder.pl

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/perl
2+
use Cwd;
3+
4+
#####################################################
5+
# A script to automate creation of a new unit test
6+
# Authors TSutton
7+
# April 08, 2006
8+
#####################################################
9+
# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ #
10+
11+
#make sure we are in a the tests/src/raster dir
12+
$myDir = fastgetcwd;
13+
$sourceDir = "../../../src/raster";
14+
print "\n\nChecking that we are in the <qgis dir>/test/src/raster/ directory....";
15+
if ($myDir =~ m/tests\/src\/raster$/)
16+
{
17+
print "yes\n";
18+
}
19+
else
20+
{
21+
print "no\n";
22+
print $myDir;
23+
print "\nPlease relocate to the /test/src/raster/ directory before attempting to run this script.\n";
24+
exit;
25+
}
26+
# get the needed information from the user
27+
$testClass="";
28+
$argCount = $#ARGV+1;
29+
if ($argCount > 0)
30+
{
31+
$testClass=@ARGV[ 0 ];
32+
}
33+
else
34+
{
35+
print "\n\nEnter the name of the class for which the test will be created.\n";
36+
print "Used mixed case notation.\n";
37+
print "e.g. QgsSymbol\n";
38+
$testClass =<STDIN>;
39+
chop $testClass;
40+
}
41+
42+
$testClassLowerCaseName = lc($testClass); #todo convert to lower case
43+
44+
#
45+
# Check source file is ok
46+
#
47+
48+
if ($testClass eq "")
49+
{
50+
print "ClassName not supplied ...exiting...";
51+
exit;
52+
}
53+
print "Checking if source class exists in filesystem ...";
54+
if (-e "${sourceDir}/${testClassLowerCaseName}.cpp" )
55+
{
56+
print "yes\n";
57+
}
58+
else
59+
{
60+
print "no, exiting\n";
61+
print "${sourceDir}/${testClassLowerCaseName}.cpp does not exist!\n";
62+
exit;
63+
}
64+
65+
66+
print "Stubs will be created for the following methods:\n";
67+
open CPPFILE, "<$sourceDir/$testClassLowerCaseName.cpp"|| die 'Unable to open header file $testClassLowerCaseName.cpp';
68+
$stubString="";
69+
$lastLine="";
70+
while(<CPPFILE>)
71+
{
72+
if(m/${testClass}::[A-Za-z0-9]*\(/)
73+
{
74+
#get the matched part of the line
75+
$line = $&;
76+
#strip off the ::
77+
$line =~ s/:://g;
78+
#strip off the (
79+
$line =~ s/\(//g;
80+
if ($lastLine eq $line)
81+
{
82+
#duplicate entry
83+
}
84+
else
85+
{
86+
#add it to our stub code
87+
$stubString = $stubString . " void $line()\n\{\n\n\};\n";
88+
#show the user the list
89+
print $line;
90+
print "\n";
91+
}
92+
$lastLine=$line;
93+
}
94+
}
95+
$createIt="n";
96+
if ($argCount eq 0)
97+
{
98+
print "-----------------------------\n";
99+
print "Create the unit test? [y/n]: ";
100+
$createIt = <STDIN>;
101+
chop $createIt;
102+
}
103+
else
104+
{
105+
$createIt="y";
106+
}
107+
108+
if(($createIt eq 'y') || ($createIt eq 'Y'))
109+
{
110+
#
111+
# its a go -- create the unit test and modify the build files
112+
#
113+
system("cp test_template.cpp test$testClassLowerCaseName.cpp");
114+
115+
# Substitute the class name in the file
116+
system("perl -pi -e 's/\\\[testClassLowerCaseName\\\]/$testClassLowerCaseName/g' test$testClassLowerCaseName.cpp");
117+
system("perl -pi -e 's/\\\[testClassCamelCaseName\\\]/$testClass/g' test$testClassLowerCaseName.cpp");
118+
system("perl -pi -e 's/\\\[TestMethods\\\]/$stubString/g' test$testClassLowerCaseName.cpp");
119+
# Add an entry to Makefile.am
120+
open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
121+
open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';
122+
# read through Makefile.am and write each line to Makefile.am.mod
123+
while(<MAKEFILE>)
124+
{
125+
if(/^\s*bin_PROGRAMS =*/)
126+
{
127+
# add our application binary name to the next line
128+
print MAKEFILEMOD;
129+
print MAKEFILEMOD "\t\ttest$testClassLowerCaseName \\\n";
130+
}
131+
elsif(/^\s*BUILT_SOURCES =*/)
132+
{
133+
# add our application binary name to the next line
134+
print MAKEFILEMOD;
135+
print MAKEFILEMOD "\t\t\$(test${testClassLowerCaseName}_MOC) \\\n";
136+
}
137+
else
138+
{
139+
print MAKEFILEMOD;
140+
}
141+
}
142+
#before closing the file add the lines for our new test class
143+
print MAKEFILEMOD "\n";
144+
print MAKEFILEMOD "test${testClassLowerCaseName}_MOC = test${testClassLowerCaseName}.moc.cpp\n";
145+
print MAKEFILEMOD "test${testClassLowerCaseName}_SOURCES = test${testClassLowerCaseName}.cpp\n";
146+
print MAKEFILEMOD "test${testClassLowerCaseName}_LDADD = \$(GLOBALLDADD)\n";
147+
print MAKEFILEMOD "test${testClassLowerCaseName}_CXXFLAGS = \$(GLOBALCXXFLAGS)\n";
148+
149+
# close the Makefile file handles
150+
close MAKEFILEMOD;
151+
close MAKEFILE;
152+
153+
# save Makefile.am in case we die before done moving things around
154+
system("mv Makefile.am Makefile.am.save");
155+
# move the new Makefile.am to where it belongs
156+
system("mv Makefile.am.mod Makefile.am");
157+
# delete the original Makefile.am
158+
unlink("Makefile.am.save");
159+
160+
161+
print << "EOP";
162+
163+
Your test unit has been created now as ${testClassLowerCaseName}.cpp.
164+
165+
EOP
166+
167+
}
168+
else
169+
{
170+
# user cancelled
171+
print "Test unit not created\n";
172+
}
173+
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
LIST=`ls ../../../src/raster/ |grep .cpp |grep ^qgs |grep -v ~$ |grep -v moc.cpp$ | sed 's/.cpp//g' |awk '$1=$1' RS= |sort`
3+
for FILE in $LIST
4+
do
5+
CLASSNAME=`grep -o "::Qgs[A-Za-z0-9]*(" ../../../src/raster/${FILE}.cpp |head -1 | sed 's/:://g'| sed 's/(//g'`
6+
./test_builder.pl $CLASSNAME
7+
#svn add test${FILE}.cpp
8+
done
9+
make install

tests/src/raster/test_template.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <QtTest>
2+
#include <QObject>
3+
#include <QString>
4+
#include <QObject>
5+
//header for class being tested
6+
#include <[testClassLowerCaseName].h>
7+
8+
class Test[testClassCamelCaseName]: public QObject
9+
{
10+
Q_OBJECT;
11+
private slots:
12+
[TestMethods]
13+
};
14+
15+
QTEST_MAIN(Test[testClassCamelCaseName])
16+
#include "test[testClassLowerCaseName].moc.cpp"
17+
18+
19+
20+

0 commit comments

Comments
 (0)