MCPcopy Create free account
hub / github.com/apache/trafficserver / testParseRange

Function testParseRange

plugins/slice/unit-tests/slice_test.cc:85–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85std::string
86testParseRange()
87{
88 std::ostringstream oss;
89
90 std::vector<std::string> const teststrings = {
91 "bytes=0-1023", "bytes=1-1024", "bytes=11-11",
92 "bytes=1-", // 2nd byte to end
93 "Range: bytes=-13", // final 13 bytes
94 "bytes=3-17", // ,23-29" // open
95 "bytes=3 -17 ", //,18-29" // adjacent
96 "bytes=3- 17", //, 11-29" // overlapping
97 "bytes=3 - 11", //,13-17 , 23-29" // unsorted triplet
98 "bytes=3-11 ", //,13-17, 23-29" // unsorted triplet
99 "bytes=0-0", //,-1" // first and last bytes
100 "bytes=-20", // last 20 bytes of file
101 "bytes=-60-50", // invalid fully negative
102 "bytes=17-13", // degenerate
103 "bytes 0-1023/146515" // this should be rejected (Content-range)
104 }; // invalid
105
106 std::vector<Range> const exps = {
107 Range{0, 1023 + 1 },
108 Range{1, 1024 + 1 },
109 Range{11, 11 + 1 },
110 Range{1, Range::maxval},
111 Range{-1, -1 },
112 Range{3, 17 + 1 },
113 Range{3, 17 + 1 },
114 Range{3, 17 + 1 },
115 Range{3, 11 + 1 },
116 Range{3, 11 + 1 },
117 Range{0, 1 },
118 Range{-20, 0 },
119 Range{-1, -1 },
120 Range{-1, -1 },
121 Range{-1, -1 }
122 };
123
124 std::vector<bool> const expsres = {true, true, true, true, false, true, true, true, true, true, true, true, false, false, false};
125
126 assert(exps.size() == teststrings.size());
127
128 std::vector<Range> gots;
129 gots.reserve(exps.size());
130 std::vector<bool> gotsres;
131
132 for (std::string const &str : teststrings) {
133 Range rng;
134 gotsres.push_back(rng.fromStringClosed(str.c_str()));
135 gots.push_back(rng);
136 }
137
138 assert(gots.size() == exps.size());
139
140 for (size_t index(0); index < gots.size(); ++index) {
141 if (exps[index] != gots[index] || expsres[index] != gotsres[index]) {
142 oss << "Error parsing index: " << index << std::endl;

Callers

nothing calls this directly

Calls 6

sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
fromStringClosedMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected