#!/usr/bin/perl # #This is a test suite to be used with the banana print program #For more documentation on the theater program, please see its documentation # #To use, simply type ./testbanana.pl and it will run on its own. # #Note: This file must be local to the banana files! use strict; use Test::More 'no_plan'; use DBI; #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($rootdir $program $username $password $dbname $host); $rootdir = "/clients/users/smithsh1/cs345/assign7/"; $program = "banana.pl"; $username = "smithsh1"; $password = "smithsh1"; $dbname = "smithsh1"; $host = "millie"; #END DEFAULTS diag( "Testing Suite for Lab 4\n" ); #Run the program. Test that it can be run ok( !system("./$program > testout.dat"), 'Testing that program runs without arguments' ); #Database variables to connect to DB for testing my $dbh; my $sth; my $result; ok( $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host", $username, $password), 'Connecting to the database'); ok( $sth = $dbh->prepare("SELECT * FROM produced"), 'Preparing Select * statement on database'); ok( $sth->execute, 'Executing Select * statement on database'); ok( $sth->rows > 0, 'Testing that number of rows returned is greater than 0' ); #Test that the database has been populated with correct data while( my @data = $sth->fetchrow_array() ){ ok( $data[1] =~ /\w*/, "Testing country data for row with id of $data[0]"); ok( $data[2] =~ /[\d,]*/, "Testing gross data for row with id of $data[0]"); ok( $data[3] =~ /[\d,]*/, "Testing percapita data for row with id of $data[0]"); ok( $data[4] =~ /\w*/, "Testing source data for row with id of $data[0]"); ok( $data[5] =~ /.*/, "Testing sourceurl data for row with id of $data[0]"); ok( $data[6] =~ /\d\d\d\d/, "Testing datayear data for row with id of $data[0]"); ok( $data[7] =~ /\d*/, "Testing grossrank data for row with id of $data[0]"); ok( $data[8] =~ /\d*/, "Testing percaprank data for row with id of $data[0]"); ok( $data[9] =~ /\w*/, "Testing percapsize data for row with id of $data[0]"); }