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

Function testContentRange

plugins/slice/slice_test.cc:32–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#include <vector>
31
32std::string
33testContentRange()
34{
35 std::ostringstream oss;
36
37 ContentRange null;
38 if (null.isValid()) {
39 oss << "fail: null isValid test" << std::endl;
40 }
41
42 ContentRange const exprange(1023, 1048576, 307232768);
43
44 if (!exprange.isValid()) {
45 oss << "Fail: exprange valid" << std::endl;
46 oss << exprange.m_beg << ' ' << exprange.m_end << ' ' << exprange.m_length << std::endl;
47 }
48
49 std::string const expstr("bytes 1023-1048575/307232768");
50
51 char gotbuf[1024];
52 int gotlen = sizeof(gotbuf);
53
54 bool const strstat(exprange.toStringClosed(gotbuf, &gotlen));
55
56 if (!strstat) {
57 oss << "failure status toStringClosed" << std::endl;
58 } else if ((int)expstr.size() != gotlen) {
59 oss << "Fail: expected toStringClosed length" << std::endl;
60 oss << "got: " << gotlen << " exp: " << expstr.size() << std::endl;
61 oss << "Got: " << gotbuf << std::endl;
62 oss << "Exp: " << expstr << std::endl;
63 } else if (expstr != gotbuf) {
64 oss << "Fail: expected toStringClosed value" << std::endl;
65 oss << "Got: " << gotbuf << std::endl;
66 oss << "Exp: " << expstr << std::endl;
67 }
68
69 ContentRange gotrange;
70 bool const gotstat(gotrange.fromStringClosed(expstr.c_str()));
71 if (!gotstat) {
72 oss << "fail: gotstat from string" << std::endl;
73 } else if (gotrange.m_beg != exprange.m_beg || gotrange.m_end != exprange.m_end || gotrange.m_length != exprange.m_length) {
74 oss << "fail: value compare gotrange and exprange" << std::endl;
75 }
76
77 std::string const teststr("bytes 0-1048575/30723276");
78 if (!gotrange.fromStringClosed(teststr.c_str())) {
79 oss << "fail: parse teststr" << std::endl;
80 }
81
82 return oss.str();
83}
84
85std::string
86testParseRange()

Callers

nothing calls this directly

Calls 6

isValidMethod · 0.45
toStringClosedMethod · 0.45
sizeMethod · 0.45
fromStringClosedMethod · 0.45
c_strMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected