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

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

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

Powered by Google App Engine
This is Rietveld 408576698