OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 ASSERT_NO_FATAL_FAILURE( | 1085 ASSERT_NO_FATAL_FAILURE( |
1086 CheckNextNameValuePair(&parser, true, true, "f", "'hello world'")); | 1086 CheckNextNameValuePair(&parser, true, true, "f", "'hello world'")); |
1087 ASSERT_NO_FATAL_FAILURE( | 1087 ASSERT_NO_FATAL_FAILURE( |
1088 CheckNextNameValuePair(&parser, true, true, "g", std::string())); | 1088 CheckNextNameValuePair(&parser, true, true, "g", std::string())); |
1089 ASSERT_NO_FATAL_FAILURE( | 1089 ASSERT_NO_FATAL_FAILURE( |
1090 CheckNextNameValuePair(&parser, true, true, "h", "hello")); | 1090 CheckNextNameValuePair(&parser, true, true, "h", "hello")); |
1091 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1091 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
1092 &parser, false, true, std::string(), std::string())); | 1092 &parser, false, true, std::string(), std::string())); |
1093 } | 1093 } |
1094 | 1094 |
1095 TEST(HttpUtilTest, NameValuePairsIteratorOptionalValues) { | |
1096 std::string data = "alpha=1; beta;cappa ; delta; e ; f=1"; | |
1097 // Test that the default parser requires values. | |
1098 HttpUtil::NameValuePairsIterator default_parser(data.begin(), data.end(), | |
1099 ';'); | |
1100 EXPECT_TRUE(default_parser.valid()); | |
1101 ASSERT_NO_FATAL_FAILURE( | |
1102 CheckNextNameValuePair(&default_parser, true, true, "alpha", "1")); | |
1103 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(&default_parser, false, false, | |
1104 std::string(), std::string())); | |
1105 | |
1106 HttpUtil::NameValuePairsIterator values_required_parser( | |
1107 data.begin(), data.end(), ';', | |
1108 HttpUtil::NameValuePairsIterator::VALUES_NOT_OPTIONAL); | |
1109 EXPECT_TRUE(values_required_parser.valid()); | |
1110 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(&values_required_parser, true, | |
1111 true, "alpha", "1")); | |
1112 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | |
1113 &values_required_parser, false, false, std::string(), std::string())); | |
1114 EXPECT_FALSE(values_required_parser.valid()); | |
davidben
2015/07/16 20:13:01
Nit: This one is probably unnecessary since CheckN
estark
2015/07/17 00:56:31
Done.
| |
1115 | |
1116 HttpUtil::NameValuePairsIterator parser( | |
1117 data.begin(), data.end(), ';', | |
1118 HttpUtil::NameValuePairsIterator::VALUES_OPTIONAL); | |
1119 EXPECT_TRUE(parser.valid()); | |
1120 | |
1121 ASSERT_NO_FATAL_FAILURE( | |
1122 CheckNextNameValuePair(&parser, true, true, "alpha", "1")); | |
1123 ASSERT_NO_FATAL_FAILURE( | |
1124 CheckNextNameValuePair(&parser, true, true, "beta", std::string())); | |
1125 ASSERT_NO_FATAL_FAILURE( | |
1126 CheckNextNameValuePair(&parser, true, true, "cappa", std::string())); | |
1127 ASSERT_NO_FATAL_FAILURE( | |
1128 CheckNextNameValuePair(&parser, true, true, "delta", std::string())); | |
1129 ASSERT_NO_FATAL_FAILURE( | |
1130 CheckNextNameValuePair(&parser, true, true, "e", std::string())); | |
1131 ASSERT_NO_FATAL_FAILURE( | |
1132 CheckNextNameValuePair(&parser, true, true, "f", "1")); | |
1133 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(&parser, false, true, | |
1134 std::string(), std::string())); | |
1135 EXPECT_TRUE(parser.valid()); | |
1136 } | |
1137 | |
1095 TEST(HttpUtilTest, NameValuePairsIteratorIllegalInputs) { | 1138 TEST(HttpUtilTest, NameValuePairsIteratorIllegalInputs) { |
1096 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; beta")); | 1139 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; beta")); |
1097 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "beta")); | 1140 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "beta")); |
1098 | 1141 |
1099 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; 'beta'=2")); | 1142 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; 'beta'=2")); |
1100 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "'beta'=2")); | 1143 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "'beta'=2")); |
1101 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", ";beta=")); | 1144 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", ";beta=")); |
1102 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", | 1145 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", |
1103 ";beta=;cappa=2")); | 1146 ";beta=;cappa=2")); |
1104 | 1147 |
(...skipping 27 matching lines...) Expand all Loading... | |
1132 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1175 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
1133 EXPECT_TRUE(parser.valid()); | 1176 EXPECT_TRUE(parser.valid()); |
1134 | 1177 |
1135 ASSERT_NO_FATAL_FAILURE( | 1178 ASSERT_NO_FATAL_FAILURE( |
1136 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1179 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
1137 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1180 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
1138 &parser, false, true, std::string(), std::string())); | 1181 &parser, false, true, std::string(), std::string())); |
1139 } | 1182 } |
1140 | 1183 |
1141 } // namespace net | 1184 } // namespace net |
OLD | NEW |