view libirccd-test/irccd/test/mock.cpp @ 735:64839725f346

Tests: replace journal_server with mock_server
author David Demelier <markand@malikania.fr>
date Tue, 24 Jul 2018 22:00:00 +0200
parents
children 199f36d4edc8
line wrap: on
line source

/*
 * mock.cpp -- keep track of function invocations
 *
 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "mock.hpp"

namespace irccd {

void mock::push(std::string name, args args)
{
    table_[name].push_back(std::move(args));
}

auto mock::find(const std::string& name) -> std::vector<args>
{
    if (const auto it = table_.find(name); it != table_.end())
        return it->second;

    return {};
}

void mock::clear(const std::string& name) noexcept
{
    table_.erase(name);
}

void mock::clear() noexcept
{
    table_.clear();
}

auto mock::empty() const noexcept -> bool
{
    return table_.empty();
}

} // !irccd