blob: c64a333b2bdd8fd2751e6aefa4cd7a005fe53474 [file] [log] [blame]
Yilun Chongd8c25012019-02-22 18:13:33 +08001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
Yilun Chongd8c25012019-02-22 18:13:33 +08003//
Joshua Haberman8a4bfd62023-09-08 19:26:10 -07004// 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 Chongd8c25012019-02-22 18:13:33 +08007
8#ifndef TEXT_FORMAT_CONFORMANCE_SUITE_H_
9#define TEXT_FORMAT_CONFORMANCE_SUITE_H_
10
Mike Kruskal39752aa2023-10-17 16:58:29 -070011#include <string>
12
Yilun Chongd8c25012019-02-22 18:13:33 +080013#include "conformance_test.h"
Mike Kruskal39752aa2023-10-17 16:58:29 -070014#include "google/protobuf/message.h"
Yilun Chongd8c25012019-02-22 18:13:33 +080015
16namespace google {
17namespace protobuf {
18
19class TextFormatConformanceTestSuite : public ConformanceTestSuite {
20 public:
21 TextFormatConformanceTestSuite();
22
23 private:
Deanna Garcia380e3522021-05-14 17:50:31 +000024 void RunSuiteImpl() override;
Mike Kruskal28e573e2023-10-17 17:26:08 -070025
Yilun Chongd8c25012019-02-22 18:13:33 +080026 bool ParseTextFormatResponse(const conformance::ConformanceResponse& response,
Hao Nguyen2f864fd2019-03-20 11:45:01 -070027 const ConformanceRequestSetting& setting,
Yilun Chongd8c25012019-02-22 18:13:33 +080028 Message* test_message);
29 bool ParseResponse(const conformance::ConformanceResponse& response,
30 const ConformanceRequestSetting& setting,
31 Message* test_message) override;
Mike Kruskal28e573e2023-10-17 17:26:08 -070032
33 template <typename MessageType>
34 friend class TextFormatConformanceTestSuiteImpl;
35};
36
37template <typename MessageType>
38class 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 Kruskal8ab39ed2024-04-05 10:09:52 -070052 void RunDelimitedTests();
Mike Kruskal28e573e2023-10-17 17:26:08 -070053 void RunGroupTests();
54 void RunAnyTests();
55
56 void RunTextFormatPerformanceTests();
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070057 void RunValidTextFormatTest(const std::string& test_name,
58 ConformanceLevel level, const std::string& input);
59 void RunValidTextFormatTestWithExpected(const std::string& test_name,
Mike Kruskal28e573e2023-10-17 17:26:08 -070060 ConformanceLevel level,
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070061 const std::string& input_text,
62 const std::string& expected_text);
63 void RunValidUnknownTextFormatTest(const std::string& test_name,
Mike Kruskal28e573e2023-10-17 17:26:08 -070064 const Message& message);
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070065 void RunValidTextFormatTestWithMessage(const std::string& test_name,
Mike Kruskal28e573e2023-10-17 17:26:08 -070066 ConformanceLevel level,
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070067 const std::string& input_text,
Mike Kruskal28e573e2023-10-17 17:26:08 -070068 const Message& message);
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070069 void ExpectParseFailure(const std::string& test_name, ConformanceLevel level,
70 const std::string& input);
Mike Kruskal32bea522022-10-06 16:48:39 -070071 void TestTextFormatPerformanceMergeMessageWithRepeatedField(
Protobuf Team Bot32bedd92024-06-28 09:09:12 -070072 const std::string& test_type_name, const std::string& message_field);
Mike Kruskal28e573e2023-10-17 17:26:08 -070073
74 TextFormatConformanceTestSuite& suite_;
Yilun Chongd8c25012019-02-22 18:13:33 +080075};
76
77} // namespace protobuf
78} // namespace google
79
80#endif // TEXT_FORMAT_CONFORMANCE_SUITE_H_