irccd  3.0.3
mock.hpp
1 /*
2  * mock.hpp -- keep track of function invocations
3  *
4  * Copyright (c) 2013-2019 David Demelier <markand@malikania.fr>
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef IRCCD_TEST_MOCK_HPP
20 #define IRCCD_TEST_MOCK_HPP
21 
27 #include <any>
28 #include <initializer_list>
29 #include <string>
30 #include <unordered_map>
31 #include <vector>
32 
33 namespace irccd::test {
34 
38 class mock {
39 public:
43  using args = std::vector<std::any>;
44 
48  using functions = std::unordered_map<std::string, std::vector<args>>;
49 
50 private:
51  mutable functions table_;
52 
53 public:
60  void push(std::string name, args args = {}) const;
61 
68  auto find(const std::string& name) const -> std::vector<args>;
69 
75  void clear(const std::string& name) const noexcept;
76 
80  void clear() const noexcept;
81 
87  auto empty() const noexcept -> bool;
88 };
89 
90 } // !irccd::test
91 
92 #endif // !IRCCD_TEST_MOCK_HPP
irccd::test::mock::find
auto find(const std::string &name) const -> std::vector< args >
irccd::test::mock::push
void push(std::string name, args args={}) const
irccd::test::mock::empty
auto empty() const noexcept -> bool
irccd::test::mock
Keep track of function invocations.
Definition: mock.hpp:38
irccd::test::mock::clear
void clear() const noexcept
irccd::test::mock::args
std::vector< std::any > args
Functions arguments.
Definition: mock.hpp:43
irccd::test::mock::clear
void clear(const std::string &name) const noexcept
irccd::test
Namespace for unit tests.
Definition: broken_plugin.hpp:29
irccd::test::mock::functions
std::unordered_map< std::string, std::vector< args > > functions
Map of all functions.
Definition: mock.hpp:48