Skip to content

Commit

Permalink
Added directory and beginnings of test framework for gui lib
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5247 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Apr 10, 2006
1 parent 58a71bb commit dc29cd3
Show file tree
Hide file tree
Showing 9 changed files with 750 additions and 1 deletion.
2 changes: 2 additions & 0 deletions configure.in
Expand Up @@ -504,7 +504,9 @@ AC_CONFIG_FILES([
tests/Makefile
tests/src/Makefile
tests/src/core/Makefile
tests/src/gui/Makefile
qgis.spec
src/plugins/qgis_community/Makefile
])

AC_OUTPUT
Expand Down
1 change: 1 addition & 0 deletions src/plugins/Makefile.am
Expand Up @@ -14,6 +14,7 @@ endif


SUBDIRS = $(GEOPROCESSING) \
qgis_community \
$(SPIT) \
$(GRASS) \
$(COMMUNITY) \
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Makefile.am
Expand Up @@ -8,5 +8,6 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

SUBDIRS = core
SUBDIRS = core \
gui

52 changes: 52 additions & 0 deletions tests/src/gui/Makefile.am
@@ -0,0 +1,52 @@
# 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 = testqgisapp

#
# 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/ui \
-I../../../src/gui

#
# Instruction for running the qt4 meta object compiler
#

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

BUILT_SOURCES = $(testqgisapp_MOC)

CLEANFILES = $(BUILT_SOURCES)

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

testqgisapp_MOC = testqgisapp.moc.cpp
testqgisapp_SOURCES = testqgisapp.cpp
testqgisapp_LDADD = $(GLOBALLDADD)
testqgisapp_CXXFLAGS = $(GLOBALCXXFLAGS)
7 changes: 7 additions & 0 deletions tests/src/gui/runtests.sh
@@ -0,0 +1,7 @@
#!/bin/bash
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=`
for FILE in $LIST;
do
echo "Running $FILE"
./${FILE} | tail -2 |head -1
done
173 changes: 173 additions & 0 deletions tests/src/gui/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/gui dir
$myDir = fastgetcwd;
$sourceDir = "../../../src/gui";
print "\n\nChecking that we are in the <qgis dir>/test/src/gui/ directory....";
if ($myDir =~ m/tests\/src\/gui$/)
{
print "yes\n";
}
else
{
print "no\n";
print $myDir;
print "\nPlease relocate to the /test/src/gui/ 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/gui/test_suite_builder.sh
@@ -0,0 +1,9 @@
#!/bin/bash
LIST=`ls ../../../src/gui/ |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/gui/${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/gui/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 dc29cd3

Please sign in to comment.