Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/protobuf/conformance/conformance_test.cc

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 string binary_protobuf; 292 string binary_protobuf;
293 Status status = 293 Status status =
294 JsonToBinaryString(type_resolver_.get(), type_url_, 294 JsonToBinaryString(type_resolver_.get(), type_url_,
295 response.json_payload(), &binary_protobuf); 295 response.json_payload(), &binary_protobuf);
296 if (!status.ok()) { 296 if (!status.ok()) {
297 ReportFailure(test_name, request, response, 297 ReportFailure(test_name, request, response,
298 "JSON output we received from test was unparseable."); 298 "JSON output we received from test was unparseable.");
299 return; 299 return;
300 } 300 }
301 301
302 GOOGLE_CHECK(test_message.ParseFromString(binary_protobuf)); 302 if (!test_message.ParseFromString(binary_protobuf)) {
303 ReportFailure(test_name, request, response,
304 "INTERNAL ERROR: internal JSON->protobuf transcode "
305 "yielded unparseable proto.");
306 return;
307 }
308
303 break; 309 break;
304 } 310 }
305 311
306 case ConformanceResponse::kProtobufPayload: { 312 case ConformanceResponse::kProtobufPayload: {
307 if (requested_output != conformance::PROTOBUF) { 313 if (requested_output != conformance::PROTOBUF) {
308 ReportFailure( 314 ReportFailure(
309 test_name, request, response, 315 test_name, request, response,
310 "Test was asked for JSON output but provided protobuf instead."); 316 "Test was asked for JSON output but provided protobuf instead.");
311 return; 317 return;
312 } 318 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 request.set_protobuf_payload(proto); 355 request.set_protobuf_payload(proto);
350 string effective_test_name = "ProtobufInput." + test_name; 356 string effective_test_name = "ProtobufInput." + test_name;
351 357
352 // We don't expect output, but if the program erroneously accepts the protobuf 358 // We don't expect output, but if the program erroneously accepts the protobuf
353 // we let it send its response as this. We must not leave it unspecified. 359 // we let it send its response as this. We must not leave it unspecified.
354 request.set_requested_output_format(conformance::PROTOBUF); 360 request.set_requested_output_format(conformance::PROTOBUF);
355 361
356 RunTest(effective_test_name, request, &response); 362 RunTest(effective_test_name, request, &response);
357 if (response.result_case() == ConformanceResponse::kParseError) { 363 if (response.result_case() == ConformanceResponse::kParseError) {
358 ReportSuccess(effective_test_name); 364 ReportSuccess(effective_test_name);
365 } else if (response.result_case() == ConformanceResponse::kSkipped) {
366 ReportSkip(effective_test_name, request, response);
359 } else { 367 } else {
360 ReportFailure(effective_test_name, request, response, 368 ReportFailure(effective_test_name, request, response,
361 "Should have failed to parse, but didn't."); 369 "Should have failed to parse, but didn't.");
362 } 370 }
363 } 371 }
364 372
365 // Expect that this protobuf will cause a parse error, even if it is followed 373 // Expect that this protobuf will cause a parse error, even if it is followed
366 // by valid protobuf data. We can try running this twice: once with this 374 // by valid protobuf data. We can try running this twice: once with this
367 // data verbatim and once with this data followed by some valid data. 375 // data verbatim and once with this data followed by some valid data.
368 // 376 //
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 const Validator& validator) { 409 const Validator& validator) {
402 ConformanceRequest request; 410 ConformanceRequest request;
403 ConformanceResponse response; 411 ConformanceResponse response;
404 request.set_json_payload(input_json); 412 request.set_json_payload(input_json);
405 request.set_requested_output_format(conformance::JSON); 413 request.set_requested_output_format(conformance::JSON);
406 414
407 string effective_test_name = "JsonInput." + test_name + ".Validator"; 415 string effective_test_name = "JsonInput." + test_name + ".Validator";
408 416
409 RunTest(effective_test_name, request, &response); 417 RunTest(effective_test_name, request, &response);
410 418
419 if (response.result_case() == ConformanceResponse::kSkipped) {
420 ReportSkip(effective_test_name, request, response);
421 return;
422 }
423
411 if (response.result_case() != ConformanceResponse::kJsonPayload) { 424 if (response.result_case() != ConformanceResponse::kJsonPayload) {
412 ReportFailure(effective_test_name, request, response, 425 ReportFailure(effective_test_name, request, response,
413 "Expected JSON payload but got type %d.", 426 "Expected JSON payload but got type %d.",
414 response.result_case()); 427 response.result_case());
415 return; 428 return;
416 } 429 }
417 Json::Reader reader; 430 Json::Reader reader;
418 Json::Value value; 431 Json::Value value;
419 if (!reader.parse(response.json_payload(), value)) { 432 if (!reader.parse(response.json_payload(), value)) {
420 ReportFailure(effective_test_name, request, response, 433 ReportFailure(effective_test_name, request, response,
(...skipping 16 matching lines...) Expand all
437 request.set_json_payload(input_json); 450 request.set_json_payload(input_json);
438 string effective_test_name = "JsonInput." + test_name; 451 string effective_test_name = "JsonInput." + test_name;
439 452
440 // We don't expect output, but if the program erroneously accepts the protobuf 453 // We don't expect output, but if the program erroneously accepts the protobuf
441 // we let it send its response as this. We must not leave it unspecified. 454 // we let it send its response as this. We must not leave it unspecified.
442 request.set_requested_output_format(conformance::JSON); 455 request.set_requested_output_format(conformance::JSON);
443 456
444 RunTest(effective_test_name, request, &response); 457 RunTest(effective_test_name, request, &response);
445 if (response.result_case() == ConformanceResponse::kParseError) { 458 if (response.result_case() == ConformanceResponse::kParseError) {
446 ReportSuccess(effective_test_name); 459 ReportSuccess(effective_test_name);
460 } else if (response.result_case() == ConformanceResponse::kSkipped) {
461 ReportSkip(effective_test_name, request, response);
447 } else { 462 } else {
448 ReportFailure(effective_test_name, request, response, 463 ReportFailure(effective_test_name, request, response,
449 "Should have failed to parse, but didn't."); 464 "Should have failed to parse, but didn't.");
450 } 465 }
451 } 466 }
452 467
453 void ConformanceTestSuite::ExpectSerializeFailureForJson( 468 void ConformanceTestSuite::ExpectSerializeFailureForJson(
454 const string& test_name, const string& text_format) { 469 const string& test_name, const string& text_format) {
455 TestAllTypes payload_message; 470 TestAllTypes payload_message;
456 GOOGLE_CHECK( 471 GOOGLE_CHECK(
457 TextFormat::ParseFromString(text_format, &payload_message)) 472 TextFormat::ParseFromString(text_format, &payload_message))
458 << "Failed to parse: " << text_format; 473 << "Failed to parse: " << text_format;
459 474
460 ConformanceRequest request; 475 ConformanceRequest request;
461 ConformanceResponse response; 476 ConformanceResponse response;
462 request.set_protobuf_payload(payload_message.SerializeAsString()); 477 request.set_protobuf_payload(payload_message.SerializeAsString());
463 string effective_test_name = test_name + ".JsonOutput"; 478 string effective_test_name = test_name + ".JsonOutput";
464 request.set_requested_output_format(conformance::JSON); 479 request.set_requested_output_format(conformance::JSON);
465 480
466 RunTest(effective_test_name, request, &response); 481 RunTest(effective_test_name, request, &response);
467 if (response.result_case() == ConformanceResponse::kSerializeError) { 482 if (response.result_case() == ConformanceResponse::kSerializeError) {
468 ReportSuccess(effective_test_name); 483 ReportSuccess(effective_test_name);
484 } else if (response.result_case() == ConformanceResponse::kSkipped) {
485 ReportSkip(effective_test_name, request, response);
469 } else { 486 } else {
470 ReportFailure(effective_test_name, request, response, 487 ReportFailure(effective_test_name, request, response,
471 "Should have failed to serialize, but didn't."); 488 "Should have failed to serialize, but didn't.");
472 } 489 }
473 } 490 }
474 491
475 void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) { 492 void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) {
476 // Incomplete values for each wire type. 493 // Incomplete values for each wire type.
477 static const string incompletes[6] = { 494 static const string incompletes[6] = {
478 string("\x80"), // VARINT 495 string("\x80"), // VARINT
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 ok = false; 1977 ok = false;
1961 } 1978 }
1962 1979
1963 // Sometimes the testee may be fixed before we update the failure list (e.g., 1980 // Sometimes the testee may be fixed before we update the failure list (e.g.,
1964 // the testee is from a different component). We warn about this case but 1981 // the testee is from a different component). We warn about this case but
1965 // don't consider it an overall test failure. 1982 // don't consider it an overall test failure.
1966 CheckSetEmpty(unexpected_succeeding_tests_, 1983 CheckSetEmpty(unexpected_succeeding_tests_,
1967 "These tests succeeded, even though they were listed in " 1984 "These tests succeeded, even though they were listed in "
1968 "the failure list. Remove them from the failure list"); 1985 "the failure list. Remove them from the failure list");
1969 1986
1970 CheckSetEmpty(skipped_,
1971 "These tests were skipped (probably because support for some "
1972 "features is not implemented)");
1973 if (verbose_) { 1987 if (verbose_) {
1974 CheckSetEmpty(skipped_, 1988 CheckSetEmpty(skipped_,
1975 "These tests were skipped (probably because support for some " 1989 "These tests were skipped (probably because support for some "
1976 "features is not implemented)"); 1990 "features is not implemented)");
1977 } 1991 }
1978 1992
1979 StringAppendF(&output_, 1993 StringAppendF(&output_,
1980 "CONFORMANCE SUITE %s: %d successes, %d skipped, " 1994 "CONFORMANCE SUITE %s: %d successes, %d skipped, "
1981 "%d expected failures, %d unexpected failures.\n", 1995 "%d expected failures, %d unexpected failures.\n",
1982 ok ? "PASSED" : "FAILED", successes_, skipped_.size(), 1996 ok ? "PASSED" : "FAILED", successes_, skipped_.size(),
1983 expected_failures_, unexpected_failing_tests_.size()); 1997 expected_failures_, unexpected_failing_tests_.size());
1984 StringAppendF(&output_, "\n"); 1998 StringAppendF(&output_, "\n");
1985 1999
1986 output->assign(output_); 2000 output->assign(output_);
1987 2001
1988 return ok; 2002 return ok;
1989 } 2003 }
1990 2004
1991 } // namespace protobuf 2005 } // namespace protobuf
1992 } // namespace google 2006 } // namespace google
OLDNEW
« no previous file with comments | « third_party/protobuf/conformance/conformance_ruby.rb ('k') | third_party/protobuf/conformance/conformance_test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698