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 "base/json/json_parser.h" | 5 #include "base/json/json_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 // Test each of the error conditions | 238 // Test each of the error conditions |
239 root = JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, &error_code, | 239 root = JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, &error_code, |
240 &error_message); | 240 &error_message); |
241 EXPECT_FALSE(root.get()); | 241 EXPECT_FALSE(root.get()); |
242 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, | 242 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, |
243 JSONReader::kUnexpectedDataAfterRoot), error_message); | 243 JSONReader::kUnexpectedDataAfterRoot), error_message); |
244 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); | 244 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); |
245 | 245 |
246 std::string nested_json; | 246 std::string nested_json; |
247 for (int i = 0; i < 101; ++i) { | 247 for (int i = 0; i < 201; ++i) { |
248 nested_json.insert(nested_json.begin(), '['); | 248 nested_json.insert(nested_json.begin(), '['); |
249 nested_json.append(1, ']'); | 249 nested_json.append(1, ']'); |
250 } | 250 } |
251 root = JSONReader::ReadAndReturnError(nested_json, JSON_PARSE_RFC, | 251 root = JSONReader::ReadAndReturnError(nested_json, JSON_PARSE_RFC, |
252 &error_code, &error_message); | 252 &error_code, &error_message); |
253 EXPECT_FALSE(root.get()); | 253 EXPECT_FALSE(root.get()); |
254 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 100, JSONReader::kTooMuchNesting), | 254 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 200, JSONReader::kTooMuchNesting), |
255 error_message); | 255 error_message); |
256 EXPECT_EQ(JSONReader::JSON_TOO_MUCH_NESTING, error_code); | 256 EXPECT_EQ(JSONReader::JSON_TOO_MUCH_NESTING, error_code); |
257 | 257 |
258 root = JSONReader::ReadAndReturnError("[1,]", JSON_PARSE_RFC, &error_code, | 258 root = JSONReader::ReadAndReturnError("[1,]", JSON_PARSE_RFC, &error_code, |
259 &error_message); | 259 &error_message); |
260 EXPECT_FALSE(root.get()); | 260 EXPECT_FALSE(root.get()); |
261 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 4, JSONReader::kTrailingComma), | 261 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 4, JSONReader::kTrailingComma), |
262 error_message); | 262 error_message); |
263 EXPECT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); | 263 EXPECT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); |
264 | 264 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 NewTestParser(quoted_bogus_char, JSON_REPLACE_INVALID_CHARACTERS)); | 337 NewTestParser(quoted_bogus_char, JSON_REPLACE_INVALID_CHARACTERS)); |
338 std::unique_ptr<Value> value(parser->ConsumeString()); | 338 std::unique_ptr<Value> value(parser->ConsumeString()); |
339 ASSERT_TRUE(value.get()); | 339 ASSERT_TRUE(value.get()); |
340 std::string str; | 340 std::string str; |
341 EXPECT_TRUE(value->GetAsString(&str)); | 341 EXPECT_TRUE(value->GetAsString(&str)); |
342 EXPECT_EQ(kUnicodeReplacementString, str); | 342 EXPECT_EQ(kUnicodeReplacementString, str); |
343 } | 343 } |
344 | 344 |
345 } // namespace internal | 345 } // namespace internal |
346 } // namespace base | 346 } // namespace base |
OLD | NEW |