comparison UnitTestsSources/RestApiTests.cpp @ 1441:f3672356c121

refactoring: IHttpHandler and HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 10:38:39 +0200
parents 20b4521631e1
children f967bdf8534e
comparison
equal deleted inserted replaced
1440:3567503c00a7 1441:f3672356c121
91 ASSERT_EQ("helloworld", s); 91 ASSERT_EQ("helloworld", s);
92 } 92 }
93 93
94 TEST(RestApi, ParseCookies) 94 TEST(RestApi, ParseCookies)
95 { 95 {
96 HttpHandler::Arguments headers; 96 IHttpHandler::Arguments headers;
97 HttpHandler::Arguments cookies; 97 IHttpHandler::Arguments cookies;
98 98
99 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;"; 99 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;";
100 HttpHandler::ParseCookies(cookies, headers); 100 HttpToolbox::ParseCookies(cookies, headers);
101 ASSERT_EQ(4u, cookies.size()); 101 ASSERT_EQ(4u, cookies.size());
102 ASSERT_EQ("b", cookies["a"]); 102 ASSERT_EQ("b", cookies["a"]);
103 ASSERT_EQ("d", cookies["c"]); 103 ASSERT_EQ("d", cookies["c"]);
104 ASSERT_EQ("f", cookies["e"]); 104 ASSERT_EQ("f", cookies["e"]);
105 ASSERT_EQ("h", cookies["g"]); 105 ASSERT_EQ("h", cookies["g"]);
106 106
107 headers["cookie"] = " name = value ; name2=value2"; 107 headers["cookie"] = " name = value ; name2=value2";
108 HttpHandler::ParseCookies(cookies, headers); 108 HttpToolbox::ParseCookies(cookies, headers);
109 ASSERT_EQ(2u, cookies.size()); 109 ASSERT_EQ(2u, cookies.size());
110 ASSERT_EQ("value", cookies["name"]); 110 ASSERT_EQ("value", cookies["name"]);
111 ASSERT_EQ("value2", cookies["name2"]); 111 ASSERT_EQ("value2", cookies["name2"]);
112 112
113 headers["cookie"] = " ;;; "; 113 headers["cookie"] = " ;;; ";
114 HttpHandler::ParseCookies(cookies, headers); 114 HttpToolbox::ParseCookies(cookies, headers);
115 ASSERT_EQ(0u, cookies.size()); 115 ASSERT_EQ(0u, cookies.size());
116 116
117 headers["cookie"] = " ; n=v ;; "; 117 headers["cookie"] = " ; n=v ;; ";
118 HttpHandler::ParseCookies(cookies, headers); 118 HttpToolbox::ParseCookies(cookies, headers);
119 ASSERT_EQ(1u, cookies.size()); 119 ASSERT_EQ(1u, cookies.size());
120 ASSERT_EQ("v", cookies["n"]); 120 ASSERT_EQ("v", cookies["n"]);
121 } 121 }
122 122
123 TEST(RestApi, RestApiPath) 123 TEST(RestApi, RestApiPath)
124 { 124 {
125 HttpHandler::Arguments args; 125 IHttpHandler::Arguments args;
126 UriComponents trail; 126 UriComponents trail;
127 127
128 { 128 {
129 RestApiPath uri("/coucou/{abc}/d/*"); 129 RestApiPath uri("/coucou/{abc}/d/*");
130 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); 130 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g"));
218 class MyVisitor : public RestApiHierarchy::IVisitor 218 class MyVisitor : public RestApiHierarchy::IVisitor
219 { 219 {
220 public: 220 public:
221 virtual bool Visit(const RestApiHierarchy::Resource& resource, 221 virtual bool Visit(const RestApiHierarchy::Resource& resource,
222 const UriComponents& uri, 222 const UriComponents& uri,
223 const HttpHandler::Arguments& components, 223 const IHttpHandler::Arguments& components,
224 const UriComponents& trailing) 224 const UriComponents& trailing)
225 { 225 {
226 return resource.Handle(*reinterpret_cast<RestApiGetCall*>(NULL)); 226 return resource.Handle(*reinterpret_cast<RestApiGetCall*>(NULL));
227 } 227 }
228 }; 228 };