binary_json_conformance_suite.h 5.5 KB

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