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 | |
1115 HttpUtil::NameValuePairsIterator parser( | |
1116 data.begin(), data.end(), ';', | |
1117 HttpUtil::NameValuePairsIterator::VALUES_OPTIONAL); | |
1118 EXPECT_TRUE(parser.valid()); | |
1119 | |
1120 ASSERT_NO_FATAL_FAILURE( | |
1121 CheckNextNameValuePair(&parser, true, true, "alpha", "1")); | |
1122 ASSERT_NO_FATAL_FAILURE( | |
1123 CheckNextNameValuePair(&parser, true, true, "beta", std::string())); | |
1124 ASSERT_NO_FATAL_FAILURE( | |
1125 CheckNextNameValuePair(&parser, true, true, "cappa", std::string())); | |
1126 ASSERT_NO_FATAL_FAILURE( | |
1127 CheckNextNameValuePair(&parser, true, true, "delta", std::string())); | |
1128 ASSERT_NO_FATAL_FAILURE( | |
1129 CheckNextNameValuePair(&parser, true, true, "e", std::string())); | |
1130 ASSERT_NO_FATAL_FAILURE( | |
1131 CheckNextNameValuePair(&parser, true, true, "f", "1")); | |
1132 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(&parser, false, true, | |
1133 std::string(), std::string())); | |
1134 EXPECT_TRUE(parser.valid()); | |
1135 } | |
1136 | |
1137 TEST(HttpUtilTest, NameValuePairsIteratorIllegalInputs) { | 1095 TEST(HttpUtilTest, NameValuePairsIteratorIllegalInputs) { |
1138 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; beta")); | 1096 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; beta")); |
1139 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "beta")); | 1097 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "beta")); |
1140 | 1098 |
1141 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; 'beta'=2")); | 1099 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", "; 'beta'=2")); |
1142 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "'beta'=2")); | 1100 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair(std::string(), "'beta'=2")); |
1143 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", ";beta=")); | 1101 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", ";beta=")); |
1144 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", | 1102 ASSERT_NO_FATAL_FAILURE(CheckInvalidNameValuePair("alpha=1", |
1145 ";beta=;cappa=2")); | 1103 ";beta=;cappa=2")); |
1146 | 1104 |
(...skipping 27 matching lines...) Expand all Loading... |
1174 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1132 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
1175 EXPECT_TRUE(parser.valid()); | 1133 EXPECT_TRUE(parser.valid()); |
1176 | 1134 |
1177 ASSERT_NO_FATAL_FAILURE( | 1135 ASSERT_NO_FATAL_FAILURE( |
1178 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1136 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
1179 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1137 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
1180 &parser, false, true, std::string(), std::string())); | 1138 &parser, false, true, std::string(), std::string())); |
1181 } | 1139 } |
1182 | 1140 |
1183 } // namespace net | 1141 } // namespace net |
OLD | NEW |