Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 3 | // |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file or at |
| 6 | // https://developers.google.com/open-source/licenses/bsd |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 7 | |
| 8 | #ifndef TEXT_FORMAT_CONFORMANCE_SUITE_H_ |
| 9 | #define TEXT_FORMAT_CONFORMANCE_SUITE_H_ |
| 10 | |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 11 | #include <string> |
| 12 | |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 13 | #include "conformance_test.h" |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 14 | #include "google/protobuf/message.h" |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 15 | |
| 16 | namespace google { |
| 17 | namespace protobuf { |
| 18 | |
| 19 | class TextFormatConformanceTestSuite : public ConformanceTestSuite { |
| 20 | public: |
| 21 | TextFormatConformanceTestSuite(); |
| 22 | |
| 23 | private: |
Deanna Garcia | 380e352 | 2021-05-14 17:50:31 +0000 | [diff] [blame] | 24 | void RunSuiteImpl() override; |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 25 | |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 26 | bool ParseTextFormatResponse(const conformance::ConformanceResponse& response, |
Hao Nguyen | 2f864fd | 2019-03-20 11:45:01 -0700 | [diff] [blame] | 27 | const ConformanceRequestSetting& setting, |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 28 | Message* test_message); |
| 29 | bool ParseResponse(const conformance::ConformanceResponse& response, |
| 30 | const ConformanceRequestSetting& setting, |
| 31 | Message* test_message) override; |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 32 | |
| 33 | template <typename MessageType> |
| 34 | friend class TextFormatConformanceTestSuiteImpl; |
| 35 | }; |
| 36 | |
| 37 | template <typename MessageType> |
| 38 | class TextFormatConformanceTestSuiteImpl { |
| 39 | public: |
| 40 | explicit TextFormatConformanceTestSuiteImpl( |
| 41 | TextFormatConformanceTestSuite* suite); |
| 42 | |
| 43 | private: |
| 44 | using ConformanceRequestSetting = |
| 45 | TextFormatConformanceTestSuite::ConformanceRequestSetting; |
| 46 | using ConformanceLevel = TextFormatConformanceTestSuite::ConformanceLevel; |
| 47 | constexpr static ConformanceLevel RECOMMENDED = ConformanceLevel::RECOMMENDED; |
| 48 | constexpr static ConformanceLevel REQUIRED = ConformanceLevel::REQUIRED; |
| 49 | |
| 50 | void RunAllTests(); |
| 51 | |
Mike Kruskal | 8ab39ed | 2024-04-05 10:09:52 -0700 | [diff] [blame] | 52 | void RunDelimitedTests(); |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 53 | void RunGroupTests(); |
| 54 | void RunAnyTests(); |
| 55 | |
| 56 | void RunTextFormatPerformanceTests(); |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 57 | void RunValidTextFormatTest(const std::string& test_name, |
| 58 | ConformanceLevel level, const std::string& input); |
| 59 | void RunValidTextFormatTestWithExpected(const std::string& test_name, |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 60 | ConformanceLevel level, |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 61 | const std::string& input_text, |
| 62 | const std::string& expected_text); |
| 63 | void RunValidUnknownTextFormatTest(const std::string& test_name, |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 64 | const Message& message); |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 65 | void RunValidTextFormatTestWithMessage(const std::string& test_name, |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 66 | ConformanceLevel level, |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 67 | const std::string& input_text, |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 68 | const Message& message); |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 69 | void ExpectParseFailure(const std::string& test_name, ConformanceLevel level, |
| 70 | const std::string& input); |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 71 | void TestTextFormatPerformanceMergeMessageWithRepeatedField( |
Protobuf Team Bot | 32bedd9 | 2024-06-28 09:09:12 -0700 | [diff] [blame] | 72 | const std::string& test_type_name, const std::string& message_field); |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 73 | |
| 74 | TextFormatConformanceTestSuite& suite_; |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace protobuf |
| 78 | } // namespace google |
| 79 | |
| 80 | #endif // TEXT_FORMAT_CONFORMANCE_SUITE_H_ |