Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package gzip |
| 6 | |
| 7 | import ( |
Russ Cox | d3a412a | 2009-06-29 15:24:23 -0700 | [diff] [blame] | 8 | "bytes"; |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 9 | "io"; |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 10 | "os"; |
Nigel Tao | b58ecb1 | 2009-08-20 16:03:34 -0700 | [diff] [blame] | 11 | "testing"; |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | type gzipTest struct { |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 15 | name string; |
| 16 | desc string; |
| 17 | raw string; |
| 18 | gzip []byte; |
| 19 | err os.Error; |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 22 | var gzipTests = []gzipTest{ |
| 23 | gzipTest{ // has 1 empty fixed-huffman block |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 24 | "empty.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 25 | "empty.txt", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 26 | "", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 27 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 28 | 0x1f, 0x8b, 0x08, 0x08, 0xf7, 0x5e, 0x14, 0x4a, |
| 29 | 0x00, 0x03, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, |
| 30 | 0x74, 0x78, 0x74, 0x00, 0x03, 0x00, 0x00, 0x00, |
| 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 32 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 33 | nil, |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 34 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 35 | gzipTest{ // has 1 non-empty fixed huffman block |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 36 | "hello.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 37 | "hello.txt", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 38 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 39 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 40 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 41 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 42 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 43 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 44 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, |
| 45 | 0x00, 0x00, |
| 46 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 47 | nil, |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 48 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 49 | gzipTest{ // concatenation |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 50 | "hello.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 51 | "hello.txt x2", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 52 | "hello world\n" |
Robert Griesemer | 183eddd | 2009-11-05 18:24:24 -0800 | [diff] [blame] | 53 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 54 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 55 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 56 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 57 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 58 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 59 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, |
| 60 | 0x00, 0x00, |
| 61 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 62 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 63 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 64 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 65 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, |
| 66 | 0x00, 0x00, |
| 67 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 68 | nil, |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 69 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 70 | gzipTest{ // has a fixed huffman block with some length-distance pairs |
Nigel Tao | b58ecb1 | 2009-08-20 16:03:34 -0700 | [diff] [blame] | 71 | "shesells.txt", |
| 72 | "shesells.txt", |
| 73 | "she sells seashells by the seashore\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 74 | []byte{ |
Nigel Tao | b58ecb1 | 2009-08-20 16:03:34 -0700 | [diff] [blame] | 75 | 0x1f, 0x8b, 0x08, 0x08, 0x72, 0x66, 0x8b, 0x4a, |
| 76 | 0x00, 0x03, 0x73, 0x68, 0x65, 0x73, 0x65, 0x6c, |
| 77 | 0x6c, 0x73, 0x2e, 0x74, 0x78, 0x74, 0x00, 0x2b, |
| 78 | 0xce, 0x48, 0x55, 0x28, 0x4e, 0xcd, 0xc9, 0x29, |
| 79 | 0x06, 0x92, 0x89, 0xc5, 0x19, 0x60, 0x56, 0x52, |
| 80 | 0xa5, 0x42, 0x09, 0x58, 0x18, 0x28, 0x90, 0x5f, |
| 81 | 0x94, 0xca, 0x05, 0x00, 0x76, 0xb0, 0x3b, 0xeb, |
| 82 | 0x24, 0x00, 0x00, 0x00, |
| 83 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 84 | nil, |
Nigel Tao | b58ecb1 | 2009-08-20 16:03:34 -0700 | [diff] [blame] | 85 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 86 | gzipTest{ // has dynamic huffman blocks |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 87 | "gettysburg", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 88 | "gettysburg", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 89 | " Four score and seven years ago our fathers brought forth on\n" |
Robert Griesemer | 183eddd | 2009-11-05 18:24:24 -0800 | [diff] [blame] | 90 | "this continent, a new nation, conceived in Liberty, and dedicated\n" |
| 91 | "to the proposition that all men are created equal.\n" |
| 92 | " Now we are engaged in a great Civil War, testing whether that\n" |
| 93 | "nation, or any nation so conceived and so dedicated, can long\n" |
| 94 | "endure.\n" |
| 95 | " We are met on a great battle-field of that war.\n" |
| 96 | " We have come to dedicate a portion of that field, as a final\n" |
| 97 | "resting place for those who here gave their lives that that\n" |
| 98 | "nation might live. It is altogether fitting and proper that\n" |
| 99 | "we should do this.\n" |
| 100 | " But, in a larger sense, we can not dedicate — we can not\n" |
| 101 | "consecrate — we can not hallow — this ground.\n" |
| 102 | " The brave men, living and dead, who struggled here, have\n" |
| 103 | "consecrated it, far above our poor power to add or detract.\n" |
| 104 | "The world will little note, nor long remember what we say here,\n" |
| 105 | "but it can never forget what they did here.\n" |
| 106 | " It is for us the living, rather, to be dedicated here to the\n" |
| 107 | "unfinished work which they who fought here have thus far so\n" |
| 108 | "nobly advanced. It is rather for us to be here dedicated to\n" |
| 109 | "the great task remaining before us — that from these honored\n" |
| 110 | "dead we take increased devotion to that cause for which they\n" |
| 111 | "gave the last full measure of devotion —\n" |
| 112 | " that we here highly resolve that these dead shall not have\n" |
| 113 | "died in vain — that this nation, under God, shall have a new\n" |
| 114 | "birth of freedom — and that government of the people, by the\n" |
| 115 | "people, for the people, shall not perish from this earth.\n" |
| 116 | "\n" |
| 117 | "Abraham Lincoln, November 19, 1863, Gettysburg, Pennsylvania\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 118 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 119 | 0x1f, 0x8b, 0x08, 0x08, 0xd1, 0x12, 0x2b, 0x4a, |
| 120 | 0x00, 0x03, 0x67, 0x65, 0x74, 0x74, 0x79, 0x73, |
| 121 | 0x62, 0x75, 0x72, 0x67, 0x00, 0x65, 0x54, 0xcd, |
| 122 | 0x6e, 0xd4, 0x30, 0x10, 0xbe, 0xfb, 0x29, 0xe6, |
| 123 | 0x01, 0x42, 0xa5, 0x0a, 0x09, 0xc1, 0x11, 0x90, |
| 124 | 0x40, 0x48, 0xa8, 0xe2, 0x80, 0xd4, 0xf3, 0x24, |
| 125 | 0x9e, 0x24, 0x56, 0xbd, 0x9e, 0xc5, 0x76, 0x76, |
| 126 | 0x95, 0x1b, 0x0f, 0xc1, 0x13, 0xf2, 0x24, 0x7c, |
| 127 | 0x63, 0x77, 0x9b, 0x4a, 0x5c, 0xaa, 0x6e, 0x6c, |
| 128 | 0xcf, 0x7c, 0x7f, 0x33, 0x44, 0x5f, 0x74, 0xcb, |
| 129 | 0x54, 0x26, 0xcd, 0x42, 0x9c, 0x3c, 0x15, 0xb9, |
| 130 | 0x48, 0xa2, 0x5d, 0x38, 0x17, 0xe2, 0x45, 0xc9, |
| 131 | 0x4e, 0x67, 0xae, 0xab, 0xe0, 0xf7, 0x98, 0x75, |
| 132 | 0x5b, 0xd6, 0x4a, 0xb3, 0xe6, 0xba, 0x92, 0x26, |
| 133 | 0x57, 0xd7, 0x50, 0x68, 0xd2, 0x54, 0x43, 0x92, |
| 134 | 0x54, 0x07, 0x62, 0x4a, 0x72, 0xa5, 0xc4, 0x35, |
| 135 | 0x68, 0x1a, 0xec, 0x60, 0x92, 0x70, 0x11, 0x4f, |
| 136 | 0x21, 0xd1, 0xf7, 0x30, 0x4a, 0xae, 0xfb, 0xd0, |
| 137 | 0x9a, 0x78, 0xf1, 0x61, 0xe2, 0x2a, 0xde, 0x55, |
| 138 | 0x25, 0xd4, 0xa6, 0x73, 0xd6, 0xb3, 0x96, 0x60, |
| 139 | 0xef, 0xf0, 0x9b, 0x2b, 0x71, 0x8c, 0x74, 0x02, |
| 140 | 0x10, 0x06, 0xac, 0x29, 0x8b, 0xdd, 0x25, 0xf9, |
| 141 | 0xb5, 0x71, 0xbc, 0x73, 0x44, 0x0f, 0x7a, 0xa5, |
| 142 | 0xab, 0xb4, 0x33, 0x49, 0x0b, 0x2f, 0xbd, 0x03, |
| 143 | 0xd3, 0x62, 0x17, 0xe9, 0x73, 0xb8, 0x84, 0x48, |
| 144 | 0x8f, 0x9c, 0x07, 0xaa, 0x52, 0x00, 0x6d, 0xa1, |
| 145 | 0xeb, 0x2a, 0xc6, 0xa0, 0x95, 0x76, 0x37, 0x78, |
| 146 | 0x9a, 0x81, 0x65, 0x7f, 0x46, 0x4b, 0x45, 0x5f, |
| 147 | 0xe1, 0x6d, 0x42, 0xe8, 0x01, 0x13, 0x5c, 0x38, |
| 148 | 0x51, 0xd4, 0xb4, 0x38, 0x49, 0x7e, 0xcb, 0x62, |
| 149 | 0x28, 0x1e, 0x3b, 0x82, 0x93, 0x54, 0x48, 0xf1, |
| 150 | 0xd2, 0x7d, 0xe4, 0x5a, 0xa3, 0xbc, 0x99, 0x83, |
| 151 | 0x44, 0x4f, 0x3a, 0x77, 0x36, 0x57, 0xce, 0xcf, |
| 152 | 0x2f, 0x56, 0xbe, 0x80, 0x90, 0x9e, 0x84, 0xea, |
| 153 | 0x51, 0x1f, 0x8f, 0xcf, 0x90, 0xd4, 0x60, 0xdc, |
| 154 | 0x5e, 0xb4, 0xf7, 0x10, 0x0b, 0x26, 0xe0, 0xff, |
| 155 | 0xc4, 0xd1, 0xe5, 0x67, 0x2e, 0xe7, 0xc8, 0x93, |
| 156 | 0x98, 0x05, 0xb8, 0xa8, 0x45, 0xc0, 0x4d, 0x09, |
| 157 | 0xdc, 0x84, 0x16, 0x2b, 0x0d, 0x9a, 0x21, 0x53, |
| 158 | 0x04, 0x8b, 0xd2, 0x0b, 0xbd, 0xa2, 0x4c, 0xa7, |
| 159 | 0x60, 0xee, 0xd9, 0xe1, 0x1d, 0xd1, 0xb7, 0x4a, |
| 160 | 0x30, 0x8f, 0x63, 0xd5, 0xa5, 0x8b, 0x33, 0x87, |
| 161 | 0xda, 0x1a, 0x18, 0x79, 0xf3, 0xe3, 0xa6, 0x17, |
| 162 | 0x94, 0x2e, 0xab, 0x6e, 0xa0, 0xe3, 0xcd, 0xac, |
| 163 | 0x50, 0x8c, 0xca, 0xa7, 0x0d, 0x76, 0x37, 0xd1, |
| 164 | 0x23, 0xe7, 0x05, 0x57, 0x8b, 0xa4, 0x22, 0x83, |
| 165 | 0xd9, 0x62, 0x52, 0x25, 0xad, 0x07, 0xbb, 0xbf, |
| 166 | 0xbf, 0xff, 0xbc, 0xfa, 0xee, 0x20, 0x73, 0x91, |
| 167 | 0x29, 0xff, 0x7f, 0x02, 0x71, 0x62, 0x84, 0xb5, |
| 168 | 0xf6, 0xb5, 0x25, 0x6b, 0x41, 0xde, 0x92, 0xb7, |
| 169 | 0x76, 0x3f, 0x91, 0x91, 0x31, 0x1b, 0x41, 0x84, |
| 170 | 0x62, 0x30, 0x0a, 0x37, 0xa4, 0x5e, 0x18, 0x3a, |
| 171 | 0x99, 0x08, 0xa5, 0xe6, 0x6d, 0x59, 0x22, 0xec, |
| 172 | 0x33, 0x39, 0x86, 0x26, 0xf5, 0xab, 0x66, 0xc8, |
| 173 | 0x08, 0x20, 0xcf, 0x0c, 0xd7, 0x47, 0x45, 0x21, |
| 174 | 0x0b, 0xf6, 0x59, 0xd5, 0xfe, 0x5c, 0x8d, 0xaa, |
| 175 | 0x12, 0x7b, 0x6f, 0xa1, 0xf0, 0x52, 0x33, 0x4f, |
| 176 | 0xf5, 0xce, 0x59, 0xd3, 0xab, 0x66, 0x10, 0xbf, |
| 177 | 0x06, 0xc4, 0x31, 0x06, 0x73, 0xd6, 0x80, 0xa2, |
| 178 | 0x78, 0xc2, 0x45, 0xcb, 0x03, 0x65, 0x39, 0xc9, |
| 179 | 0x09, 0xd1, 0x06, 0x04, 0x33, 0x1a, 0x5a, 0xf1, |
| 180 | 0xde, 0x01, 0xb8, 0x71, 0x83, 0xc4, 0xb5, 0xb3, |
| 181 | 0xc3, 0x54, 0x65, 0x33, 0x0d, 0x5a, 0xf7, 0x9b, |
| 182 | 0x90, 0x7c, 0x27, 0x1f, 0x3a, 0x58, 0xa3, 0xd8, |
| 183 | 0xfd, 0x30, 0x5f, 0xb7, 0xd2, 0x66, 0xa2, 0x93, |
| 184 | 0x1c, 0x28, 0xb7, 0xe9, 0x1b, 0x0c, 0xe1, 0x28, |
| 185 | 0x47, 0x26, 0xbb, 0xe9, 0x7d, 0x7e, 0xdc, 0x96, |
| 186 | 0x10, 0x92, 0x50, 0x56, 0x7c, 0x06, 0xe2, 0x27, |
| 187 | 0xb4, 0x08, 0xd3, 0xda, 0x7b, 0x98, 0x34, 0x73, |
| 188 | 0x9f, 0xdb, 0xf6, 0x62, 0xed, 0x31, 0x41, 0x13, |
| 189 | 0xd3, 0xa2, 0xa8, 0x4b, 0x3a, 0xc6, 0x1d, 0xe4, |
| 190 | 0x2f, 0x8c, 0xf8, 0xfb, 0x97, 0x64, 0xf4, 0xb6, |
| 191 | 0x2f, 0x80, 0x5a, 0xf3, 0x56, 0xe0, 0x40, 0x50, |
| 192 | 0xd5, 0x19, 0xd0, 0x1e, 0xfc, 0xca, 0xe5, 0xc9, |
| 193 | 0xd4, 0x60, 0x00, 0x81, 0x2e, 0xa3, 0xcc, 0xb6, |
| 194 | 0x52, 0xf0, 0xb4, 0xdb, 0x69, 0x99, 0xce, 0x7a, |
| 195 | 0x32, 0x4c, 0x08, 0xed, 0xaa, 0x10, 0x10, 0xe3, |
| 196 | 0x6f, 0xee, 0x99, 0x68, 0x95, 0x9f, 0x04, 0x71, |
| 197 | 0xb2, 0x49, 0x2f, 0x62, 0xa6, 0x5e, 0xb4, 0xef, |
| 198 | 0x02, 0xed, 0x4f, 0x27, 0xde, 0x4a, 0x0f, 0xfd, |
| 199 | 0xc1, 0xcc, 0xdd, 0x02, 0x8f, 0x08, 0x16, 0x54, |
| 200 | 0xdf, 0xda, 0xca, 0xe0, 0x82, 0xf1, 0xb4, 0x31, |
| 201 | 0x7a, 0xa9, 0x81, 0xfe, 0x90, 0xb7, 0x3e, 0xdb, |
| 202 | 0xd3, 0x35, 0xc0, 0x20, 0x80, 0x33, 0x46, 0x4a, |
| 203 | 0x63, 0xab, 0xd1, 0x0d, 0x29, 0xd2, 0xe2, 0x84, |
| 204 | 0xb8, 0xdb, 0xfa, 0xe9, 0x89, 0x44, 0x86, 0x7c, |
| 205 | 0xe8, 0x0b, 0xe6, 0x02, 0x6a, 0x07, 0x9b, 0x96, |
| 206 | 0xd0, 0xdb, 0x2e, 0x41, 0x4c, 0xa1, 0xd5, 0x57, |
| 207 | 0x45, 0x14, 0xfb, 0xe3, 0xa6, 0x72, 0x5b, 0x87, |
| 208 | 0x6e, 0x0c, 0x6d, 0x5b, 0xce, 0xe0, 0x2f, 0xe2, |
| 209 | 0x21, 0x81, 0x95, 0xb0, 0xe8, 0xb6, 0x32, 0x0b, |
| 210 | 0xb2, 0x98, 0x13, 0x52, 0x5d, 0xfb, 0xec, 0x63, |
| 211 | 0x17, 0x8a, 0x9e, 0x23, 0x22, 0x36, 0xee, 0xcd, |
| 212 | 0xda, 0xdb, 0xcf, 0x3e, 0xf1, 0xc7, 0xf1, 0x01, |
| 213 | 0x12, 0x93, 0x0a, 0xeb, 0x6f, 0xf2, 0x02, 0x15, |
| 214 | 0x96, 0x77, 0x5d, 0xef, 0x9c, 0xfb, 0x88, 0x91, |
| 215 | 0x59, 0xf9, 0x84, 0xdd, 0x9b, 0x26, 0x8d, 0x80, |
| 216 | 0xf9, 0x80, 0x66, 0x2d, 0xac, 0xf7, 0x1f, 0x06, |
| 217 | 0xba, 0x7f, 0xff, 0xee, 0xed, 0x40, 0x5f, 0xa5, |
| 218 | 0xd6, 0xbd, 0x8c, 0x5b, 0x46, 0xd2, 0x7e, 0x48, |
| 219 | 0x4a, 0x65, 0x8f, 0x08, 0x42, 0x60, 0xf7, 0x0f, |
| 220 | 0xb9, 0x16, 0x0b, 0x0c, 0x1a, 0x06, 0x00, 0x00, |
| 221 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 222 | nil, |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 223 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 224 | gzipTest{ // has 1 non-empty fixed huffman block then garbage |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 225 | "hello.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 226 | "hello.txt + garbage", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 227 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 228 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 229 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 230 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 231 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 232 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 233 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 234 | 0x00, 0x00, 'g', 'a', 'r', 'b', 'a', 'g', 'e', '!', '!', '!', |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 235 | }, |
| 236 | HeaderError, |
| 237 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 238 | gzipTest{ // has 1 non-empty fixed huffman block not enough header |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 239 | "hello.txt", |
| 240 | "hello.txt + garbage", |
| 241 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 242 | []byte{ |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 243 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 244 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 245 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 246 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 247 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, |
| 248 | 0x00, 0x00, gzipID1, |
| 249 | }, |
| 250 | io.ErrUnexpectedEOF, |
| 251 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 252 | gzipTest{ // has 1 non-empty fixed huffman block but corrupt checksum |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 253 | "hello.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 254 | "hello.txt + corrupt checksum", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 255 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 256 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 257 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 258 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 259 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 260 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 261 | 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0c, 0x00, |
| 262 | 0x00, 0x00, |
| 263 | }, |
| 264 | ChecksumError, |
| 265 | }, |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 266 | gzipTest{ // has 1 non-empty fixed huffman block but corrupt size |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 267 | "hello.txt", |
Russ Cox | 64684cc | 2009-06-22 13:26:13 -0700 | [diff] [blame] | 268 | "hello.txt + corrupt size", |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 269 | "hello world\n", |
Russ Cox | 094f1d5 | 2009-10-08 15:14:54 -0700 | [diff] [blame] | 270 | []byte{ |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 271 | 0x1f, 0x8b, 0x08, 0x08, 0xc8, 0x58, 0x13, 0x4a, |
| 272 | 0x00, 0x03, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, |
| 273 | 0x74, 0x78, 0x74, 0x00, 0xcb, 0x48, 0xcd, 0xc9, |
| 274 | 0xc9, 0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, |
| 275 | 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0xff, 0x00, |
| 276 | 0x00, 0x00, |
| 277 | }, |
| 278 | ChecksumError, |
| 279 | }, |
| 280 | } |
| 281 | |
Russ Cox | 52cf67a | 2009-08-20 10:18:48 -0700 | [diff] [blame] | 282 | func TestInflater(t *testing.T) { |
Russ Cox | d3a412a | 2009-06-29 15:24:23 -0700 | [diff] [blame] | 283 | b := new(bytes.Buffer); |
Russ Cox | ca6a0fe | 2009-09-15 09:41:59 -0700 | [diff] [blame] | 284 | for _, tt := range gzipTests { |
Russ Cox | 52cf67a | 2009-08-20 10:18:48 -0700 | [diff] [blame] | 285 | in := bytes.NewBuffer(tt.gzip); |
| 286 | gzip, err := NewInflater(in); |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 287 | if err != nil { |
Russ Cox | 52cf67a | 2009-08-20 10:18:48 -0700 | [diff] [blame] | 288 | t.Errorf("%s: NewInflater: %s", tt.name, err); |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 289 | continue; |
| 290 | } |
Nigel Tao | 70eef67 | 2009-09-10 21:33:44 -0700 | [diff] [blame] | 291 | defer gzip.Close(); |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 292 | if tt.name != gzip.Name { |
Robert Griesemer | 40621d5 | 2009-11-09 12:07:39 -0800 | [diff] [blame] | 293 | t.Errorf("%s: got name %s", tt.name, gzip.Name) |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 294 | } |
| 295 | b.Reset(); |
Rob Pike | 4d310f2 | 2009-11-01 20:59:49 -0800 | [diff] [blame] | 296 | n, err := io.Copy(b, gzip); |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 297 | if err != tt.err { |
Robert Griesemer | 40621d5 | 2009-11-09 12:07:39 -0800 | [diff] [blame] | 298 | t.Errorf("%s: io.Copy: %v want %v", tt.name, err, tt.err) |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 299 | } |
Rob Pike | 7be7700 | 2009-09-17 23:51:06 -0700 | [diff] [blame] | 300 | s := b.String(); |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 301 | if s != tt.raw { |
Robert Griesemer | 40621d5 | 2009-11-09 12:07:39 -0800 | [diff] [blame] | 302 | t.Errorf("%s: got %d-byte %q want %d-byte %q", tt.name, n, s, len(tt.raw), tt.raw) |
Russ Cox | f52c026 | 2009-06-06 21:56:04 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | } |