@ -8,19 +8,53 @@
# ifndef CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H
# define CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H
# include <memory>
# include <string>
# include <utility>
# include <vector>
# include "json/json.h"
# include "conformance_test.h"
# include "google/protobuf/descriptor.h"
# include "google/protobuf/util/type_resolver.h"
namespace google {
namespace protobuf {
class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
public :
BinaryAndJsonConformanceSuite ( ) { }
BinaryAndJsonConformanceSuite ( ) = default ;
private :
void RunSuiteImpl ( ) override ;
bool ParseJsonResponse ( const conformance : : ConformanceResponse & response ,
Message * test_message ) ;
bool ParseResponse ( const conformance : : ConformanceResponse & response ,
const ConformanceRequestSetting & setting ,
Message * test_message ) override ;
template < typename MessageType >
friend class BinaryAndJsonConformanceSuiteImpl ;
std : : unique_ptr < google : : protobuf : : util : : TypeResolver > type_resolver_ ;
std : : string type_url_ ;
} ;
template < typename MessageType >
class BinaryAndJsonConformanceSuiteImpl {
public :
BinaryAndJsonConformanceSuiteImpl ( BinaryAndJsonConformanceSuite * suite ,
bool run_proto3_tests ) ;
private :
using ConformanceRequestSetting =
BinaryAndJsonConformanceSuite : : ConformanceRequestSetting ;
using ConformanceLevel = BinaryAndJsonConformanceSuite : : ConformanceLevel ;
constexpr static ConformanceLevel RECOMMENDED = ConformanceLevel : : RECOMMENDED ;
constexpr static ConformanceLevel REQUIRED = ConformanceLevel : : REQUIRED ;
void RunAllTests ( ) ;
void RunBinaryPerformanceTests ( ) ;
void RunJsonPerformanceTests ( ) ;
void RunJsonTests ( ) ;
@ -37,10 +71,6 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
void RunValidJsonTest ( const std : : string & test_name , ConformanceLevel level ,
const std : : string & input_json ,
const std : : string & equivalent_text_format ) ;
void RunValidJsonTest ( const std : : string & test_name , ConformanceLevel level ,
const std : : string & input_json ,
const std : : string & equivalent_text_format ,
bool is_proto3 ) ;
void RunValidJsonTestWithMessage ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_json ,
@ -57,38 +87,26 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
void RunValidProtobufTest ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_protobuf ,
const std : : string & equivalent_text_format ,
bool is_proto3 ) ;
const std : : string & equivalent_text_format ) ;
void RunValidBinaryProtobufTest ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_protobuf ,
bool is_proto3 ) ;
const std : : string & input_protobuf ) ;
void RunValidBinaryProtobufTest ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_protobuf ,
const std : : string & expected_protobuf ,
bool is_proto3 ) ;
void RunBinaryPerformanceMergeMessageWithField ( const std : : string & test_name ,
const std : : string & field_proto ,
bool is_proto3 ) ;
const std : : string & expected_protobuf ) ;
void RunBinaryPerformanceMergeMessageWithField (
const std : : string & test_name , const std : : string & field_proto ) ;
void RunValidProtobufTestWithMessage (
const std : : string & test_name , ConformanceLevel level ,
const Message * input , const std : : string & equivalent_text_format ,
bool is_proto3 ) ;
bool ParseJsonResponse ( const conformance : : ConformanceResponse & response ,
Message * test_message ) ;
bool ParseResponse ( const conformance : : ConformanceResponse & response ,
const ConformanceRequestSetting & setting ,
Message * test_message ) override ;
const Message * input , const std : : string & equivalent_text_format ) ;
typedef std : : function < bool ( const Json : : Value & ) > Validator ;
void RunValidJsonTestWithValidator ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_json ,
const Validator & validator ,
bool is_proto3 ) ;
const Validator & validator ) ;
void ExpectParseFailureForJson ( const std : : string & test_name ,
ConformanceLevel level ,
const std : : string & input_json ) ;
@ -97,8 +115,7 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
const std : : string & text_format ) ;
void ExpectParseFailureForProtoWithProtoVersion ( const std : : string & proto ,
const std : : string & test_name ,
ConformanceLevel level ,
bool is_proto3 ) ;
ConformanceLevel level ) ;
void ExpectParseFailureForProto ( const std : : string & proto ,
const std : : string & test_name ,
ConformanceLevel level ) ;
@ -107,10 +124,8 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
ConformanceLevel level ) ;
void TestPrematureEOFForType ( google : : protobuf : : FieldDescriptor : : Type type ) ;
void TestIllegalTags ( ) ;
template < class MessageType >
void TestOneofMessage ( MessageType & message , bool is_proto3 ) ;
template < class MessageType >
void TestUnknownMessage ( MessageType & message , bool is_proto3 ) ;
void TestOneofMessage ( ) ;
void TestUnknownMessage ( ) ;
void TestValidDataForType (
google : : protobuf : : FieldDescriptor : : Type ,
std : : vector < std : : pair < std : : string , std : : string > > values ) ;
@ -128,8 +143,22 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
void TestJsonPerformanceMergeMessageWithRepeatedFieldForType (
google : : protobuf : : FieldDescriptor : : Type , std : : string field_value ) ;
std : : unique_ptr < google : : protobuf : : util : : TypeResolver > type_resolver_ ;
std : : string type_url_ ;
enum class Packed {
kUnspecified = 0 ,
kTrue = 1 ,
kFalse = 2 ,
} ;
const FieldDescriptor * GetFieldForType (
FieldDescriptor : : Type type , bool repeated ,
Packed packed = Packed : : kUnspecified ) const ;
const FieldDescriptor * GetFieldForMapType (
FieldDescriptor : : Type key_type , FieldDescriptor : : Type value_type ) const ;
const FieldDescriptor * GetFieldForOneofType ( FieldDescriptor : : Type type ,
bool exclusive = false ) const ;
std : : string SyntaxIdentifier ( ) const ;
BinaryAndJsonConformanceSuite & suite_ ;
bool run_proto3_tests_ ;
} ;
} // namespace protobuf