#!/usr/bin/perl # #This is a test suite to be used with the Kerasotes theater program #For more documentation on the theater program, please see its documentation # #To use, simply type ./testtheater.pl and it will run on its own. # #Note: This file must be local to the kerasotes theater files! use strict; use Test::More tests => 13; use File::stat; use Time::localtime; #DEFAULT VARIABLE SECTION #The variables in this section must be modified to match the installation #Failure to do so will cause test failures! use vars qw($program $xmlfile $siteaddress $defaultlatlng $imagefolder); $program = "generate-xml"; $xmlfile = "kerasotes.xml"; $siteaddress = "http://cs.earlham.edu/~smithsh1/journal/theaters"; $defaultlatlng = "-84.887924, 39.82805"; $imagefolder = "images"; #END DEFAULTS diag( "Testing Suite for Lab 2\n" ); #Test to ensure the program is ran regularly my $currenttime = ctime(); my $runtime = ctime(stat($program)->mtime); my @splitdate1 = split(/\s/, $runtime); my @splitdate2 = split(/\s/, $currenttime); ok( $splitdate1[1] eq $splitdate2[1], 'Testing if the program has been run this month' ); ok( $splitdate1[2] == $splitdate2[2], 'Testing if the program has been run today'); #Test command line options SKIP:{ skip('This takes too long to sit through everytime.'); ok ( !system("./$program"), 'Testing that the program runs without command line args'); ok ( !system("./$program -v > verboseout.dat"), 'Testing that verbose mode runs.'); } ok ( system("./$program -f > testout.dat"), 'Testing that bad options fail gracefully'); #Testing the output generated ok( my $homepage = `wget -U \"Mozilla/5.0\" http://kerasotes.com/Home.aspx -q -O -`, 'Testing that the Kerasotes homepage is accessible for scraping'); $homepage =~ /(\d\d)( locations)/; #Scans for line containing ## locations. my $numberoflocations = $1 + 1; #The actual number of locations is contained in $1 #There is a plus one because the website is not up to #date. They have 76 locations, not 75. However, one #of them is temporarily closed open(IN, $xmlfile); my $counter = 0; my $line; my $boolflag = 1; foreach $line (){ if( $line =~ /||<\/theaters>/ ){ $boolflag = 0; } } close(IN); ok( $counter == $numberoflocations, 'Testing that there are as many XML entries as number of locations' ); ok( $boolflag, 'Testing that all XML entries are properly formatted with correct fields.' ); #Begin Tests for the Site my $mainsite; my $javasite; ok( $mainsite = `wget -U \"Mozilla/5.0\" $siteaddress/index.html -q -O -`, 'Testing to make sure the main site exists in the proper location' ); ok( $javasite = `wget -U \"Mozilla/5.0\" $siteaddress/kerasotes.js -q -O -`, 'Testing to make sure the java functions exist in the proper location' ); ok( $javasite =~ /GLargeMapControl()/, 'Testing to make sure zoom controls are implemented on map' ); ok( $javasite =~ /GMapTypeControl()/, 'Testing to make sure satellite and hybrid controls are implemented on map' ); ok( $javasite =~ /centerAndZoom\(new GPoint\($defaultlatlng\)/, 'Testing to make sure default lat and lng is the initial focus'); #Check to make sure the image folder exist ok( opendir(DIR, $imagefolder), 'Testing if the images folder exists');