Skip to content
This repository
tag: DEB_5_5_1_1_1
Fetching contributors…

Cannot retrieve contributors at this time

file 331 lines (261 sloc) 6.456 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
# $id$
#
# Copyright (C) 2002-2007 Interchange Development Group
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA.

use Cwd;
use Config;
use Errno;

$cur_dir = cwd();
$failed = 0;

if($^O =~ /cygwin|win32/) {
print "no tests supported on Windows platform.\n";
exit;
}

die "Must be in build directory\n" unless -d 'blib';
die "No tests defined for Windows\n" if $^O =~ /win32/i;

$ENV{MINIVEND_ROOT} = "$cur_dir/blib";
$ENV{MINIVEND_PORT} = 8786 unless defined $ENV{MINIVEND_PORT};

my $extra_cfg = '';

if(-f '_allow_threads') {
open(THR, ">$ENV{MINIVEND_ROOT}/_allow_threads")
or die "Can't write allow threads file: $!\n";
print THR "I agree not to hold anyone but myself responsible for the results of running an experimental system.\n";
close THR;
$^O =~ /linux/i and $extra_cfg = 'Variable MV_GETPPID_BROKEN 1';
}

open(CONFIG, ">$ENV{MINIVEND_ROOT}/interchange.cfg")
or die "open: $!\n";

print CONFIG <<EOF;
Catalog test $ENV{MINIVEND_ROOT} /test
TcpMap $ENV{MINIVEND_PORT} -
TagDir 0
TagDir etc
$extra_cfg
EOF

open(CONFIG, ">$ENV{MINIVEND_ROOT}/catalog.cfg")
or die "open: $!\n";

print CONFIG <<'EOF';
MailOrderTo info@icdevgroup.org
VendURL http:/test
SecureURL http:/test
Database products products.asc DEFAULT
EOF

mkdir ("$ENV{MINIVEND_ROOT}/etc", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/pages", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/products", 0777);
mkdir ("$ENV{MINIVEND_ROOT}/session", 0777);
if( $ENV{PERL5LIB} ) {
$ENV{PERL5LIB} .= ":$cur_dir/extra:$cur_dir/blib/lib";
}
else {
$ENV{PERL5LIB} = "$cur_dir/extra:$cur_dir/blib/lib";
}

my $testnum = 1;

open(CONFIG, ">$ENV{MINIVEND_ROOT}/products/products.asc")
or die "open: $!\n";

print CONFIG <<EOF;
sku description price
test test product 1
EOF

open(CONFIG, ">$ENV{MINIVEND_ROOT}/pages/catalog.html")
or die "open: $!\n";

for(1 .. 100) {
print CONFIG <<EOF;
test succeeded test succeeded
EOF
}

close CONFIG;

$| = 1;

print "server/unixmode.......";
if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -u} ) {
print "not ok $testnum\n";
$failed++;
}
else {
print "ok $testnum\n";
}
$testnum++;

print "server/startup........";
for(1 .. 5) {
open(PID, "$ENV{MINIVEND_ROOT}/etc/interchange.pid") or sleep $_, next;
$pid = <PID>;
$pid =~ s/\D+//g;
last;
}

for(1 .. 5) {
unless (-e "$ENV{MINIVEND_ROOT}/etc/socket") {
system "ls -l $ENV{MINIVEND_ROOT}/*";
sleep $_;
next;
}
$LINK_FILE = "$ENV{MINIVEND_ROOT}/etc/socket";
last;
}

if(! $pid or ! $LINK_FILE) {
print "not ok $testnum\n";
$failed++;
}
else {
print "ok $testnum\n";
}
$testnum++;

use Socket;
my $LINK_HOST = '127.0.0.1';
my $LINK_PORT = $ENV{MINIVEND_PORT};
my $LINK_TIMEOUT = 15;
my $ERROR_ACTION = "-none";

$ENV{SCRIPT_NAME} = "/test";
$ENV{PATH_INFO} = "/catalog";
$ENV{REMOTE_ADDR} = "TEST";
$ENV{REQUEST_METHOD} = "GET";

sub send_arguments {

my $count = @ARGV;
my $val = "arg $count\n";
for(@ARGV) {
$val .= length($_);
$val .= " $_\n";
}
return $val;
}

sub send_environment () {
my (@tmp) = keys %ENV;
my $count = @tmp;
my ($str);
my $val = "env $count\n";
for(@tmp) {
$str = "$_=$ENV{$_}";
$val .= length($str);
$val .= " $str\n";
}
return $val;
}

$SIG{PIPE} = sub { die("signal"); };
$SIG{ALRM} = sub { die("not communicating with server\n"); exit 1; };



print "link/unixmode.........";
eval {
socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!\n";

my $ok;
do {
$ok = connect(SOCK, sockaddr_un($LINK_FILE));
} while ( ! defined $ok and $!{EINTR} || $!{ENOENT});

my $undef = ! defined $ok;
die "ok=$ok def: $undef connect: $!\n" if ! $ok;

select SOCK;
$| = 1;
select STDOUT;

print SOCK send_arguments();
print SOCK send_environment();
print SOCK "end\n";


while(<SOCK>) {
$result .= $_;
}

close (SOCK) or die "close: $!\n";

};

if(length($result) > 500 and $result =~ /test succeeded/i) {
print "ok $testnum\n";
}
else {
print "not ok $testnum";
print " ($@)" if $@;
print "\n";
print <<EOF;

# When the above test fails, it may be due to your ISP or some other
# mechanism blocking port 8786.

EOF
$failed++;
}
$testnum++;

print "server/inetmode.......";
if ( system qq{$Config{'perlpath'} blib/script/interchange -q -r -i} ) {
print "not ok $testnum\n";
$failed++;
}
else {
print "ok $testnum\n";
}
$testnum++;

alarm 0;
alarm $LINK_TIMEOUT;

$result = '';

print "link/inetmode.........";
eval {
$remote = $LINK_HOST;
$port = $LINK_PORT;

if ($port =~ /\D/) { $port = getservbyname($port, 'tcp'); }

die("no port") unless $port;

$iaddr = inet_aton($remote);
$paddr = sockaddr_in($port,$iaddr);

$proto = getprotobyname('tcp');

socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";

my $ok;

do {
$ok = connect(SOCK, $paddr);
} while ( ! defined $ok and $!{EINTR});

my $undef = ! defined $ok;
die "ok=$ok def: $undef connect: $!\n" if ! $ok;

select SOCK;
$| = 1;
select STDOUT;

print SOCK send_arguments();
print SOCK send_environment();
print SOCK "end\n";


while(<SOCK>) {
$result .= $_;
}

close (SOCK) or die "close: $!\n";

};

alarm 0;

if(length($result) > 500 and $result =~ /test succeeded/i) {
print "ok $testnum\n";
}
else {
print "not ok $testnum\n";
$failed++;
}
$testnum++;

print "server/control........";
if ( system qq{$Config{'perlpath'} blib/script/interchange -q -stop} ) {
print "not ok $testnum\n";
$failed++;
}

my $pid_there;

for(1 .. 5) {
$pid_there = -f 'blib/etc/interchange.pid';
last unless $pid_there;
sleep 1;
}

if ($pid_there) {
print "not ok $testnum\n";
$failed++;
}
else {
print "ok $testnum\n";
}
$testnum++;


$testnum--;
print "$testnum tests run";
if($failed) {
print " -- $failed/$testnum failed.\n";
exit 1;
}
else {
print ", all tests successful.\n";
exit 0;
}

END {
kill 'KILL', $pid if $pid;
}
Something went wrong with that request. Please try again.