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

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

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Created 4 years, 1 month 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // int main() { 84 // int main() {
85 // MyConformanceTestRunner runner; 85 // MyConformanceTestRunner runner;
86 // google::protobuf::ConformanceTestSuite suite; 86 // google::protobuf::ConformanceTestSuite suite;
87 // 87 //
88 // std::string output; 88 // std::string output;
89 // suite.RunSuite(&runner, &output); 89 // suite.RunSuite(&runner, &output);
90 // } 90 // }
91 // 91 //
92 class ConformanceTestSuite { 92 class ConformanceTestSuite {
93 public: 93 public:
94 ConformanceTestSuite() : verbose_(false) {} 94 ConformanceTestSuite() : verbose_(false), enforce_recommended_(false) {}
95 95
96 void SetVerbose(bool verbose) { verbose_ = verbose; } 96 void SetVerbose(bool verbose) { verbose_ = verbose; }
97 97
98 // Sets the list of tests that are expected to fail when RunSuite() is called. 98 // Sets the list of tests that are expected to fail when RunSuite() is called.
99 // RunSuite() will fail unless the set of failing tests is exactly the same 99 // RunSuite() will fail unless the set of failing tests is exactly the same
100 // as this list. 100 // as this list.
101 void SetFailureList(const std::vector<std::string>& failure_list); 101 //
102 // The filename here is *only* used to create/format useful error messages for
103 // how to update the failure list. We do NOT read this file at all.
104 void SetFailureList(const std::string& filename,
105 const std::vector<std::string>& failure_list);
106
107 // Whether to require the testee to pass RECOMMENDED tests. By default failing
108 // a RECOMMENDED test case will not fail the entire suite but will only
109 // generated a warning. If this flag is set to true, RECOMMENDED tests will
110 // be treated the same way as REQUIRED tests and failing a RECOMMENDED test
111 // case will cause the entire test suite to fail as well. An implementation
112 // can enable this if it wants to be strictly conforming to protobuf spec.
113 // See the comments about ConformanceLevel below to learn more about the
114 // difference between REQUIRED and RECOMMENDED test cases.
115 void SetEnforceRecommended(bool value) {
116 enforce_recommended_ = value;
117 }
102 118
103 // Run all the conformance tests against the given test runner. 119 // Run all the conformance tests against the given test runner.
104 // Test output will be stored in "output". 120 // Test output will be stored in "output".
105 // 121 //
106 // Returns true if the set of failing tests was exactly the same as the 122 // Returns true if the set of failing tests was exactly the same as the
107 // failure list. If SetFailureList() was not called, returns true if all 123 // failure list. If SetFailureList() was not called, returns true if all
108 // tests passed. 124 // tests passed.
109 bool RunSuite(ConformanceTestRunner* runner, std::string* output); 125 bool RunSuite(ConformanceTestRunner* runner, std::string* output);
110 126
111 private: 127 private:
128 // Test cases are classified into a few categories:
129 // REQUIRED: the test case must be passed for an implementation to be
130 // interoperable with other implementations. For example, a
131 // parser implementaiton must accept both packed and unpacked
132 // form of repeated primitive fields.
133 // RECOMMENDED: the test case is not required for the implementation to
134 // be interoperable with other implementations, but is
135 // recommended for best performance and compatibility. For
136 // example, a proto3 serializer should serialize repeated
137 // primitive fields in packed form, but an implementation
138 // failing to do so will still be able to communicate with
139 // other implementations.
140 enum ConformanceLevel {
141 REQUIRED = 0,
142 RECOMMENDED = 1,
143 };
144 string ConformanceLevelToString(ConformanceLevel level);
145
112 void ReportSuccess(const std::string& test_name); 146 void ReportSuccess(const std::string& test_name);
113 void ReportFailure(const string& test_name, 147 void ReportFailure(const string& test_name,
148 ConformanceLevel level,
114 const conformance::ConformanceRequest& request, 149 const conformance::ConformanceRequest& request,
115 const conformance::ConformanceResponse& response, 150 const conformance::ConformanceResponse& response,
116 const char* fmt, ...); 151 const char* fmt, ...);
117 void ReportSkip(const string& test_name, 152 void ReportSkip(const string& test_name,
118 const conformance::ConformanceRequest& request, 153 const conformance::ConformanceRequest& request,
119 const conformance::ConformanceResponse& response); 154 const conformance::ConformanceResponse& response);
120 void RunTest(const std::string& test_name, 155 void RunTest(const std::string& test_name,
121 const conformance::ConformanceRequest& request, 156 const conformance::ConformanceRequest& request,
122 conformance::ConformanceResponse* response); 157 conformance::ConformanceResponse* response);
123 void RunValidInputTest(const string& test_name, const string& input, 158 void RunValidInputTest(const string& test_name,
159 ConformanceLevel level,
160 const string& input,
124 conformance::WireFormat input_format, 161 conformance::WireFormat input_format,
125 const string& equivalent_text_format, 162 const string& equivalent_text_format,
126 conformance::WireFormat requested_output); 163 conformance::WireFormat requested_output);
127 void RunValidJsonTest(const string& test_name, const string& input_json, 164 void RunValidJsonTest(const string& test_name,
165 ConformanceLevel level,
166 const string& input_json,
128 const string& equivalent_text_format); 167 const string& equivalent_text_format);
129 void RunValidJsonTestWithProtobufInput(const string& test_name, 168 void RunValidJsonTestWithProtobufInput(const string& test_name,
169 ConformanceLevel level,
130 const conformance::TestAllTypes& input, 170 const conformance::TestAllTypes& input,
131 const string& equivalent_text_format); 171 const string& equivalent_text_format);
172 void RunValidProtobufTest(const string& test_name,
173 ConformanceLevel level,
174 const conformance::TestAllTypes& input,
175 const string& equivalent_text_format);
132 176
133 typedef std::function<bool(const Json::Value&)> Validator; 177 typedef std::function<bool(const Json::Value&)> Validator;
134 void RunValidJsonTestWithValidator(const string& test_name, 178 void RunValidJsonTestWithValidator(const string& test_name,
179 ConformanceLevel level,
135 const string& input_json, 180 const string& input_json,
136 const Validator& validator); 181 const Validator& validator);
137 void ExpectParseFailureForJson(const string& test_name, 182 void ExpectParseFailureForJson(const string& test_name,
183 ConformanceLevel level,
138 const string& input_json); 184 const string& input_json);
139 void ExpectSerializeFailureForJson(const string& test_name, 185 void ExpectSerializeFailureForJson(const string& test_name,
186 ConformanceLevel level,
140 const string& text_format); 187 const string& text_format);
141 void ExpectParseFailureForProto(const std::string& proto, 188 void ExpectParseFailureForProto(const std::string& proto,
142 const std::string& test_name); 189 const std::string& test_name,
190 ConformanceLevel level);
143 void ExpectHardParseFailureForProto(const std::string& proto, 191 void ExpectHardParseFailureForProto(const std::string& proto,
144 const std::string& test_name); 192 const std::string& test_name,
193 ConformanceLevel level);
145 void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); 194 void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
146 bool CheckSetEmpty(const set<string>& set_to_check, const char* msg); 195 bool CheckSetEmpty(const set<string>& set_to_check,
196 const std::string& write_to_file, const std::string& msg);
147 ConformanceTestRunner* runner_; 197 ConformanceTestRunner* runner_;
148 int successes_; 198 int successes_;
149 int expected_failures_; 199 int expected_failures_;
150 bool verbose_; 200 bool verbose_;
201 bool enforce_recommended_;
151 std::string output_; 202 std::string output_;
203 std::string failure_list_filename_;
152 204
153 // The set of test names that are expected to fail in this run, but haven't 205 // The set of test names that are expected to fail in this run, but haven't
154 // failed yet. 206 // failed yet.
155 std::set<std::string> expected_to_fail_; 207 std::set<std::string> expected_to_fail_;
156 208
157 // The set of test names that have been run. Used to ensure that there are no 209 // The set of test names that have been run. Used to ensure that there are no
158 // duplicate names in the suite. 210 // duplicate names in the suite.
159 std::set<std::string> test_names_; 211 std::set<std::string> test_names_;
160 212
161 // The set of tests that failed, but weren't expected to. 213 // The set of tests that failed, but weren't expected to.
162 std::set<std::string> unexpected_failing_tests_; 214 std::set<std::string> unexpected_failing_tests_;
163 215
164 // The set of tests that succeeded, but weren't expected to. 216 // The set of tests that succeeded, but weren't expected to.
165 std::set<std::string> unexpected_succeeding_tests_; 217 std::set<std::string> unexpected_succeeding_tests_;
166 218
167 // The set of tests that the testee opted out of; 219 // The set of tests that the testee opted out of;
168 std::set<std::string> skipped_; 220 std::set<std::string> skipped_;
169 221
170 google::protobuf::internal::scoped_ptr<google::protobuf::util::TypeResolver> 222 google::protobuf::internal::scoped_ptr<google::protobuf::util::TypeResolver>
171 type_resolver_; 223 type_resolver_;
172 std::string type_url_; 224 std::string type_url_;
173 }; 225 };
174 226
175 } // namespace protobuf 227 } // namespace protobuf
176 } // namespace google 228 } // namespace google
177 229
178 #endif // CONFORMANCE_CONFORMANCE_TEST_H 230 #endif // CONFORMANCE_CONFORMANCE_TEST_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698