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