Add test for channel validation

This commit is contained in:
Alexey Rybalchenko 2018-11-01 14:07:44 +01:00 committed by Dennis Klein
parent 0b199e779a
commit bd899a2806
3 changed files with 110 additions and 5 deletions

View File

@ -399,8 +399,7 @@ try {
} }
// validate socket type // validate socket type
const string socketTypeNames[] = { "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" }; const set<string> socketTypes{ "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" };
const set<string> socketTypes(socketTypeNames, socketTypeNames + sizeof(socketTypeNames) / sizeof(string));
if (socketTypes.find(fType) == socketTypes.end()) if (socketTypes.find(fType) == socketTypes.end())
{ {
ss << "INVALID"; ss << "INVALID";
@ -431,8 +430,7 @@ try {
else else
{ {
// we don't have a method modifier, check if the default method is set // we don't have a method modifier, check if the default method is set
const string socketMethodNames[] = { "bind", "connect" }; const set<string> socketMethods{ "bind", "connect" };
const set<string> socketMethods(socketMethodNames, socketMethodNames + sizeof(socketMethodNames) / sizeof(string));
if (socketMethods.find(fMethod) == socketMethods.end()) if (socketMethods.find(fMethod) == socketMethods.end())
{ {
ss << "INVALID"; ss << "INVALID";
@ -482,7 +480,7 @@ try {
else if (address.compare(0, 8, "verbs://") == 0) else if (address.compare(0, 8, "verbs://") == 0)
{ {
// check if IPC address is not empty // check if IPC address is not empty
string addressString = address.substr(9); string addressString = address.substr(8);
if (addressString == "") if (addressString == "")
{ {
ss << "INVALID"; ss << "INVALID";

View File

@ -209,6 +209,17 @@ add_testsuite(FairMQ.Tools
TIMEOUT 10 TIMEOUT 10
) )
add_testsuite(FairMQ.Channel
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
channel/_channel.cxx
LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 10
)
add_testsuite(FairMQ.Transport add_testsuite(FairMQ.Transport
SOURCES SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx ${CMAKE_CURRENT_BINARY_DIR}/runner.cxx

96
test/channel/_channel.cxx Normal file
View File

@ -0,0 +1,96 @@
/********************************************************************************
* Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <FairMQChannel.h>
#include <gtest/gtest.h>
#include <string>
namespace
{
using namespace std;
using namespace fair::mq;
TEST(Channel, Validation)
{
FairMQChannel channel;
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateType("pair");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("bla");
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateMethod("connect");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("ipc://");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("verbs://");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("inproc://");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("tcp://");
ASSERT_EQ(channel.ValidateChannel(), false);
ASSERT_EQ(channel.IsValid(), false);
channel.UpdateAddress("tcp://localhost:5555");
ASSERT_EQ(channel.ValidateChannel(), true);
ASSERT_EQ(channel.IsValid(), true);
channel.UpdateSndBufSize(-1);
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateSndBufSize(1000);
ASSERT_NO_THROW(channel.ValidateChannel());
channel.UpdateRcvBufSize(-1);
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRcvBufSize(1000);
ASSERT_NO_THROW(channel.ValidateChannel());
channel.UpdateSndKernelSize(-1);
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateSndKernelSize(1000);
ASSERT_NO_THROW(channel.ValidateChannel());
channel.UpdateRcvKernelSize(-1);
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRcvKernelSize(1000);
ASSERT_NO_THROW(channel.ValidateChannel());
channel.UpdateRateLogging(-1);
ASSERT_THROW(channel.ValidateChannel(), FairMQChannel::ChannelConfigurationError);
channel.UpdateRateLogging(1);
ASSERT_NO_THROW(channel.ValidateChannel());
FairMQChannel channel2 = channel;
ASSERT_NO_THROW(channel2.ValidateChannel());
ASSERT_EQ(channel2.ValidateChannel(), true);
ASSERT_EQ(channel2.IsValid(), true);
ASSERT_EQ(channel2.ValidateChannel(), true);
channel2.UpdateChannelName("Kanal");
ASSERT_EQ(channel2.GetChannelName(), "Kanal");
channel2.ResetChannel();
ASSERT_EQ(channel2.IsValid(), false);
ASSERT_EQ(channel2.ValidateChannel(), true);
}
} /* namespace */