Debian Codegraph @

extra/protobuf/protobuf-24.4/conformance/binary_json_conformance_suite.h

raw
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #ifndef CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H
32 #define CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H
33
34 #include "google/protobuf/descriptor.h"
35 #include "json/json.h"
36 #include "conformance_test.h"
37
38 namespace google {
39 namespace protobuf {
40
41 class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
42 public:
43 BinaryAndJsonConformanceSuite() {}
44
45 private:
46 void RunSuiteImpl() override;
47 void RunBinaryPerformanceTests();
48 void RunJsonPerformanceTests();
49 void RunJsonTests();
50 void RunJsonTestsForFieldNameConvention();
51 void RunJsonTestsForNonRepeatedTypes();
52 void RunJsonTestsForRepeatedTypes();
53 void RunJsonTestsForNullTypes();
54 void RunJsonTestsForWrapperTypes();
55 void RunJsonTestsForFieldMask();
56 void RunJsonTestsForStruct();
57 void RunJsonTestsForValue();
58 void RunJsonTestsForAny();
59 void RunJsonTestsForUnknownEnumStringValues();
60 void RunValidJsonTest(const std::string& test_name, ConformanceLevel level,
61 const std::string& input_json,
62 const std::string& equivalent_text_format);
63 void RunValidJsonTest(const std::string& test_name, ConformanceLevel level,
64 const std::string& input_json,
65 const std::string& equivalent_text_format,
66 bool is_proto3);
67 void RunValidJsonTestWithMessage(const std::string& test_name,
68 ConformanceLevel level,
69 const std::string& input_json,
70 const std::string& equivalent_text_forma,
71 const Message& prototype);
72 void RunValidJsonTestWithProtobufInput(
73 const std::string& test_name, ConformanceLevel level,
74 const protobuf_test_messages::proto3::TestAllTypesProto3& input,
75 const std::string& equivalent_text_format);
76 void RunValidJsonIgnoreUnknownTest(const std::string& test_name,
77 ConformanceLevel level,
78 const std::string& input_json,
79 const std::string& equivalent_text_format);
80 void RunValidProtobufTest(const std::string& test_name,
81 ConformanceLevel level,
82 const std::string& input_protobuf,
83 const std::string& equivalent_text_format,
84 bool is_proto3);
85 void RunValidBinaryProtobufTest(const std::string& test_name,
86 ConformanceLevel level,
87 const std::string& input_protobuf,
88 bool is_proto3);
89 void RunValidBinaryProtobufTest(const std::string& test_name,
90 ConformanceLevel level,
91 const std::string& input_protobuf,
92 const std::string& expected_protobuf,
93 bool is_proto3);
94 void RunBinaryPerformanceMergeMessageWithField(const std::string& test_name,
95 const std::string& field_proto,
96 bool is_proto3);
97
98 void RunValidProtobufTestWithMessage(
99 const std::string& test_name, ConformanceLevel level,
100 const Message* input, const std::string& equivalent_text_format,
101 bool is_proto3);
102
103 bool ParseJsonResponse(
104 const conformance::ConformanceResponse& response,
105 Message* test_message);
106 bool ParseResponse(
107 const conformance::ConformanceResponse& response,
108 const ConformanceRequestSetting& setting,
109 Message* test_message) override;
110
111 typedef std::function<bool(const Json::Value&)> Validator;
112 void RunValidJsonTestWithValidator(const std::string& test_name,
113 ConformanceLevel level,
114 const std::string& input_json,
115 const Validator& validator,
116 bool is_proto3);
117 void ExpectParseFailureForJson(const std::string& test_name,
118 ConformanceLevel level,
119 const std::string& input_json);
120 void ExpectSerializeFailureForJson(const std::string& test_name,
121 ConformanceLevel level,
122 const std::string& text_format);
123 void ExpectParseFailureForProtoWithProtoVersion(const std::string& proto,
124 const std::string& test_name,
125 ConformanceLevel level,
126 bool is_proto3);
127 void ExpectParseFailureForProto(const std::string& proto,
128 const std::string& test_name,
129 ConformanceLevel level);
130 void ExpectHardParseFailureForProto(const std::string& proto,
131 const std::string& test_name,
132 ConformanceLevel level);
133 void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
134 void TestIllegalTags();
135 template <class MessageType>
136 void TestOneofMessage (MessageType &message,
137 bool is_proto3);
138 template <class MessageType>
139 void TestUnknownMessage (MessageType &message,
140 bool is_proto3);
141 void TestValidDataForType(
142 google::protobuf::FieldDescriptor::Type,
143 std::vector<std::pair<std::string, std::string>> values);
144 void TestValidDataForRepeatedScalarMessage();
145 void TestValidDataForMapType(google::protobuf::FieldDescriptor::Type,
146 google::protobuf::FieldDescriptor::Type);
147 void TestValidDataForOneofType(google::protobuf::FieldDescriptor::Type);
148 void TestMergeOneofMessage();
149 void TestOverwriteMessageValueMap();
150 void TestBinaryPerformanceForAlternatingUnknownFields();
151 void TestBinaryPerformanceMergeMessageWithRepeatedFieldForType(
152 google::protobuf::FieldDescriptor::Type);
153 void TestBinaryPerformanceMergeMessageWithUnknownFieldForType(
154 google::protobuf::FieldDescriptor::Type);
155 void TestJsonPerformanceMergeMessageWithRepeatedFieldForType(
156 google::protobuf::FieldDescriptor::Type, std::string field_value);
157
158 std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver_;
159 std::string type_url_;
160 };
161
162 } // namespace protobuf
163 } // namespace google
164
165 #endif // CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H