]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | /* |
528b2c61 | 2 | * DEBUG: section 64 HTTP Range Header |
3 | * AUTHOR: Alex Rousskov | |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
528b2c61 | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
528b2c61 | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
8e46cda5 | 32 | #define SQUID_UNIT_TEST 1 |
f7f3304a | 33 | #include "squid.h" |
528b2c61 | 34 | |
e1f7507e | 35 | #if 0 |
528b2c61 | 36 | //#include "Store.h" |
528b2c61 | 37 | //#include "client_side_request.h" |
e1f7507e AJ |
38 | #endif |
39 | ||
40 | /** \todo CLEANUP: This file shoudl be called something_stub.cc */ | |
41 | ||
42 | #include "HttpHeaderRange.h" | |
43 | #include "HttpHeader.h" | |
44 | #include "Mem.h" | |
45 | ||
46 | #if 0 | |
3ad63615 | 47 | #include "acl/Checklist.h" |
e1f7507e | 48 | #endif |
528b2c61 | 49 | |
d9c252f2 | 50 | void httpHeaderPutStr(HttpHeader * hdr, http_hdr_type type, const char *str) |
528b2c61 | 51 | { |
52 | fatal ("dummy function\n"); | |
53 | } | |
54 | ||
d9c252f2 | 55 | HttpHeaderEntry *httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos) |
528b2c61 | 56 | { |
57 | fatal ("dummy function\n"); | |
58 | return NULL; | |
59 | } | |
60 | ||
d9c252f2 | 61 | String httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id) |
528b2c61 | 62 | { |
63 | fatal ("dummy function\n"); | |
30abd221 | 64 | return String(); |
528b2c61 | 65 | } |
66 | ||
d9c252f2 | 67 | int httpHeaderHas(const HttpHeader * hdr, http_hdr_type type) |
528b2c61 | 68 | { |
69 | fatal ("dummy function\n"); | |
70 | return 0; | |
71 | } | |
72 | ||
d9c252f2 | 73 | void httpHeaderPutContRange(HttpHeader * hdr, const HttpHdrContRange * cr) |
528b2c61 | 74 | { |
75 | fatal ("dummy function\n"); | |
76 | } | |
77 | ||
528b2c61 | 78 | void |
79 | testRangeParser(char const *rangestring) | |
80 | { | |
30abd221 | 81 | String aString (rangestring); |
528b2c61 | 82 | HttpHdrRange *range = HttpHdrRange::ParseCreate (&aString); |
43ae1d95 | 83 | |
528b2c61 | 84 | if (!range) |
43ae1d95 | 85 | exit (1); |
86 | ||
528b2c61 | 87 | HttpHdrRange copy(*range); |
43ae1d95 | 88 | |
528b2c61 | 89 | assert (copy.specs.count == range->specs.count); |
90 | ||
91 | HttpHdrRange::iterator pos = range->begin(); | |
43ae1d95 | 92 | |
528b2c61 | 93 | assert (*pos); |
43ae1d95 | 94 | |
00d77d6b | 95 | delete range; |
528b2c61 | 96 | } |
97 | ||
98 | HttpHdrRange * | |
99 | rangeFromString(char const *rangestring) | |
100 | { | |
30abd221 | 101 | String aString (rangestring); |
528b2c61 | 102 | HttpHdrRange *range = HttpHdrRange::ParseCreate (&aString); |
43ae1d95 | 103 | |
528b2c61 | 104 | if (!range) |
43ae1d95 | 105 | exit (1); |
106 | ||
528b2c61 | 107 | return range; |
108 | } | |
109 | ||
110 | void | |
111 | testRangeIter () | |
112 | { | |
113 | HttpHdrRange *range=rangeFromString("bytes=0-3, 1-, -2"); | |
114 | assert (range->specs.count == 3); | |
115 | size_t counter = 0; | |
116 | HttpHdrRange::iterator i = range->begin(); | |
43ae1d95 | 117 | |
528b2c61 | 118 | while (i != range->end()) { |
43ae1d95 | 119 | ++counter; |
120 | ++i; | |
528b2c61 | 121 | } |
43ae1d95 | 122 | |
528b2c61 | 123 | assert (counter == 3); |
124 | i = range->begin(); | |
125 | assert (i - range->begin() == 0); | |
126 | ++i; | |
127 | assert (i - range->begin() == 1); | |
128 | assert (i - range->end() == -2); | |
129 | } | |
130 | ||
131 | void | |
132 | testRangeCanonization() | |
133 | { | |
134 | HttpHdrRange *range=rangeFromString("bytes=0-3, 1-, -2"); | |
135 | assert (range->specs.count == 3); | |
136 | ||
137 | /* 0-3 needs a content length of 4 */ | |
138 | /* This passes in the extant code - but should it? */ | |
43ae1d95 | 139 | |
528b2c61 | 140 | if (!range->canonize(3)) |
43ae1d95 | 141 | exit(1); |
142 | ||
528b2c61 | 143 | assert (range->specs.count == 3); |
43ae1d95 | 144 | |
00d77d6b | 145 | delete range; |
43ae1d95 | 146 | |
528b2c61 | 147 | range=rangeFromString("bytes=0-3, 1-, -2"); |
43ae1d95 | 148 | |
528b2c61 | 149 | assert (range->specs.count == 3); |
43ae1d95 | 150 | |
528b2c61 | 151 | /* 0-3 needs a content length of 4 */ |
152 | if (!range->canonize(4)) | |
43ae1d95 | 153 | exit(1); |
154 | ||
00d77d6b | 155 | delete range; |
43ae1d95 | 156 | |
528b2c61 | 157 | range=rangeFromString("bytes=3-6"); |
43ae1d95 | 158 | |
528b2c61 | 159 | assert (range->specs.count == 1); |
43ae1d95 | 160 | |
528b2c61 | 161 | /* 3-6 needs a content length of 4 or more */ |
162 | if (range->canonize(3)) | |
43ae1d95 | 163 | exit(1); |
164 | ||
00d77d6b | 165 | delete range; |
528b2c61 | 166 | |
167 | range=rangeFromString("bytes=3-6"); | |
43ae1d95 | 168 | |
528b2c61 | 169 | assert (range->specs.count == 1); |
43ae1d95 | 170 | |
528b2c61 | 171 | /* 3-6 needs a content length of 4 or more */ |
172 | if (!range->canonize(4)) | |
43ae1d95 | 173 | exit(1); |
174 | ||
00d77d6b | 175 | delete range; |
43ae1d95 | 176 | |
528b2c61 | 177 | range=rangeFromString("bytes=1-1,2-3"); |
43ae1d95 | 178 | |
528b2c61 | 179 | assert (range->specs.count == 2); |
43ae1d95 | 180 | |
528b2c61 | 181 | if (!range->canonize(4)) |
43ae1d95 | 182 | exit(1); |
183 | ||
528b2c61 | 184 | assert (range->specs.count == 2); |
43ae1d95 | 185 | |
00d77d6b | 186 | delete range; |
528b2c61 | 187 | } |
188 | ||
189 | int | |
190 | main (int argc, char **argv) | |
191 | { | |
192 | Mem::Init(); | |
193 | /* enable for debugging to console */ | |
43ae1d95 | 194 | // _db_init (NULL, NULL); |
195 | // Debug::Levels[64] = 9; | |
528b2c61 | 196 | testRangeParser ("bytes=0-3"); |
197 | testRangeParser ("bytes=-3"); | |
198 | testRangeParser ("bytes=1-"); | |
199 | testRangeParser ("bytes=0-3, 1-, -2"); | |
200 | testRangeIter (); | |
201 | testRangeCanonization(); | |
202 | return 0; | |
203 | } |