Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <sstream> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/gunit.h" |
| 16 | #include "rtc_base/openssladapter.h" |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 17 | |
| 18 | namespace rtc { |
| 19 | |
| 20 | TEST(OpenSSLAdapterTest, TestTransformAlpnProtocols) { |
| 21 | EXPECT_EQ("", TransformAlpnProtocols(std::vector<std::string>())); |
| 22 | |
| 23 | // Protocols larger than 255 characters (whose size can't be fit in a byte), |
| 24 | // can't be converted, and an empty string will be returned. |
| 25 | std::string large_protocol(256, 'a'); |
| 26 | EXPECT_EQ("", |
| 27 | TransformAlpnProtocols(std::vector<std::string>{large_protocol})); |
| 28 | |
| 29 | // One protocol test. |
| 30 | std::vector<std::string> alpn_protos{"h2"}; |
| 31 | std::stringstream expected_response; |
| 32 | expected_response << static_cast<char>(2) << "h2"; |
| 33 | EXPECT_EQ(expected_response.str(), TransformAlpnProtocols(alpn_protos)); |
| 34 | |
| 35 | // Standard protocols test (h2,http/1.1). |
| 36 | alpn_protos.push_back("http/1.1"); |
| 37 | expected_response << static_cast<char>(8) << "http/1.1"; |
| 38 | EXPECT_EQ(expected_response.str(), TransformAlpnProtocols(alpn_protos)); |
| 39 | } |
| 40 | |
| 41 | } // namespace rtc |