extern_interface/tests/handler/setup.inc

57 lines
1.6 KiB
PHP
Raw Normal View History

#pragma once
#include "c_testcase.h"
#include "logging/interface.h"
#include "exint/detail.hpp"
#include "exint/protocol.hpp"
class MockTransport: public Transport {
public:
void send_backend() override {}
void receive_backend() override {}
Transport::FrameType get_sent_frame() {
return super::send_que.Pop(std::chrono::seconds(1)).first; //
}
void set_received_frame(ComFrame* frame) {
super::recv_que.Push(std::make_pair(std::shared_ptr<ComFrame>(frame, ComFrame_Del), nullptr));
}
private:
typedef Transport super;
};
static int g_telemetry_request_count = 0;
static DataQueue<std::tuple<uint32_t, size_t, void*>> g_data_queue;
static MockTransport* g_upperhost_mock_transport;
static MockTransport* g_telemetry_mock_transport;
void exint_data_callback(uint32_t type, size_t size, void* data) {
if (type == ET_TYPE_TELEMETRY_REQUEST) {
g_telemetry_request_count++;
memset(data, 0, size);
((TelemetryRequestData*)data)->app_ver_high = 1;
((TelemetryRequestData*)data)->app_ver_low = 2;
} else {
g_data_queue.Push(std::make_tuple(type, size, data));
}
}
SETUP {
g_upperhost_mock_transport = new MockTransport();
g_telemetry_mock_transport = new MockTransport();
exint_setup(std::unique_ptr<Transport>(g_upperhost_mock_transport), std::unique_ptr<Transport>(g_telemetry_mock_transport), exint_data_callback);
g_telemetry_request_count = 0;
log_set_level(LOG_LEVEL_DEBUG);
return 0;
}
TEARDOWN {
exint_finalize();
g_data_queue.Clear();
return 0;
}