Mercurial > hg > nginx-tests
annotate range_mp4.t @ 540:481d705b8610
Tests: SSL support in mail backends.
Socket is now embedded into every mail module.
Socket methods are wrapped where appropriate.
The new "SSL" extra flag specifies to accept connection over SSL.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 03 Apr 2015 00:11:38 +0300 |
parents | d5bf5942a8b2 |
children | e9064d691790 |
rev | line source |
---|---|
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for mp4 module with range filter module. |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
385
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffmpeg'); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 listen 127.0.0.1:8080; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 location / { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 mp4; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 EOF |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
385
diff
changeset
|
50 plan(skip_all => 'no lavfi') |
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
385
diff
changeset
|
51 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 system('ffmpeg -loglevel quiet -y ' |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 . "-pix_fmt yuv420p -c:v libx264 ${\($t->testdir())}/test.mp4") == 0 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 or die "Can't create mp4 file: $!"; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
385
diff
changeset
|
57 $t->run()->plan(13); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 ############################################################################### |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 # simply ensure that mp4 start argument works, we rely on this in range tests |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 my $fsz0 = http_head('/test.mp4') =~ /Content-Length: (\d+)/ && $1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 my $fsz = http_head('/test.mp4?start=1') =~ /Content-Length: (\d+)/ && $1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 isnt($fsz0, $fsz, 'mp4 start argument works'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 my $t1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 # MP4 has minimally 16 byte ftyp object at start |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $start = $fsz - 10; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 my $last = $fsz - 1; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-9'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
75 like($t1, qr/ 206 /, 'first bytes - 206 partial reply'); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like($t1, qr/Content-Length: 10/, 'first bytes - content length'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like($t1, qr/Content-Range: bytes 0-9\/$fsz/, 'first bytes - content range'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=-10'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
80 like($t1, qr/ 206 /, 'final bytes - 206 partial reply'); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 like($t1, qr/Content-Range: bytes $start-$last\/$fsz/, |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 'final bytes - content range'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-99'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
86 like($t1, qr/ 206 /, 'multi buffers - 206 partial reply'); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like($t1, qr/Content-Length: 100/, 'multi buffers - content length'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like($t1, qr/Content-Range: bytes 0-99\/$fsz/, |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 'multi buffers - content range'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 TODO: { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 local $TODO = 'multipart range on mp4'; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-10,11-99'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
95 like($t1, qr/ 206 /, 'multipart range - 206 partial reply'); |
385
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 like($t1, qr/Content-Length: 100/, 'multipart range - content length'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 like($t1, qr/Content-Range: bytes 0-10,11-99\/$fsz/, |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 'multipart range - content range'); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 ############################################################################### |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 sub http_get_range { |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 my ($url, $extra) = @_; |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 return http(<<EOF); |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 HEAD $url HTTP/1.1 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 Host: localhost |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 Connection: close |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 $extra |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 EOF |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 } |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 |
0d9aaa1c01ea
Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 ############################################################################### |