| OLD | NEW |
| (Empty) |
| 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 | |
| 31 | |
| 32 // This file defines a protocol for running the conformance test suite | |
| 33 // in-process. In other words, the suite itself will run in the same process as | |
| 34 // the code under test. | |
| 35 // | |
| 36 // For pros and cons of this approach, please see conformance.proto. | |
| 37 | |
| 38 #ifndef CONFORMANCE_CONFORMANCE_TEST_H | |
| 39 #define CONFORMANCE_CONFORMANCE_TEST_H | |
| 40 | |
| 41 #include <string> | |
| 42 #include <google/protobuf/stubs/common.h> | |
| 43 #include <google/protobuf/util/type_resolver.h> | |
| 44 #include <google/protobuf/wire_format_lite.h> | |
| 45 | |
| 46 namespace conformance { | |
| 47 class ConformanceRequest; | |
| 48 class ConformanceResponse; | |
| 49 } // namespace conformance | |
| 50 | |
| 51 namespace google { | |
| 52 namespace protobuf { | |
| 53 | |
| 54 class ConformanceTestRunner { | |
| 55 public: | |
| 56 // Call to run a single conformance test. | |
| 57 // | |
| 58 // "input" is a serialized conformance.ConformanceRequest. | |
| 59 // "output" should be set to a serialized conformance.ConformanceResponse. | |
| 60 // | |
| 61 // If there is any error in running the test itself, set "runtime_error" in | |
| 62 // the response. | |
| 63 virtual void RunTest(const std::string& input, std::string* output) = 0; | |
| 64 }; | |
| 65 | |
| 66 // Class representing the test suite itself. To run it, implement your own | |
| 67 // class derived from ConformanceTestRunner and then write code like: | |
| 68 // | |
| 69 // class MyConformanceTestRunner : public ConformanceTestRunner { | |
| 70 // public: | |
| 71 // virtual void RunTest(...) { | |
| 72 // // INSERT YOUR FRAMEWORK-SPECIFIC CODE HERE. | |
| 73 // } | |
| 74 // }; | |
| 75 // | |
| 76 // int main() { | |
| 77 // MyConformanceTestRunner runner; | |
| 78 // google::protobuf::ConformanceTestSuite suite; | |
| 79 // | |
| 80 // std::string output; | |
| 81 // suite.RunSuite(&runner, &output); | |
| 82 // } | |
| 83 // | |
| 84 class ConformanceTestSuite { | |
| 85 public: | |
| 86 ConformanceTestSuite() : verbose_(false) {} | |
| 87 | |
| 88 void SetVerbose(bool verbose) { verbose_ = verbose; } | |
| 89 | |
| 90 // Sets the list of tests that are expected to fail when RunSuite() is called. | |
| 91 // RunSuite() will fail unless the set of failing tests is exactly the same | |
| 92 // as this list. | |
| 93 void SetFailureList(const std::vector<std::string>& failure_list); | |
| 94 | |
| 95 // Run all the conformance tests against the given test runner. | |
| 96 // Test output will be stored in "output". | |
| 97 // | |
| 98 // Returns true if the set of failing tests was exactly the same as the | |
| 99 // failure list. If SetFailureList() was not called, returns true if all | |
| 100 // tests passed. | |
| 101 bool RunSuite(ConformanceTestRunner* runner, std::string* output); | |
| 102 | |
| 103 private: | |
| 104 void ReportSuccess(const std::string& test_name); | |
| 105 void ReportFailure(const string& test_name, | |
| 106 const conformance::ConformanceRequest& request, | |
| 107 const conformance::ConformanceResponse& response, | |
| 108 const char* fmt, ...); | |
| 109 void ReportSkip(const string& test_name, | |
| 110 const conformance::ConformanceRequest& request, | |
| 111 const conformance::ConformanceResponse& response); | |
| 112 void RunTest(const std::string& test_name, | |
| 113 const conformance::ConformanceRequest& request, | |
| 114 conformance::ConformanceResponse* response); | |
| 115 void RunValidInputTest(const string& test_name, const string& input, | |
| 116 conformance::WireFormat input_format, | |
| 117 const string& equivalent_text_format, | |
| 118 conformance::WireFormat requested_output); | |
| 119 void RunValidJsonTest(const string& test_name, const string& input_json, | |
| 120 const string& equivalent_text_format); | |
| 121 void ExpectParseFailureForProto(const std::string& proto, | |
| 122 const std::string& test_name); | |
| 123 void ExpectHardParseFailureForProto(const std::string& proto, | |
| 124 const std::string& test_name); | |
| 125 void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); | |
| 126 bool CheckSetEmpty(const set<string>& set_to_check, const char* msg); | |
| 127 ConformanceTestRunner* runner_; | |
| 128 int successes_; | |
| 129 int expected_failures_; | |
| 130 bool verbose_; | |
| 131 std::string output_; | |
| 132 | |
| 133 // The set of test names that are expected to fail in this run, but haven't | |
| 134 // failed yet. | |
| 135 std::set<std::string> expected_to_fail_; | |
| 136 | |
| 137 // The set of test names that have been run. Used to ensure that there are no | |
| 138 // duplicate names in the suite. | |
| 139 std::set<std::string> test_names_; | |
| 140 | |
| 141 // The set of tests that failed, but weren't expected to. | |
| 142 std::set<std::string> unexpected_failing_tests_; | |
| 143 | |
| 144 // The set of tests that succeeded, but weren't expected to. | |
| 145 std::set<std::string> unexpected_succeeding_tests_; | |
| 146 | |
| 147 // The set of tests that the testee opted out of; | |
| 148 std::set<std::string> skipped_; | |
| 149 | |
| 150 google::protobuf::internal::scoped_ptr<google::protobuf::util::TypeResolver> | |
| 151 type_resolver_; | |
| 152 std::string type_url_; | |
| 153 }; | |
| 154 | |
| 155 } // namespace protobuf | |
| 156 } // namespace google | |
| 157 | |
| 158 #endif // CONFORMANCE_CONFORMANCE_TEST_H | |
| OLD | NEW |