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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // Error strings should not be modified in case of success. | 203 // Error strings should not be modified in case of success. |
204 std::string error_message; | 204 std::string error_message; |
205 int error_code = 0; | 205 int error_code = 0; |
206 scoped_ptr<Value> root; | 206 scoped_ptr<Value> root; |
207 root.reset(JSONReader::ReadAndReturnError("[42]", JSON_PARSE_RFC, | 207 root.reset(JSONReader::ReadAndReturnError("[42]", JSON_PARSE_RFC, |
208 &error_code, &error_message)); | 208 &error_code, &error_message)); |
209 EXPECT_TRUE(error_message.empty()); | 209 EXPECT_TRUE(error_message.empty()); |
210 EXPECT_EQ(0, error_code); | 210 EXPECT_EQ(0, error_code); |
211 | 211 |
212 // Test line and column counting | 212 // Test line and column counting |
213 const char* big_json = "[\n0,\n1,\n2,\n3,4,5,6 7,\n8,\n9\n]"; | 213 const char big_json[] = "[\n0,\n1,\n2,\n3,4,5,6 7,\n8,\n9\n]"; |
214 // error here ---------------------------------^ | 214 // error here ---------------------------------^ |
Mark Mentovai
2013/02/05 02:13:38
You need to fix this now—it’s supposed to point to
| |
215 root.reset(JSONReader::ReadAndReturnError(big_json, JSON_PARSE_RFC, | 215 root.reset(JSONReader::ReadAndReturnError(big_json, JSON_PARSE_RFC, |
216 &error_code, &error_message)); | 216 &error_code, &error_message)); |
217 EXPECT_FALSE(root.get()); | 217 EXPECT_FALSE(root.get()); |
218 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), | 218 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), |
219 error_message); | 219 error_message); |
220 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); | 220 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); |
221 | 221 |
222 error_code = 0; | |
223 error_message = ""; | |
224 // Test line and column counting with "\r\n" line ending | |
225 const char big_json_crlf[] = | |
226 "[\r\n0,\r\n1,\r\n2,\r\n3,4,5,6 7,\r\n8,\r\n9\r\n]"; | |
227 // error here --------------------^ | |
Mark Mentovai
2013/02/05 02:13:38
This too.
| |
228 root.reset(JSONReader::ReadAndReturnError(big_json_crlf, JSON_PARSE_RFC, | |
229 &error_code, &error_message)); | |
230 EXPECT_FALSE(root.get()); | |
231 EXPECT_EQ(JSONParser::FormatErrorMessage(5, 10, JSONReader::kSyntaxError), | |
232 error_message); | |
233 EXPECT_EQ(JSONReader::JSON_SYNTAX_ERROR, error_code); | |
234 | |
222 // Test each of the error conditions | 235 // Test each of the error conditions |
223 root.reset(JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, | 236 root.reset(JSONReader::ReadAndReturnError("{},{}", JSON_PARSE_RFC, |
224 &error_code, &error_message)); | 237 &error_code, &error_message)); |
225 EXPECT_FALSE(root.get()); | 238 EXPECT_FALSE(root.get()); |
226 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, | 239 EXPECT_EQ(JSONParser::FormatErrorMessage(1, 3, |
227 JSONReader::kUnexpectedDataAfterRoot), error_message); | 240 JSONReader::kUnexpectedDataAfterRoot), error_message); |
228 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); | 241 EXPECT_EQ(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, error_code); |
229 | 242 |
230 std::string nested_json; | 243 std::string nested_json; |
231 for (int i = 0; i < 101; ++i) { | 244 for (int i = 0; i < 101; ++i) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 std::string error_message; | 310 std::string error_message; |
298 int error_code = 0; | 311 int error_code = 0; |
299 scoped_ptr<Value> root( | 312 scoped_ptr<Value> root( |
300 JSONReader::ReadAndReturnError(kUtf8Data, JSON_PARSE_RFC, &error_code, | 313 JSONReader::ReadAndReturnError(kUtf8Data, JSON_PARSE_RFC, &error_code, |
301 &error_message)); | 314 &error_message)); |
302 EXPECT_TRUE(root.get()) << error_message; | 315 EXPECT_TRUE(root.get()) << error_message; |
303 } | 316 } |
304 | 317 |
305 } // namespace internal | 318 } // namespace internal |
306 } // namespace base | 319 } // namespace base |
OLD | NEW |