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