Commit 361e087c authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

Testing

- added test for outdoor worker thread
- added corresponding mock and test classes
parent ac33f511
......@@ -24,6 +24,7 @@ set( ProjectSources "all_tests.cpp"
"utils_test.cpp"
"filter_test.cpp"
"filter_network_test.cpp"
"outdoor_worker_thread_test.cpp"
)
if( ITA_SIMULATION_SCHEDULER_RAVEN_MODULE )
......
......@@ -6,15 +6,21 @@
#include <ITA/SimulationScheduler/RoomAcoustics/master_simulation_controller.h>
#include <ITA/SimulationScheduler/AudibilityFilter/audibility_filter_interface.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulation_result.h>
#ifdef WITH_RAVEN
#include <ITA/SimulationScheduler/RoomAcoustics/raven/simulator.h>
#include "ITA/SimulationScheduler/RoomAcoustics/Raven/worker_thread.h"
#endif
#include <ITAException.h>
// Vista
#include <VistaBase/VistaTimeUtils.h>
#include "ITAException.h"
// STD
#include <memory>
using namespace ITA::SimulationScheduler;
using namespace ITA::SimulationScheduler::RoomAcoustics;
......@@ -209,6 +215,51 @@ struct MockAudibilityFilter : public AudibilityFilter::IAudibilityFilter
Behaviour eBehaviour = Behaviour::nothingAudible;
};
//----------SIMULATORS----------
//------------------------------
struct MockOutdoorAcousticSimulator : public OutdoorAcoustics::ISimulatorInterface
{
bool bReset = false;
bool bUpdateReceived = false;
ITAAtomicBool bFinishSimulation = false;
//inline static std::string GetType() { return "MockOutdoorAcousticSimulator"; };
//inline static std::unique_ptr<ISimulatorInterface> Create(const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& pConfig)
//{
// return std::make_unique< MockOutdoorAcousticSimulator >( );
//}
inline void Reset() override
{
bReset = true;
};
inline std::unique_ptr<OutdoorAcoustics::COutdoorSimulationResult> Compute(std::unique_ptr<CUpdateScene> pSceneUpdate) override
{
bUpdateReceived = true;
while (!bFinishSimulation)
{
VistaTimeUtils::Sleep(100);
}
auto oPathProperty = OutdoorAcoustics::COutdoorSimulationResult::CPathProperty();
oPathProperty.dPropagationDelay = 42;
oPathProperty.dSpreadingLoss = 1.0 / 42.0;
oPathProperty.iDiffractionOrder = 42;
oPathProperty.iReflectionOrder = 42;
oPathProperty.v3SourceWaveFrontNormal = VistaVector3D(1, 1, 1);
oPathProperty.v3ReceiverWaveFrontNormal = VistaVector3D(1, 1, 1);
auto pResult = std::make_unique< OutdoorAcoustics::COutdoorSimulationResult >();
pResult->voPathProperties.push_back(oPathProperty);
return std::move(pResult);
};
};
#ifdef WITH_RAVEN
struct MockRavenSimulator : public Raven::ISimulatorInterface
......@@ -219,12 +270,12 @@ struct MockRavenSimulator : public Raven::ISimulatorInterface
ITAAtomicBool finishSimulation = false;
void Reset ( ) override
inline void Reset() override
{
bReset = true;
}
};
void Compute ( Raven::CSimulationTask* pTask, Raven::CRavenSimulationResult* pResult ) override
inline void Compute ( Raven::CSimulationTask* pTask, Raven::CRavenSimulationResult* pResult ) override
{
bTaskReceived = true;
......@@ -251,7 +302,7 @@ struct MockRavenSimulator : public Raven::ISimulatorInterface
{
pResult->vcspResult [0]->psfResult->operator[]( 0 ) [i] = sin ( 3.14 * i / 128 );
}
}
};
};
#endif
\ No newline at end of file
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_worker_thread.h>
//#include <ITA/SimulationScheduler/worker_interface.h>
#include "mocks.hpp"
#include "test_classes.hpp"
// GTest
#include "gtest/gtest.h"
using namespace ITA::SimulationScheduler;
using namespace OutdoorAcoustics;
struct OutdoorWorkerThreadTest : testing::Test
{
std::unique_ptr<TestOutdoorWorkerThread> pWorker;
std::unique_ptr<MockScheduler> pScheduler;
OutdoorWorkerThreadTest ( )
{
// overwrite the correct create function.
CWorkerFactory::RegisterWorker (OutdoorAcoustics::CWorkerThread::GetType(), TestOutdoorWorkerThread::CreateWorker, std::make_shared<TestOutdoorWorkerThread::WorkerThreadConfig> );
pScheduler = std::make_unique<MockScheduler> ( );
auto oConfig = std::make_shared<OutdoorAcoustics::CWorkerThread::WorkerThreadConfig> ( );
pWorker = std::unique_ptr<TestOutdoorWorkerThread> ( dynamic_cast< TestOutdoorWorkerThread* >( CWorkerFactory::CreateWorker ( oConfig, pScheduler.get ( ) ).release ( ) ) );
}
~OutdoorWorkerThreadTest()
{
// Reset the create function
CWorkerFactory::RegisterWorker (OutdoorAcoustics::CWorkerThread::GetType(), OutdoorAcoustics::CWorkerThread::CreateWorker, std::make_shared<OutdoorAcoustics::CWorkerThread::WorkerThreadConfig> );
}
};
TEST_F ( OutdoorWorkerThreadTest, updateToSimulatorAndResultToScheduler )
{
auto update = std::make_unique<CUpdateScene> ( 1 );
auto source = std::make_unique<C3DObject> (
VistaVector3D ( 3, 2, 6 ), VistaQuaternion ( 1, 0, 0, 0 ), C3DObject::Type::source, 1 );
auto receiver = std::make_unique<C3DObject> (
VistaVector3D ( 6, 1, 10 ), VistaQuaternion ( 1, 0, 0, 0 ), C3DObject::Type::receiver, 1 );
update->SetSourceReceiverPair ( std::move ( source ),
std::move ( receiver ) );
pWorker->PushUpdate ( std::move ( update ) );
// wait for the thread
VistaTimeUtils::Sleep ( 100 );
EXPECT_TRUE ( pWorker->pSimulator->bUpdateReceived );
EXPECT_TRUE ( pWorker->IsBusy ( ) );
pWorker->pSimulator->bFinishSimulation = true;
// wait for the thread
VistaTimeUtils::Sleep ( 500 );
EXPECT_EQ ( 1, pScheduler->results.size ( ) );
}
TEST_F ( OutdoorWorkerThreadTest, reset )
{
pWorker->Reset ( );
EXPECT_TRUE ( pWorker->pSimulator->bReset );
}
\ No newline at end of file
......@@ -5,6 +5,8 @@
#include <ITA/SimulationScheduler/scheduler.h>
#include <ITA/SimulationScheduler/RoomAcoustics/master_simulation_controller.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_worker_thread.h>
#ifdef WITH_RAVEN
#include <ITA/SimulationScheduler/RoomAcoustics/raven/worker_thread.h>
#endif
......@@ -12,12 +14,12 @@
#include "mocks.hpp"
using namespace ITA::SimulationScheduler;
using namespace ITA::SimulationScheduler::RoomAcoustics;
//using namespace ITA::SimulationScheduler::RoomAcoustics;
#ifdef WITH_RAVEN
using namespace ITA::SimulationScheduler::RoomAcoustics::Raven;
#endif
struct TestMasterSimulationController : public CMasterSimulationController
struct TestMasterSimulationController : public RoomAcoustics::CMasterSimulationController
{
TestMasterSimulationController ( ) : CMasterSimulationController (
CMasterSimulationController::MasterSimulationControllerConfig ( ) )
......@@ -55,6 +57,32 @@ struct TestLocalScheduler : public CScheduler
}
};
//----OUTDOOR ACOUSTICS----
//-------------------------
struct TestOutdoorWorkerThread : public OutdoorAcoustics::CWorkerThread
{
MockOutdoorAcousticSimulator* pSimulator;
TestOutdoorWorkerThread(const WorkerThreadConfig& oConfig, ISchedulerInterface* pParent) : CWorkerThread(oConfig, pParent)
{
auto pSimulatorTmp = std::make_unique<MockOutdoorAcousticSimulator>();
pSimulator = pSimulatorTmp.get();
SetSimulator( std::move(pSimulatorTmp) );
}
static std::unique_ptr<IWorkerInterface> CreateWorker(const std::shared_ptr<IWorkerInterface::WorkerConfig>& pConfig, ISchedulerInterface* pParent)
{
return std::make_unique<TestOutdoorWorkerThread>(dynamic_cast<const WorkerThreadConfig&>(*pConfig), pParent);
}
};
//--------RAVEN--------
//---------------------
#ifdef WITH_RAVEN
struct TestRavenWorkerInterface : public IRavenWorkerInterface
......@@ -98,7 +126,7 @@ struct TestRavenWorkerInterface : public IRavenWorkerInterface
std::vector<CUpdateScene*> vUpdates;
};
struct TestRavenWorkerThread : public CWorkerThread
struct TestRavenWorkerThread : public Raven::CWorkerThread
{
MockRavenSimulator* simulator;
......
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