Changeset 2428 for box/trunk/test
- Timestamp:
- 03/01/2009 08:59:47 (3 years ago)
- File:
-
- 1 edited
-
box/trunk/test/httpserver/testhttpserver.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/test/httpserver/testhttpserver.cpp
r2423 r2428 17 17 #include "HTTPRequest.h" 18 18 #include "HTTPResponse.h" 19 #include "IOStreamGetLine.h" 19 20 #include "ServerControl.h" 20 21 … … 72 73 case HTTPRequest::Method_HEAD: m = "HEAD"; break; 73 74 case HTTPRequest::Method_POST: m = "POST"; break; 75 default: m = "UNKNOWN"; 74 76 } 75 77 rResponse.Write(m, 4); … … 126 128 int pid = LaunchServer("./test server testfiles/httpserver.conf", "testfiles/httpserver.pid"); 127 129 TEST_THAT(pid != -1 && pid != 0); 128 if(pid > 0) 129 { 130 // Run the request script 131 TEST_THAT(::system("perl testfiles/testrequests.pl") == 0); 130 if(pid <= 0) 131 { 132 return 0; 133 } 134 135 // Run the request script 136 TEST_THAT(::system("perl testfiles/testrequests.pl") == 0); 137 138 signal(SIGPIPE, SIG_IGN); 139 140 SocketStream sock; 141 sock.Open(Socket::TypeINET, "localhost", 1080); 142 143 for (int i = 0; i < 4; i++) 144 { 145 HTTPRequest request(HTTPRequest::Method_GET, 146 "/test-one/34/341s/234?p1=vOne&p2=vTwo"); 147 148 if (i >= 2) 149 { 150 // first set of passes has keepalive off by default, 151 // so when i == 1 the socket has already been closed 152 // by the server, and we'll get -EPIPE when we try 153 // to send the request. 154 request.SetClientKeepAliveRequested(true); 155 } 156 157 if (i == 1) 158 { 159 TEST_CHECK_THROWS(request.Write(sock, 160 IOStream::TimeOutInfinite), 161 ConnectionException, SocketWriteError); 162 sock.Close(); 163 sock.Open(Socket::TypeINET, "localhost", 1080); 164 continue; 165 } 166 else 167 { 168 request.Write(sock, IOStream::TimeOutInfinite); 169 } 170 171 HTTPResponse response; 172 response.Receive(sock); 173 174 TEST_THAT(response.GetResponseCode() == HTTPResponse::Code_OK); 175 TEST_THAT(response.GetContentType() == "text/html"); 176 177 IOStreamGetLine getline(response); 178 std::string line; 179 180 TEST_THAT(getline.GetLine(line)); 181 TEST_EQUAL("<html>", line); 182 TEST_THAT(getline.GetLine(line)); 183 TEST_EQUAL("<head><title>TEST SERVER RESPONSE</title></head>", 184 line); 185 TEST_THAT(getline.GetLine(line)); 186 TEST_EQUAL("<body><h1>Test response</h1>", line); 187 TEST_THAT(getline.GetLine(line)); 188 TEST_EQUAL("<p><b>URI:</b> /test-one/34/341s/234</p>", line); 189 TEST_THAT(getline.GetLine(line)); 190 TEST_EQUAL("<p><b>Query string:</b> p1=vOne&p2=vTwo</p>", line); 191 TEST_THAT(getline.GetLine(line)); 192 TEST_EQUAL("<p><b>Method:</b> GET </p>", line); 193 TEST_THAT(getline.GetLine(line)); 194 TEST_EQUAL("<p><b>Decoded query:</b><br>", line); 195 TEST_THAT(getline.GetLine(line)); 196 TEST_EQUAL("PARAM:p1=vOne<br>", line); 197 TEST_THAT(getline.GetLine(line)); 198 TEST_EQUAL("PARAM:p2=vTwo<br></p>", line); 199 TEST_THAT(getline.GetLine(line)); 200 TEST_EQUAL("<p><b>Content type:</b> </p>", line); 201 TEST_THAT(getline.GetLine(line)); 202 TEST_EQUAL("<p><b>Content length:</b> -1</p>", line); 203 TEST_THAT(getline.GetLine(line)); 204 TEST_EQUAL("<p><b>Cookies:</b><br>", line); 205 TEST_THAT(getline.GetLine(line)); 206 TEST_EQUAL("</p>", line); 207 TEST_THAT(getline.GetLine(line)); 208 TEST_EQUAL("</body>", line); 209 TEST_THAT(getline.GetLine(line)); 210 TEST_EQUAL("</html>", line); 211 } 132 212 133 // Kill it 134 TEST_THAT(KillServer(pid)); 135 TestRemoteProcessMemLeaks("generic-httpserver.memleaks"); 136 } 213 // Kill it 214 TEST_THAT(KillServer(pid)); 215 TestRemoteProcessMemLeaks("generic-httpserver.memleaks"); 137 216 138 217 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
