Home | History | Annotate | Line # | Download | only in engine
      1 // Copyright 2010 Google Inc.
      2 // All rights reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 // * Redistributions of source code must retain the above copyright
      9 //   notice, this list of conditions and the following disclaimer.
     10 // * Redistributions in binary form must reproduce the above copyright
     11 //   notice, this list of conditions and the following disclaimer in the
     12 //   documentation and/or other materials provided with the distribution.
     13 // * Neither the name of Google Inc. nor the names of its contributors
     14 //   may be used to endorse or promote products derived from this software
     15 //   without specific prior written permission.
     16 //
     17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 
     29 /// \file engine/test_case.hpp
     30 /// Interface to interact with test cases.
     31 
     32 #if !defined(ENGINE_TEST_CASE_HPP)
     33 #define ENGINE_TEST_CASE_HPP
     34 
     35 #include <ostream>
     36 #include <string>
     37 
     38 #include "engine/metadata.hpp"
     39 #include "utils/config/tree.hpp"
     40 #include "utils/fs/path.hpp"
     41 #include "utils/optional.hpp"
     42 #include "utils/shared_ptr.hpp"
     43 
     44 namespace engine {
     45 
     46 
     47 class test_result;
     48 class test_program;
     49 
     50 
     51 /// Hooks to introspect the execution of a test case.
     52 ///
     53 /// There is no guarantee that these hooks will be called during the execution
     54 /// of the test case.  There are conditions in which they don't make sense.
     55 ///
     56 /// Note that this class is not abstract.  All hooks have default, empty
     57 /// implementations.  The purpose of this is to simplify some tests that need to
     58 /// pass hooks but that are not interested in the results.  We might want to
     59 /// rethink this and provide an "empty subclass" of a base abstract template.
     60 class test_case_hooks {
     61 public:
     62     virtual ~test_case_hooks(void);
     63 
     64     virtual void got_stdout(const utils::fs::path&);
     65     virtual void got_stderr(const utils::fs::path&);
     66 };
     67 
     68 
     69 /// Representation of a test case.
     70 class test_case {
     71     struct impl;
     72 
     73     /// Pointer to the shared internal implementation.
     74     std::shared_ptr< impl > _pimpl;
     75 
     76 public:
     77     test_case(const std::string&, const test_program&,
     78               const std::string&, const metadata&);
     79     test_case(const std::string&, const test_program&,
     80               const std::string&, const std::string&,
     81               const engine::test_result&);
     82     ~test_case(void);
     83 
     84     const std::string& interface_name(void) const;
     85     const test_program& container_test_program(void) const;
     86     const std::string& name(void) const;
     87     const metadata& get_metadata(void) const;
     88     utils::optional< test_result > fake_result(void) const;
     89 
     90     bool operator==(const test_case&) const;
     91     bool operator!=(const test_case&) const;
     92 };
     93 
     94 
     95 std::ostream& operator<<(std::ostream&, const test_case&);
     96 
     97 
     98 /// Pointer to a test case.
     99 typedef std::shared_ptr< test_case > test_case_ptr;
    100 
    101 
    102 test_result debug_test_case(const test_case*, const utils::config::tree&,
    103                             test_case_hooks&, const utils::fs::path&,
    104                             const utils::fs::path&, const utils::fs::path&);
    105 test_result run_test_case(const test_case*, const utils::config::tree&,
    106                           test_case_hooks&, const utils::fs::path&);
    107 
    108 
    109 }  // namespace engine
    110 
    111 
    112 #endif  // !defined(ENGINE_TEST_CASE_HPP)
    113