<commit_before>#ifndef UNITTEST11_MOCK_HPP
#define UNITTEST11_MOCK_HPP

#include "Utility/MockArgumentHandler.hpp"
#include "Utility/MockReturnHandler.hpp"
#include "Assert/Fail.hpp"

#include <memory>

namespace ut11
{
    template<typename T> class Mock;
    template<typename R, typename... ARGS> class Mock<R (ARGS...)>
    {
    public:
    	Mock()
    		: m_callbackHandler(),
    		  m_argumentHandler(),
    		  m_returnHandler()
		{
		}

    	Mock(const Mock& orig)
    		: m_callbackHandler(orig.m_callbackHandler),
    		  m_argumentHandler(orig.m_argumentHandler),
    		  m_returnHandler(orig.m_returnHandler)
    	{
    	}

    	Mock& operator=(const Mock& orig)
    	{
    		m_callbackHandler = orig.m_callbackHandler;
    		m_argumentHandler = orig.m_argumentHandler;
    		m_returnHandler = orig.m_returnHandler;
    		return *this;
    	}

    	~Mock()
    	{
    	}

        inline R operator()(ARGS... args)
        {
            if ( m_callbackHandler )
                m_callbackHandler(args...);

            m_argumentHandler.AddCall(args...);
            return m_returnHandler(args...);
        }

        inline void SetCallback(std::function<void (const ARGS&...)> callback)
        {
            m_callbackHandler = callback;
        }

        template<typename V> inline void SetReturn(V value) { m_returnHandler.SetReturn(value); }

        inline void VerifyAny(std::size_t line, std::string file) const
        {
            if ( m_argumentHandler.TotalCount() == 0 )
                Assert::Fail(line, file, GetVerifyFailMessage());
        }

        template<typename... Expectations> inline void Verify(std::size_t line, std::string file, const Expectations&... expectations) const
        {
            if ( m_argumentHandler.CountCalls(expectations...) == 0 )
                Assert::Fail(line, file, GetVerifyFailMessage());
        }

        template<typename... Expectations> inline void VerifyTimes(std::size_t line, std::string file, std::size_t count, const Expectations&... expectations) const
        {
            if ( m_argumentHandler.CountCalls(expectations...) != count )
                Assert::Fail(line, file, GetVerifyFailMessage());
        }

    private:
        inline std::string GetVerifyFailMessage() const
        {
            return "Expected function call was not found";
        }

        std::function<void (const ARGS&...)> m_callbackHandler;
        Utility::MockArgumentHandler<ARGS...> m_argumentHandler;
        Utility::MockReturnHandler<R, ARGS...> m_returnHandler;
    };
}


#endif // UNITTEST11_MOCK_HPP<commit_msg>Mock now has different failure message for VerifyTimes<commit_after>#ifndef UNITTEST11_MOCK_HPP
#define UNITTEST11_MOCK_HPP

#include "Utility/MockArgumentHandler.hpp"
#include "Utility/MockReturnHandler.hpp"
#include "Assert/Fail.hpp"

#include <memory>

namespace ut11
{
    template<typename T> class Mock;
    template<typename R, typename... ARGS> class Mock<R (ARGS...)>
    {
    public:
    	Mock()
    		: m_callbackHandler(),
    		  m_argumentHandler(),
    		  m_returnHandler()
		{
		}

    	Mock(const Mock& orig)
    		: m_callbackHandler(orig.m_callbackHandler),
    		  m_argumentHandler(orig.m_argumentHandler),
    		  m_returnHandler(orig.m_returnHandler)
    	{
    	}

    	Mock& operator=(const Mock& orig)
    	{
    		m_callbackHandler = orig.m_callbackHandler;
    		m_argumentHandler = orig.m_argumentHandler;
    		m_returnHandler = orig.m_returnHandler;
    		return *this;
    	}

    	~Mock()
    	{
    	}

        inline R operator()(ARGS... args)
        {
            if ( m_callbackHandler )
                m_callbackHandler(args...);

            m_argumentHandler.AddCall(args...);
            return m_returnHandler(args...);
        }

        inline void SetCallback(std::function<void (const ARGS&...)> callback)
        {
            m_callbackHandler = callback;
        }

        template<typename V> inline void SetReturn(V value) { m_returnHandler.SetReturn(value); }

        inline void VerifyAny(std::size_t line, std::string file) const
        {
            if ( m_argumentHandler.TotalCount() == 0 )
                Assert::Fail(line, file, GetVerifyFailMessage());
        }

        template<typename... Expectations> inline void Verify(std::size_t line, std::string file, const Expectations&... expectations) const
        {
            if ( m_argumentHandler.CountCalls(expectations...) == 0 )
                Assert::Fail(line, file, GetVerifyFailMessage());
        }

        template<typename... Expectations> inline void VerifyTimes(std::size_t line, std::string file, std::size_t count, const Expectations&... expectations) const
        {
        	auto actual = m_argumentHandler.CountCalls(expectations...);
            if ( actual != count )
                Assert::Fail(line, file, GetVerifyFailTimesMessage(count, actual));
        }

    private:
        inline std::string GetVerifyFailMessage() const
        {
            return "Expected function call was not found";
        }

        inline std::string GetVerifyFailTimesMessage(std::size_t expected, std::size_t actual) const
        {
        	std::stringstream output;
        	output << "Expected function to be called " << expected << " times was actually called " << actual << " times";
        	return output.str();
        }

        std::function<void (const ARGS&...)> m_callbackHandler;
        Utility::MockArgumentHandler<ARGS...> m_argumentHandler;
        Utility::MockReturnHandler<R, ARGS...> m_returnHandler;
    };
}


#endif // UNITTEST11_MOCK_HPP
{'fraction_non_alphanumeric': 0.11373390557939914, 'fraction_numerical': 0.00357653791130186, 'mean_word_length': 2.4439655172413794, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3214538', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1626, 'n_words': 330}