16b3a42afSjmmv // Copyright 2010 Google Inc. 26b3a42afSjmmv // All rights reserved. 36b3a42afSjmmv // 46b3a42afSjmmv // Redistribution and use in source and binary forms, with or without 56b3a42afSjmmv // modification, are permitted provided that the following conditions are 66b3a42afSjmmv // met: 76b3a42afSjmmv // 86b3a42afSjmmv // * Redistributions of source code must retain the above copyright 96b3a42afSjmmv // notice, this list of conditions and the following disclaimer. 106b3a42afSjmmv // * Redistributions in binary form must reproduce the above copyright 116b3a42afSjmmv // notice, this list of conditions and the following disclaimer in the 126b3a42afSjmmv // documentation and/or other materials provided with the distribution. 136b3a42afSjmmv // * Neither the name of Google Inc. nor the names of its contributors 146b3a42afSjmmv // may be used to endorse or promote products derived from this software 156b3a42afSjmmv // without specific prior written permission. 166b3a42afSjmmv // 176b3a42afSjmmv // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186b3a42afSjmmv // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196b3a42afSjmmv // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206b3a42afSjmmv // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216b3a42afSjmmv // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226b3a42afSjmmv // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236b3a42afSjmmv // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246b3a42afSjmmv // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256b3a42afSjmmv // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266b3a42afSjmmv // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276b3a42afSjmmv // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286b3a42afSjmmv 296b3a42afSjmmv /// \file engine/test_case.hpp 306b3a42afSjmmv /// Interface to interact with test cases. 316b3a42afSjmmv 326b3a42afSjmmv #if !defined(ENGINE_TEST_CASE_HPP) 336b3a42afSjmmv #define ENGINE_TEST_CASE_HPP 346b3a42afSjmmv 356b3a42afSjmmv #include <ostream> 366b3a42afSjmmv #include <string> 376b3a42afSjmmv 386b3a42afSjmmv #include "engine/metadata.hpp" 396b3a42afSjmmv #include "utils/config/tree.hpp" 406b3a42afSjmmv #include "utils/fs/path.hpp" 416b3a42afSjmmv #include "utils/optional.hpp" 42*f39f9c9bSjmmv #include "utils/shared_ptr.hpp" 436b3a42afSjmmv 446b3a42afSjmmv namespace engine { 456b3a42afSjmmv 466b3a42afSjmmv 476b3a42afSjmmv class test_result; 486b3a42afSjmmv class test_program; 496b3a42afSjmmv 506b3a42afSjmmv 516b3a42afSjmmv /// Hooks to introspect the execution of a test case. 526b3a42afSjmmv /// 536b3a42afSjmmv /// There is no guarantee that these hooks will be called during the execution 546b3a42afSjmmv /// of the test case. There are conditions in which they don't make sense. 556b3a42afSjmmv /// 566b3a42afSjmmv /// Note that this class is not abstract. All hooks have default, empty 576b3a42afSjmmv /// implementations. The purpose of this is to simplify some tests that need to 586b3a42afSjmmv /// pass hooks but that are not interested in the results. We might want to 596b3a42afSjmmv /// rethink this and provide an "empty subclass" of a base abstract template. 606b3a42afSjmmv class test_case_hooks { 616b3a42afSjmmv public: 626b3a42afSjmmv virtual ~test_case_hooks(void); 636b3a42afSjmmv 646b3a42afSjmmv virtual void got_stdout(const utils::fs::path&); 656b3a42afSjmmv virtual void got_stderr(const utils::fs::path&); 666b3a42afSjmmv }; 676b3a42afSjmmv 686b3a42afSjmmv 696b3a42afSjmmv /// Representation of a test case. 706b3a42afSjmmv class test_case { 716b3a42afSjmmv struct impl; 726b3a42afSjmmv 736b3a42afSjmmv /// Pointer to the shared internal implementation. 74*f39f9c9bSjmmv std::shared_ptr< impl > _pimpl; 756b3a42afSjmmv 766b3a42afSjmmv public: 776b3a42afSjmmv test_case(const std::string&, const test_program&, 786b3a42afSjmmv const std::string&, const metadata&); 796b3a42afSjmmv test_case(const std::string&, const test_program&, 806b3a42afSjmmv const std::string&, const std::string&, 816b3a42afSjmmv const engine::test_result&); 826b3a42afSjmmv ~test_case(void); 836b3a42afSjmmv 846b3a42afSjmmv const std::string& interface_name(void) const; 856b3a42afSjmmv const test_program& container_test_program(void) const; 866b3a42afSjmmv const std::string& name(void) const; 876b3a42afSjmmv const metadata& get_metadata(void) const; 886b3a42afSjmmv utils::optional< test_result > fake_result(void) const; 896b3a42afSjmmv 906b3a42afSjmmv bool operator==(const test_case&) const; 916b3a42afSjmmv bool operator!=(const test_case&) const; 926b3a42afSjmmv }; 936b3a42afSjmmv 946b3a42afSjmmv 956b3a42afSjmmv std::ostream& operator<<(std::ostream&, const test_case&); 966b3a42afSjmmv 976b3a42afSjmmv 986b3a42afSjmmv /// Pointer to a test case. 99*f39f9c9bSjmmv typedef std::shared_ptr< test_case > test_case_ptr; 1006b3a42afSjmmv 1016b3a42afSjmmv 1026b3a42afSjmmv test_result debug_test_case(const test_case*, const utils::config::tree&, 1036b3a42afSjmmv test_case_hooks&, const utils::fs::path&, 1046b3a42afSjmmv const utils::fs::path&, const utils::fs::path&); 1056b3a42afSjmmv test_result run_test_case(const test_case*, const utils::config::tree&, 1066b3a42afSjmmv test_case_hooks&, const utils::fs::path&); 1076b3a42afSjmmv 1086b3a42afSjmmv 1096b3a42afSjmmv } // namespace engine 1106b3a42afSjmmv 1116b3a42afSjmmv 1126b3a42afSjmmv #endif // !defined(ENGINE_TEST_CASE_HPP) 113