binary_json_conformance_suite.h 6.7 KB

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