4
#####################################################
5
# A script to automate creation of a new unit test
8
#####################################################
9
# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ #
11
#make sure we are in a the tests/src/raster dir
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$/)
23
print "\nPlease relocate to the /test/src/raster/ directory before attempting to run this script.\n";
26
# get the needed information from the user
31
$testClass=@ARGV[ 0 ];
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";
42
$testClassLowerCaseName = lc($testClass); #todo convert to lower case
45
# Check source file is ok
50
print "ClassName not supplied ...exiting...";
53
print "Checking if source class exists in filesystem ...";
54
if (-e "${sourceDir}/${testClassLowerCaseName}.cpp" )
60
print "no, exiting\n";
61
print "${sourceDir}/${testClassLowerCaseName}.cpp does not exist!\n";
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';
72
if(m/${testClass}::[A-Za-z0-9]*\(/)
74
#get the matched part of the line
80
if ($lastLine eq $line)
86
#add it to our stub code
87
$stubString = $stubString . " void $line()\n\{\n\n\};\n";
88
#show the user the list
98
print "-----------------------------\n";
99
print "Create the unit test? [y/n]: ";
108
if(($createIt eq 'y') || ($createIt eq 'Y'))
111
# its a go -- create the unit test and modify the build files
113
system("cp test_template.cpp test$testClassLowerCaseName.cpp");
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
125
if(/^\s*bin_PROGRAMS =*/)
127
# add our application binary name to the next line
129
print MAKEFILEMOD "\t\ttest$testClassLowerCaseName \\\n";
131
elsif(/^\s*BUILT_SOURCES =*/)
133
# add our application binary name to the next line
135
print MAKEFILEMOD "\t\t\$(test${testClassLowerCaseName}_MOC) \\\n";
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";
149
# close the Makefile file handles
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");
163
Your test unit has been created now as ${testClassLowerCaseName}.cpp.
171
print "Test unit not created\n";