ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TUriTest.C
Go to the documentation of this file.
1 // TUriTest.C - rudimentary TUri test macro - Gerhard E. Bruckner 2007-10-18
2 
3 #include <TUri.h>
4 
5 
6 Bool_t TestResolutionHelper(TUri reference, TUri nominal, TUri &base)
7 {
8  TUri actual = TUri::Transform(reference, base);
9  if (!(nominal == actual))
10  Printf("\tERROR: %s => %s (should read: %s)", reference.GetUri().Data(), actual.GetUri().Data(), nominal.GetUri().Data());
11  return (nominal == actual);
12 }
13 
14 
16 {
17  TUri base = TUri("http://a/b/c/d;p?q");
18  Bool_t success = kTRUE;
19 
20  // 5.4.1. Normal Examples
21  success &= TestResolutionHelper("g:h", "g:h", base);
22  success &= TestResolutionHelper("g", "http://a/b/c/g", base);
23  success &= TestResolutionHelper("./g", "http://a/b/c/g", base);
24  success &= TestResolutionHelper("g/", "http://a/b/c/g/", base);
25  success &= TestResolutionHelper("/g", "http://a/g", base);
26  success &= TestResolutionHelper("//g", "http://g", base);
27  success &= TestResolutionHelper("?y", "http://a/b/c/d;p?y", base);
28  success &= TestResolutionHelper("g?y", "http://a/b/c/g?y", base);
29  success &= TestResolutionHelper("#s", "http://a/b/c/d;p?q#s", base);
30  success &= TestResolutionHelper("g#s", "http://a/b/c/g#s", base);
31  success &= TestResolutionHelper("g?y#s", "http://a/b/c/g?y#s", base);
32  success &= TestResolutionHelper(";x", "http://a/b/c/;x", base);
33  success &= TestResolutionHelper("g;x", "http://a/b/c/g;x", base);
34  success &= TestResolutionHelper("g;x?y#s", "http://a/b/c/g;x?y#s", base);
35  success &= TestResolutionHelper("", "http://a/b/c/d;p?q", base);
36  success &= TestResolutionHelper(".", "http://a/b/c/", base);
37  success &= TestResolutionHelper("./", "http://a/b/c/", base);
38  success &= TestResolutionHelper("..", "http://a/b/", base);
39  success &= TestResolutionHelper("../", "http://a/b/", base);
40  success &= TestResolutionHelper("../g", "http://a/b/g", base);
41  success &= TestResolutionHelper("../..", "http://a/", base);
42  success &= TestResolutionHelper("../../", "http://a/", base);
43  success &= TestResolutionHelper("../../g", "http://a/g", base);
44  // 5.4.2. Abnormal Examples
45  success &= TestResolutionHelper("../../../g", "http://a/g", base);
46  success &= TestResolutionHelper("../../../../g", "http://a/g", base);
47  success &= TestResolutionHelper("/./g", "http://a/g", base);
48  success &= TestResolutionHelper("/../g", "http://a/g", base);
49  success &= TestResolutionHelper("g.", "http://a/b/c/g.", base);
50  success &= TestResolutionHelper(".g", "http://a/b/c/.g", base);
51  success &= TestResolutionHelper("g..", "http://a/b/c/g..", base);
52  success &= TestResolutionHelper("..g", "http://a/b/c/..g", base);
53  success &= TestResolutionHelper("./../g", "http://a/b/g", base);
54  success &= TestResolutionHelper("./g/.", "http://a/b/c/g/", base);
55  success &= TestResolutionHelper("g/./h", "http://a/b/c/g/h", base);
56  success &= TestResolutionHelper("g/../h", "http://a/b/c/h", base);
57  success &= TestResolutionHelper("g;x=1/./y", "http://a/b/c/g;x=1/y", base);
58  success &= TestResolutionHelper("g;x=1/../y", "http://a/b/c/y", base);
59  success &= TestResolutionHelper("g?y/./x", "http://a/b/c/g?y/./x", base);
60  success &= TestResolutionHelper("g?y/../x", "http://a/b/c/g?y/../x", base);
61  success &= TestResolutionHelper("g#s/./x", "http://a/b/c/g#s/./x", base);
62  success &= TestResolutionHelper("g#s/../x", "http://a/b/c/g#s/../x", base);
63  success &= TestResolutionHelper("http:g", "http:g", base);
64  return(success);
65 }
66 
67 
69 {
70  TString errors = "";
71  for (char i = 0; i < 127; i++) {
72  if (TUri::PctDecode(TUri::PctEncode(i)) != i) {
73  char buffer[10];
74  sprintf(buffer, "0x%02x, ", i);
75  errors = errors + buffer;
76  }
77  }
78  if (!errors.IsNull())
79  Printf("\tERROR at %s", errors.Data());
80  else
81  Printf("\tOK");
82  return errors.IsNull();
83 }
84 
86 {
87  TString composed = "http://user:pass@host.org/some/path/file.avi?key1=value1#anchor3";
88  TUri uri;
89  uri.SetScheme("http");
90  uri.SetUserInfo("user:pass");
91  uri.SetHost("host.org");
92  uri.SetPath("/some/path/file.avi");
93  uri.SetQuery("key1=value1");
94  uri.SetFragment("anchor3");
95  return uri.GetUri() == composed;
96 }
97 
98 void Answer(Bool_t success)
99 {
100  if (success)
101  Printf("---> SUCCESS\n");
102  else
103  Printf("---> F A I L E D F A I L E D F A I L E D\n");
104 }
105 
107 {
108  // validating examples from RFC chapter 1.1.2
109  Bool_t valid = kTRUE;
110  valid &= TUri("ftp://ftp.is.co.za/rfc/rfc1808.txt").IsUri();
111  valid &= TUri("http://www.ietf.org/rfc/rfc2396.txt").IsUri();
112  // IPV6 example excluded
113  //valid &= TUri("ldap://[2001:db8::7]/c=GB?objectClass?one").IsUri();
114  valid &= TUri("mailto:John.Doe@example.com").IsUri();
115  valid &= TUri("news:comp.infosystems.www.servers.unix").IsUri();
116  valid &= TUri("tel:+1-816-555-1212").IsUri();
117  valid &= TUri("telnet://192.0.2.16:80/").IsUri();
118  valid &= TUri("urn:oasis:names:specification:docbook:dtd:xml:4.1.2").IsUri();
119  return valid;
120 }
121 
122 
123 void TUriTest()
124 {
125  Printf("\n\nTUri test macro ...");
126  Printf("---> Validation");
128  Printf("---> Reference Resolution");
130  Printf("---> PCT Conversion");
131  Answer(TestPct());
132  Printf("---> Equivalence and Normalisation");
133  Answer(TUri("example://a/b/c/%7Bfoo%7D") == TUri("eXAMPLE://a/./b/../b/%63/%7bfoo%7d"));
134  Printf("---> Composition");
136 }
137 
tuple buffer
Definition: tree.py:99
Bool_t SetPath(const TString &path)
Set path component of URI: path = path-abempty ; begins with "/" or is empty ...
Definition: TUri.cxx:480
Bool_t TestResolutionHelper(TUri reference, TUri nominal, TUri &base)
Definition: TUriTest.C:6
Bool_t SetUserInfo(const TString &userinfo)
Set userinfo component of URI: userinfo = *( unreserved / pct-encoded / sub-delims / ":" )...
Definition: TUri.cxx:404
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
This class represents a RFC 3986 compatible URI.
Definition: TUri.h:39
static const TString PctDecode(const TString &source)
Percent-decode the given string according to chapter 2.1 we assume a valid pct-encoded string...
Definition: TUri.cxx:1085
Bool_t SetQuery(const TString &path)
Set query component of URI: query = *( pchar / "/" / "?" ).
Definition: TUri.cxx:297
const char * Data() const
Definition: TString.h:349
Bool_t IsUri() const
Returns kTRUE if instance qualifies as URI URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] ...
Definition: TUri.cxx:226
static const TString PctEncode(const TString &source)
Percent-encode and return the given string according to RFC 3986 in principle, this function cannot f...
Definition: TUri.cxx:814
Bool_t SetScheme(const TString &scheme)
Set scheme component of URI: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ).
Definition: TUri.cxx:247
const TString GetUri() const
Returns the whole URI - an implementation of chapter 5.3 component recomposition. ...
Definition: TUri.cxx:139
Bool_t TestPct()
Definition: TUriTest.C:68
void TUriTest()
Definition: TUriTest.C:123
Bool_t TestValidation()
Definition: TUriTest.C:106
Bool_t SetFragment(const TString &fragment)
Set fragment component of URI: fragment = *( pchar / "/" / "?" ).
Definition: TUri.cxx:497
static TUri Transform(const TUri &reference, const TUri &base)
Transform a URI reference into its target URI using given a base URI.
Definition: TUri.cxx:1121
Bool_t IsNull() const
Definition: TString.h:387
#define Printf
Definition: TGeoToOCC.h:18
Bool_t SetHost(const TString &host)
Set host component of URI: RFC 3986: host = IP-literal / IPv4address / reg-name implemented: host ...
Definition: TUri.cxx:441
std::vector< double > errors
Definition: TwoHistoFit2D.C:33
Bool_t TestComposition()
Definition: TUriTest.C:85
Bool_t TestResolution()
Definition: TUriTest.C:15
const Bool_t kTRUE
Definition: Rtypes.h:91
void Answer(Bool_t success)
Definition: TUriTest.C:98