LCOV - code coverage report
Current view: top level - include/testutils/hardio/impl - mock_tcp_protocol.h (source / functions) Hit Total Coverage
Test: hardiocore_coverage Lines: 1 1 100.0 %
Date: 2025-05-26 19:00:29 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /*      File: mock_tcp_protocol.h
       2             :  *       This file is part of the program hardiocore
       3             :  *       Program description : Abstract low level I/O removing direct hardware
       4             :  * implementation Copyright (C) 2018-2020 -  Robin Passama (CNRS / LIRMM)
       5             :  * Clement Rebut (EPITA / LIRMM) Charles Villard (EPITA / LIRMM). All Right
       6             :  * reserved.
       7             :  *
       8             :  *       This software is free software: you can redistribute it and/or modify
       9             :  *       it under the terms of the CeCILL-C license as published by
      10             :  *       the CEA CNRS INRIA, either version 1
      11             :  *       of the License, or (at your option) any later version.
      12             :  *       This software is distributed in the hope that it will be useful,
      13             :  *       but WITHOUT ANY WARRANTY without even the implied warranty of
      14             :  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      15             :  *       CeCILL-C License for more details.
      16             :  *
      17             :  *       You should have received a copy of the CeCILL-C License
      18             :  *       along with this software. If not, it can be found on the official
      19             :  * website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
      20             :  */
      21             : /**
      22             :  * @file impl/mock_tcp_protocol.h
      23             :  * @author Robin Passama
      24             :  * @brief header file for MockTCPClient class.
      25             :  * @date May 2025
      26             :  * @ingroup  testutils
      27             :  */
      28             : #pragma once
      29             : 
      30             : #include <hardio/core.h>
      31             : #include <hardio/test/mock_message_interface.h>
      32             : #include <map>
      33             : #include <tuple>
      34             : #include <cstdint>
      35             : #include <memory>
      36             : 
      37             : namespace hardio {
      38             : 
      39             : namespace test {
      40             : 
      41             : class MockTCPClient : public TCPClient {
      42             : public:
      43             :     MockTCPClient();
      44             : 
      45          24 :     virtual ~MockTCPClient() = default;
      46             : 
      47             :     std::vector<EndpointSpec> connected_servers() const final;
      48             : 
      49             :     bool connect(std::string_view ip, ssize_t port) final;
      50             :     bool connected(std::string_view ip, ssize_t port) final;
      51             : 
      52             :     bool disconnect(std::string_view ip, ssize_t port) final;
      53             : 
      54             :     bool write_to(std::string_view ip, ssize_t port, size_t length,
      55             :                   const uint8_t* data) final;
      56             : 
      57             :     bool read_from(std::string_view ip, ssize_t port, size_t length,
      58             :                    uint8_t* data, size_t& data_read) final;
      59             : 
      60             :     bool read_from_if(std::string_view ip, ssize_t port, size_t length,
      61             :                       uint8_t* data, size_t& data_read) final;
      62             : 
      63             :     std::shared_ptr<MockMessageInterface> remote(const std::string& ip,
      64             :                                                  ssize_t port) const;
      65             : 
      66             : private:
      67             :     std::map<uint64_t, std::tuple<std::string, ssize_t,
      68             :                                   std::shared_ptr<MockMessageInterface>,
      69             :                                   std::shared_ptr<MockMessageInterface>>>
      70             :         connected_servers_;
      71             : };
      72             : } // namespace test
      73             : } // namespace hardio

Generated by: LCOV version 1.16