Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial framwork for raster tests
git-svn-id: http://svn.osgeo.org/qgis/trunk@5254 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Apr 11, 2006
1 parent 6b8a5c7 commit 2f61769
Show file tree
Hide file tree
Showing 6 changed files with 561 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/src/raster/Makefile.am
@@ -0,0 +1,53 @@
# Copyright (C) 2003 Gary Sherman <sherman at mrcc.com>
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

bin_PROGRAMS = testqgsrasterlayer

#
# Define some global variables that will be used for building each test
#

GLOBALLDADD = $(QT_LDADD) \
$(PG_LIB) \
$(GDAL_LDADD) \
-lproj \
../../../src/core/libqgis_core.la \
../../../src/raster/libqgis_raster.la \
../../../src/gui/libqgis_gui.la
GLOBALCXXFLAGS = $(CXXFLAGS) \
$(EXTRA_CXXFLAGS) \
$(GDAL_CFLAGS) \
$(QT_CXXFLAGS) \
$(PG_INC) \
-I../../../src/raster \
-I../../../src/core \
-I../../../src/widgets/projectionselector \
-I../../../src/ui \
-I../../../src/gui

#
# Instruction for running the qt4 meta object compiler
#

%.moc.cpp: %.cpp
$(MOC) -o $@ $<

BUILT_SOURCES = $(testqgsrasterlayer_MOC)

CLEANFILES = $(BUILT_SOURCES)

#
# Specify the compilation files for each unit test now
#

testqgsrasterlayer_MOC = testqgsrasterlayer.moc.cpp
testqgsrasterlayer_SOURCES = testqgsrasterlayer.cpp
testqgsrasterlayer_LDADD = $(GLOBALLDADD)
testqgsrasterlayer_CXXFLAGS = $(GLOBALCXXFLAGS)
26 changes: 26 additions & 0 deletions tests/src/raster/runtests.sh
@@ -0,0 +1,26 @@
#!/bin/bash
#set -x
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=`

TOTALEXES=0
TOTALFAILED=0
TOTALPASSED=0
TOTALSKIPPED=0
for FILE in $LIST;
do
RESULT=`./${FILE} | tail -2 |head -1`
PASSED=`echo ${RESULT} | awk '{print $2}'`
FAILED=`echo ${RESULT} | awk '{print $4}'`
SKIPPED=`echo ${RESULT} | awk '{print $6}'`
TOTALFAILED=`expr $TOTALFAILED + $FAILED`
TOTALPASSED=`expr $TOTALPASSED + $PASSED`
TOTALSKIPPED=`expr $TOTALSKIPPED + $SKIPPED`
TOTALEXES=`expr $TOTALEXES + 1`
done
echo "-------------------------------"
echo "TOTAL TESTS : ${TOTALEXES}"
echo "-------------------------------"
echo "TOTAL TEST CASES PASSED : ${TOTALPASSED}"
echo "TOTAL TEST CASES FAILED : ${TOTALFAILED}"
echo "TOTAL TEST CASES SKIPPED : ${TOTALSKIPPED}"
echo "-------------------------------"
173 changes: 173 additions & 0 deletions tests/src/raster/test_builder.pl
@@ -0,0 +1,173 @@
#!/usr/bin/perl
use Cwd;

#####################################################
# A script to automate creation of a new unit test
# Authors TSutton
# April 08, 2006
#####################################################
# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ #

#make sure we are in a the tests/src/raster dir
$myDir = fastgetcwd;
$sourceDir = "../../../src/raster";
print "\n\nChecking that we are in the <qgis dir>/test/src/raster/ directory....";
if ($myDir =~ m/tests\/src\/raster$/)
{
print "yes\n";
}
else
{
print "no\n";
print $myDir;
print "\nPlease relocate to the /test/src/raster/ directory before attempting to run this script.\n";
exit;
}
# get the needed information from the user
$testClass="";
$argCount = $#ARGV+1;
if ($argCount > 0)
{
$testClass=@ARGV[ 0 ];
}
else
{
print "\n\nEnter the name of the class for which the test will be created.\n";
print "Used mixed case notation.\n";
print "e.g. QgsSymbol\n";
$testClass =<STDIN>;
chop $testClass;
}

$testClassLowerCaseName = lc($testClass); #todo convert to lower case

#
# Check source file is ok
#

if ($testClass eq "")
{
print "ClassName not supplied ...exiting...";
exit;
}
print "Checking if source class exists in filesystem ...";
if (-e "${sourceDir}/${testClassLowerCaseName}.cpp" )
{
print "yes\n";
}
else
{
print "no, exiting\n";
print "${sourceDir}/${testClassLowerCaseName}.cpp does not exist!\n";
exit;
}


print "Stubs will be created for the following methods:\n";
open CPPFILE, "<$sourceDir/$testClassLowerCaseName.cpp"|| die 'Unable to open header file $testClassLowerCaseName.cpp';
$stubString="";
$lastLine="";
while(<CPPFILE>)
{
if(m/${testClass}::[A-Za-z0-9]*\(/)
{
#get the matched part of the line
$line = $&;
#strip off the ::
$line =~ s/:://g;
#strip off the (
$line =~ s/\(//g;
if ($lastLine eq $line)
{
#duplicate entry
}
else
{
#add it to our stub code
$stubString = $stubString . " void $line()\n\{\n\n\};\n";
#show the user the list
print $line;
print "\n";
}
$lastLine=$line;
}
}
$createIt="n";
if ($argCount eq 0)
{
print "-----------------------------\n";
print "Create the unit test? [y/n]: ";
$createIt = <STDIN>;
chop $createIt;
}
else
{
$createIt="y";
}

if(($createIt eq 'y') || ($createIt eq 'Y'))
{
#
# its a go -- create the unit test and modify the build files
#
system("cp test_template.cpp test$testClassLowerCaseName.cpp");

# Substitute the class name in the file
system("perl -pi -e 's/\\\[testClassLowerCaseName\\\]/$testClassLowerCaseName/g' test$testClassLowerCaseName.cpp");
system("perl -pi -e 's/\\\[testClassCamelCaseName\\\]/$testClass/g' test$testClassLowerCaseName.cpp");
system("perl -pi -e 's/\\\[TestMethods\\\]/$stubString/g' test$testClassLowerCaseName.cpp");
# Add an entry to Makefile.am
open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';
# read through Makefile.am and write each line to Makefile.am.mod
while(<MAKEFILE>)
{
if(/^\s*bin_PROGRAMS =*/)
{
# add our application binary name to the next line
print MAKEFILEMOD;
print MAKEFILEMOD "\t\ttest$testClassLowerCaseName \\\n";
}
elsif(/^\s*BUILT_SOURCES =*/)
{
# add our application binary name to the next line
print MAKEFILEMOD;
print MAKEFILEMOD "\t\t\$(test${testClassLowerCaseName}_MOC) \\\n";
}
else
{
print MAKEFILEMOD;
}
}
#before closing the file add the lines for our new test class
print MAKEFILEMOD "\n";
print MAKEFILEMOD "test${testClassLowerCaseName}_MOC = test${testClassLowerCaseName}.moc.cpp\n";
print MAKEFILEMOD "test${testClassLowerCaseName}_SOURCES = test${testClassLowerCaseName}.cpp\n";
print MAKEFILEMOD "test${testClassLowerCaseName}_LDADD = \$(GLOBALLDADD)\n";
print MAKEFILEMOD "test${testClassLowerCaseName}_CXXFLAGS = \$(GLOBALCXXFLAGS)\n";

# close the Makefile file handles
close MAKEFILEMOD;
close MAKEFILE;

# save Makefile.am in case we die before done moving things around
system("mv Makefile.am Makefile.am.save");
# move the new Makefile.am to where it belongs
system("mv Makefile.am.mod Makefile.am");
# delete the original Makefile.am
unlink("Makefile.am.save");


print << "EOP";
Your test unit has been created now as ${testClassLowerCaseName}.cpp.
EOP

}
else
{
# user cancelled
print "Test unit not created\n";
}

9 changes: 9 additions & 0 deletions tests/src/raster/test_suite_builder.sh
@@ -0,0 +1,9 @@
#!/bin/bash
LIST=`ls ../../../src/raster/ |grep .cpp |grep ^qgs |grep -v ~$ |grep -v moc.cpp$ | sed 's/.cpp//g' |awk '$1=$1' RS= |sort`
for FILE in $LIST
do
CLASSNAME=`grep -o "::Qgs[A-Za-z0-9]*(" ../../../src/raster/${FILE}.cpp |head -1 | sed 's/:://g'| sed 's/(//g'`
./test_builder.pl $CLASSNAME
#svn add test${FILE}.cpp
done
make install
20 changes: 20 additions & 0 deletions tests/src/raster/test_template.cpp
@@ -0,0 +1,20 @@
#include <QtTest>
#include <QObject>
#include <QString>
#include <QObject>
//header for class being tested
#include <[testClassLowerCaseName].h>

class Test[testClassCamelCaseName]: public QObject
{
Q_OBJECT;
private slots:
[TestMethods]
};

QTEST_MAIN(Test[testClassCamelCaseName])
#include "test[testClassLowerCaseName].moc.cpp"




0 comments on commit 2f61769

Please sign in to comment.