Skip to content
Snippets Groups Projects
Commit 7d4b71e3 authored by Lucas Givord's avatar Lucas Givord
Browse files

TestSocketComunicator: check breaking connection handling

parent c86e3aaa
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,80 @@
#define MESSAGE(x) cout << (is_server ? "SERVER" : "CLIENT") << ":" x << endl;
//-----------------------------------------------------------------------------
// This unit test make sure that we can Send/Receive a int, vtkDataArray and a vtkDataSet
bool TestSendReceiveDataArray(vtkSocketController* controller, bool& is_server)
{
int idata = 0;
double ddata = 0;
vtkNew<vtkDoubleArray> dArray;
vtkNew<vtkPolyData> pData;
MESSAGE("---- TestSendReceiveDataArray ----")
for (int cc = 0; cc < 2; cc++)
{
MESSAGE("---- Test stage " << cc << "----");
if (is_server)
{
idata = 10;
ddata = 10.0;
dArray->SetNumberOfTuples(10);
dArray->FillComponent(0, 10.0);
pData->Initialize();
controller->Send(&idata, 1, 1, 101011);
controller->Send(&ddata, 1, 1, 101012);
controller->Send(dArray, 1, 101013);
controller->Send(pData, 1, 101014);
}
else
{
controller->Receive(&idata, 1, 1, 101011);
controller->Receive(&ddata, 1, 1, 101012);
controller->Receive(dArray, 1, 101013);
controller->Receive(pData, 1, 101014);
if (idata != 10 || ddata != 10.0 || dArray->GetNumberOfTuples() != 10 ||
dArray->GetValue(9) != 10.0)
{
MESSAGE("ERROR: Communication failed!!!");
return false;
}
}
MESSAGE(" .... PASSED!");
// switch the flags so server becomes client and client becomes server and
// ship messages around.
is_server = !is_server;
}
MESSAGE("All's well!");
return true;
}
//-----------------------------------------------------------------------------
// This unit test make sure that it is correctly checked, especially on Windows as it previously the
// server hangs indefinitely.
bool TestConnectionAbortHandling(vtkSocketController* controller, bool& is_server)
{
MESSAGE("---- TestConnectionAbortHandling ----")
MESSAGE("Check support of connection failure...")
vtkNew<vtkDoubleArray> dArray;
if (is_server)
{
controller->Receive(dArray, 1, 101013);
MESSAGE("Error is expected, continue.")
}
else
{
MESSAGE("Kill the client")
controller->TriggerBreakRMIs();
}
return true;
}
//-----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
vtkNew<vtkTesting> testing;
......@@ -54,45 +128,14 @@ int main(int argc, char* argv[])
}
MESSAGE("Connected.");
int idata = 0;
double ddata = 0;
vtkNew<vtkDoubleArray> dArray;
vtkNew<vtkPolyData> pData;
bool succeed = true;
succeed &= ::TestSendReceiveDataArray(controller, is_server);
succeed &= ::TestConnectionAbortHandling(controller, is_server);
for (int cc = 0; cc < 2; cc++)
if (succeed)
{
MESSAGE("---- Test stage " << cc << "----");
if (is_server)
{
idata = 10;
ddata = 10.0;
dArray->SetNumberOfTuples(10);
dArray->FillComponent(0, 10.0);
pData->Initialize();
controller->Send(&idata, 1, 1, 101011);
controller->Send(&ddata, 1, 1, 101012);
controller->Send(dArray, 1, 101013);
controller->Send(pData, 1, 101014);
}
else
{
controller->Receive(&idata, 1, 1, 101011);
controller->Receive(&ddata, 1, 1, 101012);
controller->Receive(dArray, 1, 101013);
controller->Receive(pData, 1, 101014);
if (idata != 10 || ddata != 10.0 || dArray->GetNumberOfTuples() != 10 ||
dArray->GetValue(9) != 10.0)
{
MESSAGE("ERROR: Communication failed!!!");
return EXIT_FAILURE;
}
}
MESSAGE(" .... PASSED!");
// switch the flags so server becomes client and client becomes server and
// ship messages around.
is_server = !is_server;
return EXIT_SUCCESS;
}
MESSAGE("All's well!");
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
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