• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "conformance_test.h"
35 #include "third_party/jsoncpp/json.h"
36 
37 namespace google {
38 namespace protobuf {
39 
40 class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
41  public:
BinaryAndJsonConformanceSuite()42   BinaryAndJsonConformanceSuite() {}
43 
44  private:
45   void RunSuiteImpl();
46   void RunValidJsonTest(const string& test_name,
47                         ConformanceLevel level,
48                         const string& input_json,
49                         const string& equivalent_text_format);
50   void RunValidJsonTestWithProtobufInput(
51       const string& test_name,
52       ConformanceLevel level,
53       const protobuf_test_messages::proto3::TestAllTypesProto3& input,
54       const string& equivalent_text_format);
55   void RunValidJsonIgnoreUnknownTest(
56       const string& test_name, ConformanceLevel level, const string& input_json,
57       const string& equivalent_text_format);
58   void RunValidProtobufTest(const string& test_name, ConformanceLevel level,
59                             const string& input_protobuf,
60                             const string& equivalent_text_format,
61                             bool is_proto3);
62   void RunValidBinaryProtobufTest(const string& test_name,
63                                   ConformanceLevel level,
64                                   const string& input_protobuf,
65                                   bool is_proto3);
66   void RunValidProtobufTestWithMessage(
67       const string& test_name, ConformanceLevel level,
68       const Message *input,
69       const string& equivalent_text_format,
70       bool is_proto3);
71 
72   bool ParseJsonResponse(
73       const conformance::ConformanceResponse& response,
74       Message* test_message);
75   bool ParseResponse(
76       const conformance::ConformanceResponse& response,
77       const ConformanceRequestSetting& setting,
78       Message* test_message) override;
79 
80   typedef std::function<bool(const Json::Value&)> Validator;
81   void RunValidJsonTestWithValidator(const string& test_name,
82                                      ConformanceLevel level,
83                                      const string& input_json,
84                                      const Validator& validator);
85   void ExpectParseFailureForJson(const string& test_name,
86                                  ConformanceLevel level,
87                                  const string& input_json);
88   void ExpectSerializeFailureForJson(const string& test_name,
89                                      ConformanceLevel level,
90                                      const string& text_format);
91   void ExpectParseFailureForProtoWithProtoVersion (const string& proto,
92                                                    const string& test_name,
93                                                    ConformanceLevel level,
94                                                    bool is_proto3);
95   void ExpectParseFailureForProto(const std::string& proto,
96                                   const std::string& test_name,
97                                   ConformanceLevel level);
98   void ExpectHardParseFailureForProto(const std::string& proto,
99                                       const std::string& test_name,
100                                       ConformanceLevel level);
101   void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
102   void TestIllegalTags();
103   template <class MessageType>
104   void TestOneofMessage (MessageType &message,
105                          bool is_proto3);
106   template <class MessageType>
107   void TestUnknownMessage (MessageType &message,
108                            bool is_proto3);
109   void TestValidDataForType(
110       google::protobuf::FieldDescriptor::Type,
111       std::vector<std::pair<std::string, std::string>> values);
112 
113   std::unique_ptr<google::protobuf::util::TypeResolver>
114       type_resolver_;
115   std::string type_url_;
116 };
117 
118 }  // namespace protobuf
119 }  // namespace google
120 
121 #endif  // CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H
122