OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
15 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
16 #include "webrtc/base/pathutils.h" | 17 #include "webrtc/base/pathutils.h" |
17 #include "webrtc/base/scoped_ptr.h" | |
18 #include "webrtc/base/multipart.h" | 18 #include "webrtc/base/multipart.h" |
19 | 19 |
20 namespace rtc { | 20 namespace rtc { |
21 | 21 |
22 static const std::string kTestMultipartBoundary = "123456789987654321"; | 22 static const std::string kTestMultipartBoundary = "123456789987654321"; |
23 static const std::string kTestContentType = | 23 static const std::string kTestContentType = |
24 "multipart/form-data; boundary=123456789987654321"; | 24 "multipart/form-data; boundary=123456789987654321"; |
25 static const char kTestData[] = "This is a test."; | 25 static const char kTestData[] = "This is a test."; |
26 static const char kTestStreamContent[] = "This is a test stream."; | 26 static const char kTestStreamContent[] = "This is a test stream."; |
27 | 27 |
(...skipping 26 matching lines...) Expand all Loading... |
54 TEST(MultipartTest, TestAddAndRead) { | 54 TEST(MultipartTest, TestAddAndRead) { |
55 MultipartStream multipart("multipart/form-data", kTestMultipartBoundary); | 55 MultipartStream multipart("multipart/form-data", kTestMultipartBoundary); |
56 | 56 |
57 size_t part_size = | 57 size_t part_size = |
58 multipart.GetPartSize(kTestData, "form-data; name=\"text\"", "text"); | 58 multipart.GetPartSize(kTestData, "form-data; name=\"text\"", "text"); |
59 EXPECT_TRUE(multipart.AddPart(kTestData, "form-data; name=\"text\"", "text")); | 59 EXPECT_TRUE(multipart.AddPart(kTestData, "form-data; name=\"text\"", "text")); |
60 size_t size; | 60 size_t size; |
61 EXPECT_TRUE(multipart.GetSize(&size)); | 61 EXPECT_TRUE(multipart.GetSize(&size)); |
62 EXPECT_EQ(part_size, size); | 62 EXPECT_EQ(part_size, size); |
63 | 63 |
64 rtc::scoped_ptr<rtc::MemoryStream> stream( | 64 std::unique_ptr<rtc::MemoryStream> stream( |
65 new rtc::MemoryStream(kTestStreamContent)); | 65 new rtc::MemoryStream(kTestStreamContent)); |
66 size_t stream_size = 0; | 66 size_t stream_size = 0; |
67 EXPECT_TRUE(stream->GetSize(&stream_size)); | 67 EXPECT_TRUE(stream->GetSize(&stream_size)); |
68 part_size += | 68 part_size += |
69 multipart.GetPartSize("", "form-data; name=\"stream\"", "stream"); | 69 multipart.GetPartSize("", "form-data; name=\"stream\"", "stream"); |
70 part_size += stream_size; | 70 part_size += stream_size; |
71 | 71 |
72 EXPECT_TRUE(multipart.AddPart( | 72 EXPECT_TRUE(multipart.AddPart( |
73 new rtc::MemoryStream(kTestStreamContent), | 73 new rtc::MemoryStream(kTestStreamContent), |
74 "form-data; name=\"stream\"", | 74 "form-data; name=\"stream\"", |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 pos = str.find(kTestMultipartBoundary, pos); | 117 pos = str.find(kTestMultipartBoundary, pos); |
118 EXPECT_NE(std::string::npos, pos); | 118 EXPECT_NE(std::string::npos, pos); |
119 pos += kTestMultipartBoundary.length(); | 119 pos += kTestMultipartBoundary.length(); |
120 | 120 |
121 pos = str.find(kTestMultipartBoundary, pos); | 121 pos = str.find(kTestMultipartBoundary, pos); |
122 EXPECT_EQ(std::string::npos, pos); | 122 EXPECT_EQ(std::string::npos, pos); |
123 } | 123 } |
124 | 124 |
125 } // namespace rtc | 125 } // namespace rtc |
OLD | NEW |