2017-03-23 15:45:49 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/httpcommon.h"
|
|
|
|
|
#include "rtc_base/gunit.h"
|
2017-03-23 15:45:49 -07:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
|
|
|
|
TEST(HttpResponseData, parseLeaderHttp1_0) {
|
|
|
|
|
static const char kResponseString[] = "HTTP/1.0 200 OK";
|
|
|
|
|
HttpResponseData response;
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(HE_NONE,
|
|
|
|
|
response.parseLeader(kResponseString, sizeof(kResponseString) - 1));
|
2017-03-23 15:45:49 -07:00
|
|
|
EXPECT_EQ(HVER_1_0, response.version);
|
|
|
|
|
EXPECT_EQ(200U, response.scode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HttpResponseData, parseLeaderHttp1_1) {
|
|
|
|
|
static const char kResponseString[] = "HTTP/1.1 200 OK";
|
|
|
|
|
HttpResponseData response;
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(HE_NONE,
|
|
|
|
|
response.parseLeader(kResponseString, sizeof(kResponseString) - 1));
|
2017-03-23 15:45:49 -07:00
|
|
|
EXPECT_EQ(HVER_1_1, response.version);
|
|
|
|
|
EXPECT_EQ(200U, response.scode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HttpResponseData, parseLeaderHttpUnknown) {
|
|
|
|
|
static const char kResponseString[] = "HTTP 200 OK";
|
|
|
|
|
HttpResponseData response;
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(HE_NONE,
|
|
|
|
|
response.parseLeader(kResponseString, sizeof(kResponseString) - 1));
|
2017-03-23 15:45:49 -07:00
|
|
|
EXPECT_EQ(HVER_UNKNOWN, response.version);
|
|
|
|
|
EXPECT_EQ(200U, response.scode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HttpResponseData, parseLeaderHttpFailure) {
|
|
|
|
|
static const char kResponseString[] = "HTTP/1.1 503 Service Unavailable";
|
|
|
|
|
HttpResponseData response;
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(HE_NONE,
|
|
|
|
|
response.parseLeader(kResponseString, sizeof(kResponseString) - 1));
|
2017-03-23 15:45:49 -07:00
|
|
|
EXPECT_EQ(HVER_1_1, response.version);
|
|
|
|
|
EXPECT_EQ(503U, response.scode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(HttpResponseData, parseLeaderHttpInvalid) {
|
|
|
|
|
static const char kResponseString[] = "Durrrrr, what's HTTP?";
|
|
|
|
|
HttpResponseData response;
|
2018-06-19 15:03:05 +02:00
|
|
|
EXPECT_EQ(HE_PROTOCOL,
|
|
|
|
|
response.parseLeader(kResponseString, sizeof(kResponseString) - 1));
|
2017-03-23 15:45:49 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
} // namespace rtc
|