| 1 | # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| 2 | # contributor license agreements. See the NOTICE file distributed with | ||
| 3 | # this work for additional information regarding copyright ownership. | ||
| 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| 5 | # (the "License"); you may not use this file except in compliance with | ||
| 6 | # the License. You may obtain a copy of the License at | ||
| 7 | # | ||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | # | ||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | # See the License for the specific language governing permissions and | ||
| 14 | # limitations under the License. | ||
| 15 | # | ||
| 16 | package Apache::TestCommon; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use warnings FATAL => 'all'; | ||
| 20 | |||
| 21 | use File::Basename; | ||
| 22 | |||
| 23 | use Apache::Test; | ||
| 24 | use Apache::TestRequest; | ||
| 25 | use Apache::TestUtil; | ||
| 26 | use Apache::TestCommonPost (); | ||
| 27 | |||
| 28 | #this module contains common tests that are called from different .t files | ||
| 29 | |||
| 30 | #t/apache/passbrigade.t | ||
| 31 | #t/apache/rwrite.t | ||
| 32 | |||
| 33 | sub run_write_test { | ||
| 34 | my $module = shift; | ||
| 35 | |||
| 36 | #1k..9k, 10k..50k, 100k, 300k, 500k, 2Mb, 4Mb, 6Mb, 10Mb | ||
| 37 | my @sizes = (1..9, 10..50, 100, 300, 500, 2000, 4000, 6000, 10_000); | ||
| 38 | my @buff_sizes = (1024, 8192); | ||
| 39 | |||
| 40 | plan tests => @sizes * @buff_sizes, [$module, 'LWP']; | ||
| 41 | |||
| 42 | my $location = "/$module"; | ||
| 43 | my $ua = Apache::TestRequest::user_agent(); | ||
| 44 | |||
| 45 | for my $buff_size (@buff_sizes) { | ||
| 46 | for my $size (@sizes) { | ||
| 47 | my $length = $size * 1024; | ||
| 48 | my $received = 0; | ||
| 49 | |||
| 50 | $ua->do_request(GET => "$location?$buff_size,$length", | ||
| 51 | sub { | ||
| 52 | my($chunk, $res) = @_; | ||
| 53 | $received += length $chunk; | ||
| 54 | }); | ||
| 55 | |||
| 56 | ok t_cmp($received, $length, 'bytes in body'); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | sub run_files_test { | ||
| 62 | my($verify, $skip_other) = @_; | ||
| 63 | |||
| 64 | my $vars = Apache::Test::vars(); | ||
| 65 | my $perlpod = $vars->{perlpod}; | ||
| 66 | |||
| 67 | my %pod = ( | ||
| 68 | files => [], | ||
| 69 | num => 0, | ||
| 70 | url => '/getfiles-perl-pod', | ||
| 71 | dir => "", | ||
| 72 | ); | ||
| 73 | |||
| 74 | if (-d $perlpod) { | ||
| 75 | my @files = map { basename $_ } <$perlpod/*.pod>; | ||
| 76 | $pod{files} = \@files; | ||
| 77 | $pod{num} = scalar @files; | ||
| 78 | $pod{dir} = $perlpod; | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | push @Apache::Test::SkipReasons, | ||
| 82 | "dir $vars->{perlpod} does not exist"; | ||
| 83 | } | ||
| 84 | |||
| 85 | my %other_files = (); | ||
| 86 | |||
| 87 | unless ($skip_other) { #allow to skip the large binary files | ||
| 88 | %other_files = map { | ||
| 89 | ("/getfiles-binary-$_", $vars->{$_}) | ||
| 90 | } qw(httpd perl); | ||
| 91 | } | ||
| 92 | |||
| 93 | my $tests = $pod{num} + keys(%other_files); | ||
| 94 | |||
| 95 | plan tests => $tests, sub { $pod{num} and have_lwp() }; | ||
| 96 | |||
| 97 | my $ua = Apache::TestRequest::user_agent(); | ||
| 98 | |||
| 99 | for my $file (@{ $pod{files} }) { | ||
| 100 | $verify->($ua, "$pod{url}/$file", "$pod{dir}/$file"); | ||
| 101 | } | ||
| 102 | |||
| 103 | for my $url (sort keys %other_files) { | ||
| 104 | $verify->($ua, $url, $other_files{$url}); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | 1; | ||
| 109 | __END__ |