Skip to content
Snippets Groups Projects
Commit 01e9e848 authored by Leon Dietrich's avatar Leon Dietrich
Browse files

add: Loopback connection client for testing purposes

`get_send_data()` doesn't work yet as I haven't found a C++ style way to safely cast const std::string& to std::string in line 24 of loopback_connection.cpp
parent 939cdafd
No related branches found
No related tags found
No related merge requests found
/*
* loopback_connection_client.cpp
*
* Created on: 05.01.2021
* Author: doralitze
*/
#include "test/loopback_connection_client.hpp"
#include <string.h>
namespace rmrf::test {
loopback_connection_client::loopback_connection_client(rmrf::net::connection_client::incomming_data_cb mut_send_data_cb_) :
rmrf::net::connection_client{}, mut_send_data_cb(mut_send_data_cb_), send_data_archive{} {
// Does nothing special
}
loopback_connection_client::~loopback_connection_client() {
// Also doesn't do anything fancy.
}
void loopback_connection_client::write_data(const std::string& data) {
// TODO fixme
//this->send_data_archive.push_back(data_ptr);
if(this->mut_send_data_cb != nullptr) {
this->mut_send_data_cb(data);
}
}
void loopback_connection_client::send_data_to_incomming_data_cb(const std::string& data) {
if(this->in_data_cb != nullptr) {
this->in_data_cb(data);
}
}
std::vector<std::string> loopback_connection_client::get_send_data() {
return this->send_data_archive;
}
}
/*
* loopback_connection_client.hpp
*
* Created on: 05.01.2021
* Author: doralitze
*/
#pragma once
#include <vector>
#include "net/connection_client.hpp"
namespace rmrf::test {
/**
* Use this cass to mock a connection client.
*/
class loopback_connection_client : public rmrf::net::connection_client {
private:
const rmrf::net::connection_client::incomming_data_cb mut_send_data_cb;
const std::vector<std::string> send_data_archive;
public:
/**
* This constructor uses the given callback to notify the test suite that the module under test
* send data.
*/
loopback_connection_client(rmrf::net::connection_client::incomming_data_cb mut_send_data_cb_);
/**
* Just the mandatory virtual destructor.
*/
virtual ~loopback_connection_client();
/**
* This method gets called by the module under test as it simulates the behavior of a normal connection client.
* @param data The data the module wants to send.
*/
virtual void write_data(const std::string& data);
/**
* This method sends data to the connections incoming data callback.
* Use it to mimic a remote client sending data.
*
* @param data The data to send.
*/
void send_data_to_incomming_data_cb(const std::string& data);
/**
* Use this method in order to get all data the module under test has send.
*/
std::vector<std::string> get_send_data();
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment