EXPECT_TRUE(connect(fd,reinterpret_cast<sockaddr*>(&server_addr),sizeof(server_addr))>=0)<<"Service should be running";//NOSONAR bit_cast is not supported by the bullseye clang++ compiler
ASSERT_EQ(6,write(fd,"RASCSI",6));
SerializeMessage(fd,command);
DeserializeMessage(fd,result);
close(fd);
}
TEST(PiscsiServiceTest,Init)
{
PiscsiServiceservice;
EXPECT_FALSE(service.Init(nullptr,65536).empty())<<"Illegal port number";
EXPECT_FALSE(service.Init(nullptr,0).empty())<<"Illegal port number";
EXPECT_FALSE(service.Init(nullptr,-1).empty())<<"Illegal port number";
EXPECT_FALSE(service.Init(nullptr,1).empty())<<"Port 1 is only available for the root user";
EXPECT_TRUE(service.Init(nullptr,9999).empty())<<"Port 9999 is expected not to be in use for this test";
service.Stop();
}
TEST(PiscsiServiceTest,IsRunning)
{
PiscsiServiceservice;
EXPECT_FALSE(service.IsRunning());
EXPECT_TRUE(service.Init(nullptr,9999).empty())<<"Port 9999 is expected not to be in use for this test";
EXPECT_FALSE(connect(fd,reinterpret_cast<sockaddr*>(&server_addr),sizeof(server_addr))>=0)<<"Service should not be running";//NOSONAR bit_cast is not supported by the bullseye clang++ compiler