]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/test_http_range.cc
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 64 HTTP Range Header */
13 #include "HttpHeader.h"
14 #include "HttpHeaderRange.h"
16 /** \todo CLEANUP: This file should be called something_stub.cc */
18 void httpHeaderPutStr(HttpHeader
* hdr
, Http::HdrType type
, const char *str
)
20 fatal ("dummy function\n");
23 HttpHeaderEntry
*httpHeaderGetEntry(const HttpHeader
* hdr
, HttpHeaderPos
* pos
)
25 fatal ("dummy function\n");
29 String
httpHeaderGetList(const HttpHeader
* hdr
, Http::HdrType id
)
31 fatal ("dummy function\n");
35 int httpHeaderHas(const HttpHeader
* hdr
, Http::HdrType type
)
37 fatal ("dummy function\n");
41 void httpHeaderPutContRange(HttpHeader
* hdr
, const HttpHdrContRange
* cr
)
43 fatal ("dummy function\n");
47 testRangeParser(char const *rangestring
)
49 String
aString (rangestring
);
50 HttpHdrRange
*range
= HttpHdrRange::ParseCreate (&aString
);
55 HttpHdrRange
copy(*range
);
57 assert (copy
.specs
.size() == range
->specs
.size());
59 HttpHdrRange::iterator pos
= range
->begin();
67 rangeFromString(char const *rangestring
)
69 String
aString (rangestring
);
70 HttpHdrRange
*range
= HttpHdrRange::ParseCreate (&aString
);
81 HttpHdrRange
*range
=rangeFromString("bytes=0-3, 1-, -2");
82 assert (range
->specs
.size() == 3);
84 HttpHdrRange::iterator i
= range
->begin();
86 while (i
!= range
->end()) {
91 assert (counter
== 3);
93 assert (i
- range
->begin() == 0);
95 assert (i
- range
->begin() == 1);
96 assert (i
- range
->end() == -2);
100 testRangeCanonization()
102 HttpHdrRange
*range
=rangeFromString("bytes=0-3, 1-, -2");
103 assert (range
->specs
.size() == 3);
105 /* 0-3 needs a content length of 4 */
106 /* This passes in the extant code - but should it? */
108 if (!range
->canonize(3))
111 assert (range
->specs
.size() == 3);
115 range
=rangeFromString("bytes=0-3, 1-, -2");
117 assert (range
->specs
.size() == 3);
119 /* 0-3 needs a content length of 4 */
120 if (!range
->canonize(4))
125 range
=rangeFromString("bytes=3-6");
127 assert (range
->specs
.size() == 1);
129 /* 3-6 needs a content length of 4 or more */
130 if (range
->canonize(3))
135 range
=rangeFromString("bytes=3-6");
137 assert (range
->specs
.size() == 1);
139 /* 3-6 needs a content length of 4 or more */
140 if (!range
->canonize(4))
145 range
=rangeFromString("bytes=1-1,2-3");
147 assert (range
->specs
.size()== 2);
149 if (!range
->canonize(4))
152 assert (range
->specs
.size() == 2);
158 main(int argc
, char **argv
)
162 /* enable for debugging to console */
163 // _db_init (NULL, NULL);
164 // Debug::Levels[64] = 9;
165 testRangeParser("bytes=0-3");
166 testRangeParser("bytes=-3");
167 testRangeParser("bytes=1-");
168 testRangeParser("bytes=0-3, 1-, -2");
170 testRangeCanonization();
171 } catch (const std::exception
&e
) {
172 printf("Error: dying from an unhandled exception: %s\n", e
.what());
175 printf("Error: dying from an unhandled exception.\n");