2015-04-02 00:23:48 +00:00
|
|
|
// Protocol Buffers - Google's data interchange format
|
|
|
|
// Copyright 2008 Google Inc. All rights reserved.
|
|
|
|
// https://developers.google.com/protocol-buffers/
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
#include <set>
|
2015-04-02 00:23:48 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string>
|
2016-05-16 19:45:02 +00:00
|
|
|
#include <fstream>
|
2015-04-02 00:23:48 +00:00
|
|
|
|
|
|
|
#include "conformance.pb.h"
|
2015-04-14 20:45:39 +00:00
|
|
|
#include "conformance_test.h"
|
2016-12-03 16:51:25 +00:00
|
|
|
|
2015-04-14 20:45:39 +00:00
|
|
|
#include <google/protobuf/stubs/stringprintf.h>
|
2018-08-09 00:00:41 +00:00
|
|
|
#include <google/protobuf/stubs/strutil.h>
|
|
|
|
#include <google/protobuf/message.h>
|
2015-07-10 23:36:59 +00:00
|
|
|
#include <google/protobuf/text_format.h>
|
2015-12-12 01:09:20 +00:00
|
|
|
#include <google/protobuf/util/field_comparator.h>
|
2016-12-03 16:51:25 +00:00
|
|
|
#include <google/protobuf/util/json_util.h>
|
2015-07-10 23:36:59 +00:00
|
|
|
#include <google/protobuf/util/message_differencer.h>
|
2015-12-12 01:09:20 +00:00
|
|
|
|
2015-04-02 00:23:48 +00:00
|
|
|
using conformance::ConformanceRequest;
|
|
|
|
using conformance::ConformanceResponse;
|
2015-07-10 23:36:59 +00:00
|
|
|
using conformance::WireFormat;
|
|
|
|
using google::protobuf::TextFormat;
|
2015-12-12 01:09:20 +00:00
|
|
|
using google::protobuf::util::DefaultFieldComparator;
|
2015-07-10 23:36:59 +00:00
|
|
|
using google::protobuf::util::JsonToBinaryString;
|
|
|
|
using google::protobuf::util::MessageDifferencer;
|
|
|
|
using google::protobuf::util::Status;
|
2015-04-02 00:23:48 +00:00
|
|
|
using std::string;
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
namespace google {
|
|
|
|
namespace protobuf {
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
std::set<ConformanceTestSuite*> *conformance_test_suite_set;
|
|
|
|
GOOGLE_PROTOBUF_DECLARE_ONCE(conformance_test_suite_set_init_);
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
void DeleteConformanceTestSuiteSet() {
|
|
|
|
delete conformance_test_suite_set;
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
static void InitConformanceTestSuiteSet() {
|
|
|
|
conformance_test_suite_set = new std::set<ConformanceTestSuite*>();
|
|
|
|
internal::OnShutdown(&DeleteConformanceTestSuiteSet);
|
2017-01-07 00:58:21 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
static void InitConformanceTestSuiteSetOnce() {
|
|
|
|
::google::protobuf::GoogleOnceInit(
|
|
|
|
&conformance_test_suite_set_init_,
|
|
|
|
&InitConformanceTestSuiteSet);
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
void AddTestSuite(ConformanceTestSuite* suite) {
|
|
|
|
InitConformanceTestSuiteSetOnce();
|
|
|
|
conformance_test_suite_set->insert(suite);
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
const std::set<ConformanceTestSuite*>& GetTestSuiteSet() {
|
|
|
|
InitConformanceTestSuiteSetOnce();
|
|
|
|
return *conformance_test_suite_set;
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:23 +00:00
|
|
|
ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting(
|
2018-08-09 00:00:41 +00:00
|
|
|
ConformanceLevel level,
|
|
|
|
conformance::WireFormat input_format,
|
|
|
|
conformance::WireFormat output_format,
|
|
|
|
conformance::TestCategory test_category,
|
|
|
|
const Message& prototype_message,
|
2018-07-09 21:29:23 +00:00
|
|
|
const string& test_name, const string& input)
|
2018-08-09 00:00:41 +00:00
|
|
|
: level_(level),
|
|
|
|
input_format_(input_format),
|
|
|
|
output_format_(output_format),
|
|
|
|
prototype_message_(prototype_message),
|
|
|
|
test_name_(test_name) {
|
2018-07-09 21:29:23 +00:00
|
|
|
switch (input_format) {
|
|
|
|
case conformance::PROTOBUF: {
|
|
|
|
request_.set_protobuf_payload(input);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case conformance::JSON: {
|
|
|
|
request_.set_json_payload(input);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
GOOGLE_LOG(FATAL) << "Unspecified input format";
|
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
request_.set_test_category(test_category);
|
2018-07-09 21:29:23 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
request_.set_message_type(prototype_message.GetDescriptor()->full_name());
|
|
|
|
request_.set_requested_output_format(output_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
Message* ConformanceTestSuite::ConformanceRequestSetting::
|
|
|
|
GetTestMessage() const {
|
|
|
|
return prototype_message_.New();
|
|
|
|
}
|
|
|
|
|
|
|
|
string ConformanceTestSuite::ConformanceRequestSetting::
|
|
|
|
GetTestName() const {
|
|
|
|
string rname =
|
|
|
|
prototype_message_.GetDescriptor()->file()->syntax() ==
|
|
|
|
FileDescriptor::SYNTAX_PROTO3 ? "Proto3" : "Proto2";
|
|
|
|
|
|
|
|
return StrCat(ConformanceLevelToString(level_), ".",
|
|
|
|
rname, ".",
|
|
|
|
InputFormatString(input_format_),
|
|
|
|
".", test_name_, ".",
|
|
|
|
OutputFormatString(output_format_));
|
|
|
|
}
|
|
|
|
|
|
|
|
string ConformanceTestSuite::ConformanceRequestSetting::
|
|
|
|
ConformanceLevelToString(
|
|
|
|
ConformanceLevel level) const {
|
|
|
|
switch (level) {
|
|
|
|
case REQUIRED: return "Required";
|
|
|
|
case RECOMMENDED: return "Recommended";
|
|
|
|
}
|
|
|
|
GOOGLE_LOG(FATAL) << "Unknown value: " << level;
|
|
|
|
return "";
|
|
|
|
}
|
2018-07-09 21:29:23 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
string ConformanceTestSuite::ConformanceRequestSetting::
|
|
|
|
InputFormatString(conformance::WireFormat format) const {
|
|
|
|
switch (format) {
|
|
|
|
case conformance::PROTOBUF:
|
|
|
|
return "ProtobufInput";
|
|
|
|
case conformance::JSON:
|
|
|
|
return "JsonInput";
|
2018-07-09 21:29:23 +00:00
|
|
|
default:
|
|
|
|
GOOGLE_LOG(FATAL) << "Unspecified output format";
|
|
|
|
}
|
2018-08-09 00:00:41 +00:00
|
|
|
return "";
|
|
|
|
}
|
2018-07-09 21:29:23 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
string ConformanceTestSuite::ConformanceRequestSetting::
|
|
|
|
OutputFormatString(conformance::WireFormat format) const {
|
|
|
|
switch (format) {
|
|
|
|
case conformance::PROTOBUF:
|
|
|
|
return "ProtobufOutput";
|
|
|
|
case conformance::JSON:
|
|
|
|
return "JsonOutput";
|
|
|
|
default:
|
|
|
|
GOOGLE_LOG(FATAL) << "Unspecified output format";
|
2018-07-09 21:29:23 +00:00
|
|
|
}
|
2018-08-09 00:00:41 +00:00
|
|
|
return "";
|
2018-07-09 21:29:23 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
void ConformanceTestSuite::SetFailureList(
|
|
|
|
const string& filename,
|
|
|
|
const std::vector<string>& failure_list) {
|
|
|
|
failure_list_filename_ = filename;
|
|
|
|
expected_to_fail_.clear();
|
|
|
|
std::copy(failure_list.begin(), failure_list.end(),
|
|
|
|
std::inserter(expected_to_fail_, expected_to_fail_.end()));
|
2018-07-09 21:29:23 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 19:04:35 +00:00
|
|
|
void ConformanceTestSuite::ReportSuccess(const string& test_name) {
|
|
|
|
if (expected_to_fail_.erase(test_name) != 0) {
|
|
|
|
StringAppendF(&output_,
|
|
|
|
"ERROR: test %s is in the failure list, but test succeeded. "
|
|
|
|
"Remove it from the failure list.\n",
|
|
|
|
test_name.c_str());
|
|
|
|
unexpected_succeeding_tests_.insert(test_name);
|
|
|
|
}
|
2015-04-14 20:45:39 +00:00
|
|
|
successes_++;
|
|
|
|
}
|
|
|
|
|
2015-06-03 19:04:35 +00:00
|
|
|
void ConformanceTestSuite::ReportFailure(const string& test_name,
|
2016-09-19 20:45:07 +00:00
|
|
|
ConformanceLevel level,
|
2015-07-10 23:36:59 +00:00
|
|
|
const ConformanceRequest& request,
|
|
|
|
const ConformanceResponse& response,
|
2015-06-03 19:04:35 +00:00
|
|
|
const char* fmt, ...) {
|
|
|
|
if (expected_to_fail_.erase(test_name) == 1) {
|
2015-07-10 23:36:59 +00:00
|
|
|
expected_failures_++;
|
|
|
|
if (!verbose_)
|
|
|
|
return;
|
2016-09-19 20:45:07 +00:00
|
|
|
} else if (level == RECOMMENDED && !enforce_recommended_) {
|
|
|
|
StringAppendF(&output_, "WARNING, test=%s: ", test_name.c_str());
|
2015-06-03 19:04:35 +00:00
|
|
|
} else {
|
2015-06-04 22:04:00 +00:00
|
|
|
StringAppendF(&output_, "ERROR, test=%s: ", test_name.c_str());
|
2015-06-03 19:04:35 +00:00
|
|
|
unexpected_failing_tests_.insert(test_name);
|
|
|
|
}
|
2015-04-14 20:45:39 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
StringAppendV(&output_, fmt, args);
|
|
|
|
va_end(args);
|
2015-07-10 23:36:59 +00:00
|
|
|
StringAppendF(&output_, " request=%s, response=%s\n",
|
|
|
|
request.ShortDebugString().c_str(),
|
|
|
|
response.ShortDebugString().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConformanceTestSuite::ReportSkip(const string& test_name,
|
|
|
|
const ConformanceRequest& request,
|
|
|
|
const ConformanceResponse& response) {
|
|
|
|
if (verbose_) {
|
|
|
|
StringAppendF(&output_, "SKIPPED, test=%s request=%s, response=%s\n",
|
|
|
|
test_name.c_str(), request.ShortDebugString().c_str(),
|
|
|
|
response.ShortDebugString().c_str());
|
|
|
|
}
|
|
|
|
skipped_.insert(test_name);
|
2015-04-14 20:45:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 23:36:59 +00:00
|
|
|
void ConformanceTestSuite::RunValidInputTest(
|
2018-07-09 21:29:23 +00:00
|
|
|
const ConformanceRequestSetting& setting,
|
|
|
|
const string& equivalent_text_format) {
|
|
|
|
Message* reference_message = setting.GetTestMessage();
|
2015-07-10 23:36:59 +00:00
|
|
|
GOOGLE_CHECK(
|
2017-07-25 18:52:33 +00:00
|
|
|
TextFormat::ParseFromString(equivalent_text_format, reference_message))
|
2018-07-09 21:29:23 +00:00
|
|
|
<< "Failed to parse data for test case: " << setting.GetTestName()
|
2015-12-12 01:09:20 +00:00
|
|
|
<< ", data: " << equivalent_text_format;
|
2017-10-26 21:41:43 +00:00
|
|
|
const string equivalent_wire_format = reference_message->SerializeAsString();
|
2018-07-09 21:29:23 +00:00
|
|
|
RunValidBinaryInputTest(setting, equivalent_wire_format);
|
2017-10-26 21:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConformanceTestSuite::RunValidBinaryInputTest(
|
2018-07-09 21:29:23 +00:00
|
|
|
const ConformanceRequestSetting& setting,
|
|
|
|
const string& equivalent_wire_format) {
|
|
|
|
const string& test_name = setting.GetTestName();
|
|
|
|
ConformanceLevel level = setting.GetLevel();
|
|
|
|
|
|
|
|
Message* reference_message = setting.GetTestMessage();
|
2017-10-26 21:41:43 +00:00
|
|
|
GOOGLE_CHECK(
|
|
|
|
reference_message->ParseFromString(equivalent_wire_format))
|
|
|
|
<< "Failed to parse wire data for test case: " << test_name;
|
2015-07-10 23:36:59 +00:00
|
|
|
|
2018-07-09 21:29:23 +00:00
|
|
|
const ConformanceRequest& request = setting.GetRequest();
|
2015-07-10 23:36:59 +00:00
|
|
|
ConformanceResponse response;
|
|
|
|
|
|
|
|
RunTest(test_name, request, &response);
|
|
|
|
|
2018-07-09 21:29:23 +00:00
|
|
|
Message* test_message = setting.GetTestMessage();
|
|
|
|
|
|
|
|
WireFormat requested_output = request.requested_output_format();
|
2015-07-10 23:36:59 +00:00
|
|
|
|
|
|
|
switch (response.result_case()) {
|
2016-08-11 13:44:07 +00:00
|
|
|
case ConformanceResponse::RESULT_NOT_SET:
|
2016-09-20 00:29:57 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2016-08-11 13:44:07 +00:00
|
|
|
"Response didn't have any field in the Response.");
|
|
|
|
return;
|
|
|
|
|
2015-07-10 23:36:59 +00:00
|
|
|
case ConformanceResponse::kParseError:
|
|
|
|
case ConformanceResponse::kRuntimeError:
|
2015-12-12 01:09:20 +00:00
|
|
|
case ConformanceResponse::kSerializeError:
|
2016-09-20 00:29:57 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2016-08-11 13:44:07 +00:00
|
|
|
"Failed to parse input or produce output.");
|
2015-07-10 23:36:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ConformanceResponse::kSkipped:
|
|
|
|
ReportSkip(test_name, request, response);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ConformanceResponse::kJsonPayload: {
|
|
|
|
if (requested_output != conformance::JSON) {
|
|
|
|
ReportFailure(
|
2016-09-19 20:45:07 +00:00
|
|
|
test_name, level, request, response,
|
2015-07-10 23:36:59 +00:00
|
|
|
"Test was asked for protobuf output but provided JSON instead.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string binary_protobuf;
|
|
|
|
Status status =
|
|
|
|
JsonToBinaryString(type_resolver_.get(), type_url_,
|
|
|
|
response.json_payload(), &binary_protobuf);
|
|
|
|
if (!status.ok()) {
|
2016-09-19 20:45:07 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2015-07-10 23:36:59 +00:00
|
|
|
"JSON output we received from test was unparseable.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-25 18:52:33 +00:00
|
|
|
if (!test_message->ParseFromString(binary_protobuf)) {
|
2016-09-19 20:45:07 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2017-07-25 18:52:33 +00:00
|
|
|
"INTERNAL ERROR: internal JSON->protobuf transcode "
|
|
|
|
"yielded unparseable proto.");
|
2015-12-31 00:03:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-10 23:36:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ConformanceResponse::kProtobufPayload: {
|
|
|
|
if (requested_output != conformance::PROTOBUF) {
|
|
|
|
ReportFailure(
|
2016-09-19 20:45:07 +00:00
|
|
|
test_name, level, request, response,
|
2015-07-10 23:36:59 +00:00
|
|
|
"Test was asked for JSON output but provided protobuf instead.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-25 18:52:33 +00:00
|
|
|
if (!test_message->ParseFromString(response.protobuf_payload())) {
|
2016-09-19 20:45:07 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2017-07-25 18:52:33 +00:00
|
|
|
"Protobuf output we received from test was unparseable.");
|
2015-07-10 23:36:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-12-12 01:09:20 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: "
|
|
|
|
<< response.result_case();
|
2015-07-10 23:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageDifferencer differencer;
|
2015-12-12 01:09:20 +00:00
|
|
|
DefaultFieldComparator field_comparator;
|
|
|
|
field_comparator.set_treat_nan_as_equal(true);
|
|
|
|
differencer.set_field_comparator(&field_comparator);
|
2015-07-10 23:36:59 +00:00
|
|
|
string differences;
|
|
|
|
differencer.ReportDifferencesToString(&differences);
|
|
|
|
|
2017-07-25 18:52:33 +00:00
|
|
|
bool check;
|
|
|
|
check = differencer.Compare(*reference_message, *test_message);
|
|
|
|
if (check) {
|
2015-07-10 23:36:59 +00:00
|
|
|
ReportSuccess(test_name);
|
|
|
|
} else {
|
2016-09-19 20:45:07 +00:00
|
|
|
ReportFailure(test_name, level, request, response,
|
2015-07-10 23:36:59 +00:00
|
|
|
"Output was not equivalent to reference message: %s.",
|
|
|
|
differences.c_str());
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 20:45:39 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
void ConformanceTestSuite::RunTest(const string& test_name,
|
|
|
|
const ConformanceRequest& request,
|
|
|
|
ConformanceResponse* response) {
|
|
|
|
if (test_names_.insert(test_name).second == false) {
|
|
|
|
GOOGLE_LOG(FATAL) << "Duplicated test name: " << test_name;
|
2015-12-12 01:09:20 +00:00
|
|
|
}
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
string serialized_request;
|
|
|
|
string serialized_response;
|
|
|
|
request.SerializeToString(&serialized_request);
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
runner_->RunTest(test_name, serialized_request, &serialized_response);
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
if (!response->ParseFromString(serialized_response)) {
|
|
|
|
response->Clear();
|
|
|
|
response->set_runtime_error("response proto could not be parsed.");
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
2017-07-25 18:52:33 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
if (verbose_) {
|
|
|
|
StringAppendF(&output_,
|
|
|
|
"conformance test: name=%s, request=%s, response=%s\n",
|
|
|
|
test_name.c_str(),
|
|
|
|
request.ShortDebugString().c_str(),
|
|
|
|
response->ShortDebugString().c_str());
|
2016-12-14 00:31:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
bool ConformanceTestSuite::CheckSetEmpty(
|
|
|
|
const std::set<string>& set_to_check,
|
|
|
|
const std::string& write_to_file,
|
|
|
|
const std::string& msg) {
|
2015-06-03 19:04:35 +00:00
|
|
|
if (set_to_check.empty()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
StringAppendF(&output_, "\n");
|
2016-05-16 19:45:02 +00:00
|
|
|
StringAppendF(&output_, "%s\n\n", msg.c_str());
|
2017-07-10 03:31:50 +00:00
|
|
|
for (std::set<string>::const_iterator iter = set_to_check.begin();
|
2015-06-03 19:04:35 +00:00
|
|
|
iter != set_to_check.end(); ++iter) {
|
2015-07-10 23:36:59 +00:00
|
|
|
StringAppendF(&output_, " %s\n", iter->c_str());
|
2015-06-03 19:04:35 +00:00
|
|
|
}
|
2015-07-10 23:36:59 +00:00
|
|
|
StringAppendF(&output_, "\n");
|
2016-05-16 19:45:02 +00:00
|
|
|
|
|
|
|
if (!write_to_file.empty()) {
|
|
|
|
std::ofstream os(write_to_file);
|
|
|
|
if (os) {
|
2017-07-10 03:31:50 +00:00
|
|
|
for (std::set<string>::const_iterator iter = set_to_check.begin();
|
2016-05-16 19:45:02 +00:00
|
|
|
iter != set_to_check.end(); ++iter) {
|
|
|
|
os << *iter << "\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
StringAppendF(&output_, "Failed to open file: %s\n",
|
|
|
|
write_to_file.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-03 19:04:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
bool ConformanceTestSuite::RunSuite(
|
|
|
|
ConformanceTestRunner* runner, std::string* output) {
|
2015-04-14 20:45:39 +00:00
|
|
|
runner_ = runner;
|
|
|
|
successes_ = 0;
|
2015-07-10 23:36:59 +00:00
|
|
|
expected_failures_ = 0;
|
|
|
|
skipped_.clear();
|
2015-06-03 19:04:35 +00:00
|
|
|
test_names_.clear();
|
|
|
|
unexpected_failing_tests_.clear();
|
|
|
|
unexpected_succeeding_tests_.clear();
|
2015-07-10 23:36:59 +00:00
|
|
|
|
|
|
|
output_ = "\nCONFORMANCE TEST BEGIN ====================================\n\n";
|
2015-04-02 00:23:48 +00:00
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
RunSuiteImpl();
|
2018-07-09 21:29:23 +00:00
|
|
|
|
2015-12-12 01:09:20 +00:00
|
|
|
bool ok = true;
|
2016-05-16 19:45:02 +00:00
|
|
|
if (!CheckSetEmpty(expected_to_fail_, "nonexistent_tests.txt",
|
2015-12-12 01:09:20 +00:00
|
|
|
"These tests were listed in the failure list, but they "
|
2016-05-16 19:45:02 +00:00
|
|
|
"don't exist. Remove them from the failure list by "
|
|
|
|
"running:\n"
|
|
|
|
" ./update_failure_list.py " + failure_list_filename_ +
|
|
|
|
" --remove nonexistent_tests.txt")) {
|
2015-12-12 01:09:20 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
2016-05-16 19:45:02 +00:00
|
|
|
if (!CheckSetEmpty(unexpected_failing_tests_, "failing_tests.txt",
|
2015-12-12 01:09:20 +00:00
|
|
|
"These tests failed. If they can't be fixed right now, "
|
|
|
|
"you can add them to the failure list so the overall "
|
2016-05-16 19:45:02 +00:00
|
|
|
"suite can succeed. Add them to the failure list by "
|
|
|
|
"running:\n"
|
|
|
|
" ./update_failure_list.py " + failure_list_filename_ +
|
|
|
|
" --add failing_tests.txt")) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
if (!CheckSetEmpty(unexpected_succeeding_tests_, "succeeding_tests.txt",
|
|
|
|
"These tests succeeded, even though they were listed in "
|
|
|
|
"the failure list. Remove them from the failure list "
|
|
|
|
"by running:\n"
|
|
|
|
" ./update_failure_list.py " + failure_list_filename_ +
|
|
|
|
" --remove succeeding_tests.txt")) {
|
2015-12-12 01:09:20 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
2015-06-03 19:04:35 +00:00
|
|
|
|
2015-08-17 19:30:49 +00:00
|
|
|
if (verbose_) {
|
2016-05-16 19:45:02 +00:00
|
|
|
CheckSetEmpty(skipped_, "",
|
2015-08-17 19:30:49 +00:00
|
|
|
"These tests were skipped (probably because support for some "
|
|
|
|
"features is not implemented)");
|
|
|
|
}
|
2015-07-10 23:36:59 +00:00
|
|
|
|
|
|
|
StringAppendF(&output_,
|
|
|
|
"CONFORMANCE SUITE %s: %d successes, %d skipped, "
|
|
|
|
"%d expected failures, %d unexpected failures.\n",
|
|
|
|
ok ? "PASSED" : "FAILED", successes_, skipped_.size(),
|
|
|
|
expected_failures_, unexpected_failing_tests_.size());
|
|
|
|
StringAppendF(&output_, "\n");
|
|
|
|
|
2015-04-14 20:45:39 +00:00
|
|
|
output->assign(output_);
|
2015-06-03 19:04:35 +00:00
|
|
|
|
|
|
|
return ok;
|
2015-04-02 00:23:48 +00:00
|
|
|
}
|
2015-04-14 20:45:39 +00:00
|
|
|
|
|
|
|
} // namespace protobuf
|
|
|
|
} // namespace google
|