comparison image_filter_webp.t @ 1072:37c18a92115b

Tests: basic WebP tests in image filter.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 27 Oct 2016 19:29:24 +0300
parents
children 766bcbb632ee
comparison
equal deleted inserted replaced
1071:1dd57525de8b 1072:37c18a92115b
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for image filter module, WebP support.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http image_filter/)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 daemon off;
31
32 events {
33 }
34
35 http {
36 %%TEST_GLOBALS_HTTP%%
37
38 server {
39 listen 127.0.0.1:8080;
40 server_name localhost;
41
42 location /size {
43 image_filter size;
44 alias %%TESTDIR%%/;
45 }
46
47 location /test {
48 image_filter test;
49 alias %%TESTDIR%%/;
50 }
51
52 location /resize {
53 image_filter resize 1 1;
54 alias %%TESTDIR%%/;
55 }
56
57 location /quality {
58 image_filter rotate 90;
59 image_filter_webp_quality 50;
60 alias %%TESTDIR%%/;
61 }
62 location /quality_var {
63 image_filter rotate 90;
64 image_filter_webp_quality $arg_q;
65 alias %%TESTDIR%%/;
66 }
67 }
68 }
69
70 EOF
71
72 $t->try_run('no WebP support')->plan(18);
73
74 $t->write_file('webp', pack("A4LA8", "RIFF", 0x22, "WEBPVP8 ") .
75 pack("N4", 0x16000000, 0x3001009d, 0x012a0100, 0x01000ec0) .
76 pack("N2n", 0xfe25a400, 0x03700000, 0x0000));
77 $t->write_file('webpl', pack("A4LA8", "RIFF", 0x1a, "WEBPVP8L") .
78 pack("N4n", 0x0d000000, 0x2f000000, 0x10071011, 0x118888fe, 0x0700));
79 $t->write_file('webpx', pack("A4LA8", "RIFF", 0x4a, "WEBPVP8X") .
80 pack("N4", 0x0a000000, 0x10000000, 0x00000000, 0x0000414c) .
81 pack("N4", 0x50480c00, 0x00001107, 0x1011fd0f, 0x4444ff03) .
82 pack("N4", 0x00005650, 0x38201800, 0x00001401, 0x009d012a) .
83 pack("N4n", 0x01000100, 0x0000fe00, 0x000dc000, 0xfee6b500, 0x0000));
84
85 $t->write_file('webperr', pack("A4LA8", "RIFF", 0x22, "WEBPERR ") .
86 pack("N4", 0x16000000, 0x3001009d, 0x012a0100, 0x01000ec0) .
87 pack("N2n", 0xfe25a400, 0x03700000, 0x0000));
88 $t->write_file('webptrunc', substr $t->read_file('webp'), 0, 29);
89
90 ###############################################################################
91
92 my $r = http_get('/test/webp');
93 like($r, qr!Content-Type: image/webp!, 'content-type');
94 like($r, qr/RIFF/, 'content');
95
96 $r = http_get('/size/webp');
97 like($r, qr/"type": "webp"/, 'size type');
98 like($r, qr/"width": 1/, 'size width');
99 like($r, qr/"height": 1/, 'size height');
100
101 # lossless
102
103 $r = http_get('/size/webpl');
104 like($r, qr/"type": "webp"/, 'lossless type');
105 like($r, qr/"width": 1/, 'lossless width');
106 like($r, qr/"height": 1/, 'lossless height');
107
108 # extended
109
110 $r = http_get('/size/webpx');
111 like($r, qr/"type": "webp"/, 'extended type');
112 like($r, qr/"width": 1/, 'extended width');
113 like($r, qr/"height": 1/, 'extended height');
114
115 # transforms, libgd may have no WebP support
116
117 like(http_get('/quality/webp'), qr/RIFF|415/, 'quality');
118 like(http_get('/quality_var/webp?q=40'), qr/RIFF|415/, 'quality var');
119 like(http_get('/resize/webp'), qr/RIFF/, 'resize as is');
120
121 # generic error handling
122
123 like(http_get('/quality/webperr'), qr/415 Unsupported/, 'bad header');
124 like(http_get('/quality/webptrunc'), qr/415 Unsupported/, 'truncated');
125
126 like(http_get('/size/webperr'), qr/{}/, 'size - bad header');
127 like(http_get('/size/webptrunc'), qr/{}/, 'size - truncated');
128
129 ###############################################################################