Commit 3b2b26cc authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Move mocks and test classes to separate file - WIP

parent 745cc156
......@@ -15,6 +15,8 @@ set( ProjectSources "all_tests.cpp"
"enum_to_int.cpp"
"master_simulation_controller_test.cpp"
"simulation_result_test.cpp"
"mocks.hpp"
"test_classes.hpp"
)
add_executable( all_tests ${ProjectSources} )
......
......@@ -21,94 +21,22 @@
#include "gtest/gtest.h"
#include "enum_to_int.cpp"
#include "mocks.hpp"
#include "test_classes.hpp"
using namespace ITA::simulation_scheduler;
using namespace ITA::simulation_scheduler::room_acoustics;
struct MockResultHandler : public IResultHandler
{
MockResultHandler ( )
{
}
void postResultReceived ( std::unique_ptr<CSimulationResult> result ) override
{
resultVector.push_back ( result.release ( ) );
}
std::vector<CSimulationResult*> resultVector = std::vector<CSimulationResult*> ( );
};
struct MockScheduler : public ISchedulerInterface
{
MockScheduler ( )
{
}
void postUpdate ( std::unique_ptr<ITA::simulation_scheduler::IUpdateMessage> pUpdate ) override
{
updates.push_back ( pUpdate.release ( ) );
if ( auto sceneUpdate = dynamic_cast< CUpdateScene* >( updates.back ( ) ) )
{
for ( auto handler : handlers )
{
auto result = std::make_unique<CSimulationResult> ( );
result->sourceReceiverPair = sceneUpdate->getSourceReceiverPair ( );
handler->postResultReceived ( std::move ( result ) );
}
}
}
void attachResultHandler ( IResultHandler* pHandler ) override
{
handlers.push_back ( pHandler );
}
void detachResultHandler ( IResultHandler* ) override
{ }
std::vector<IResultHandler*> handlers;
std::vector<IUpdateMessage*> updates;
};
struct MockMasterSimulationController : public CMasterSimulationController
{
MockMasterSimulationController ( ) : CMasterSimulationController (
CMasterSimulationController::getDefaultMasterSimulationControllerConfig (
CMasterSimulationController::SchedulerType::local,
CMasterSimulationController::SchedulerType::local,
CMasterSimulationController::SchedulerType::local ) )
{
scheduler.push_back ( new MockScheduler );
scheduler.push_back ( new MockScheduler );
scheduler.push_back ( new MockScheduler );
auto ptr1 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 0 ) );
auto ptr2 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 1 ) );
auto ptr3 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 2 ) );
setScheduler ( std::move ( ptr1 ), std::move ( ptr2 ), std::move ( ptr3 ) );
}
std::vector<MockScheduler*> scheduler;
};
struct MasterSimulationControllerTest : testing::Test
{
std::unique_ptr<MockMasterSimulationController> controller;
std::unique_ptr<TestMasterSimulationController> controller;
MockResultHandler* handler;
MasterSimulationControllerTest ( )
{
controller = std::make_unique<MockMasterSimulationController> ( );
controller = std::make_unique<TestMasterSimulationController> ( );
handler = new MockResultHandler ( );
......
#pragma once
#include <ITA/simulation_scheduler/room_acoustics/result_handler.h>
#include <ITA/simulation_scheduler/room_acoustics/scheduler_interface.h>
#include <ITA/simulation_scheduler/room_acoustics/worker_interface.h>
#include <ITA/simulation_scheduler/room_acoustics/master_simulation_controller.h>
using namespace ITA::simulation_scheduler;
using namespace ITA::simulation_scheduler::room_acoustics;
struct MockResultHandler : public IResultHandler
{
MockResultHandler ( )
{
}
void postResultReceived ( std::unique_ptr<CSimulationResult> result ) override
{
resultVector.push_back ( result.release ( ) );
}
std::vector<CSimulationResult*> resultVector = std::vector<CSimulationResult*> ( );
};
struct MockScheduler : public ISchedulerInterface
{
MockScheduler ( )
{
}
void postUpdate ( std::unique_ptr<ITA::simulation_scheduler::IUpdateMessage> pUpdate ) override
{
updates.push_back ( pUpdate.release ( ) );
if ( auto sceneUpdate = dynamic_cast< CUpdateScene* >( updates.back ( ) ) )
{
for ( auto handler : handlers )
{
auto result = std::make_unique<CSimulationResult> ( );
result->sourceReceiverPair = sceneUpdate->getSourceReceiverPair ( );
handler->postResultReceived ( std::move ( result ) );
}
}
}
void attachResultHandler ( IResultHandler* pHandler ) override
{
handlers.push_back ( pHandler );
}
void detachResultHandler ( IResultHandler* ) override
{ }
std::vector<IResultHandler*> handlers;
std::vector<IUpdateMessage*> updates;
};
struct MockWorker : public IWorkerInterface
{
};
\ No newline at end of file
#pragma once
#include <ITA/simulation_scheduler/room_acoustics/scheduler_interface.h>
#include <ITA/simulation_scheduler/room_acoustics/worker_interface.h>
#include <ITA/simulation_scheduler/room_acoustics/master_simulation_controller.h>
#include "mocks.hpp"
using namespace ITA::simulation_scheduler;
using namespace ITA::simulation_scheduler::room_acoustics;
struct TestMasterSimulationController : public CMasterSimulationController
{
TestMasterSimulationController ( ) : CMasterSimulationController (
CMasterSimulationController::getDefaultMasterSimulationControllerConfig (
CMasterSimulationController::SchedulerType::local,
CMasterSimulationController::SchedulerType::local,
CMasterSimulationController::SchedulerType::local ) )
{
scheduler.push_back ( new MockScheduler );
scheduler.push_back ( new MockScheduler );
scheduler.push_back ( new MockScheduler );
auto ptr1 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 0 ) );
auto ptr2 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 1 ) );
auto ptr3 = std::unique_ptr<ISchedulerInterface> ( scheduler.at ( 2 ) );
setScheduler ( std::move ( ptr1 ), std::move ( ptr2 ), std::move ( ptr3 ) );
}
std::vector<MockScheduler*> scheduler;
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment