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