Skip to content

Commit

Permalink
Add test for FairMQMessage::Rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Nov 28, 2018
1 parent 0d2fc7e commit a9df367
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fairmq/nanomsg/FairMQSocketNN.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, const string& name, const str
}
#endif

// LOG(info) << "created socket " << fId;
LOG(debug) << "Created socket " << GetId();
}

string FairMQSocketNN::GetId()
Expand Down
2 changes: 1 addition & 1 deletion fairmq/shmem/FairMQSocketSHM.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ FairMQSocketSHM::FairMQSocketSHM(Manager& manager, const string& type, const str
throw fair::mq::SocketError("PUB/SUB socket type is not supported for shared memory transport");
}

// LOG(info) << "created socket " << fId;
LOG(debug) << "Created socket " << GetId();
}

bool FairMQSocketSHM::Bind(const string& address)
Expand Down
2 changes: 1 addition & 1 deletion fairmq/zeromq/FairMQSocketZMQ.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, const s
}
}

// LOG(info) << "created socket " << fId;
LOG(debug) << "Created socket " << GetId();
}

string FairMQSocketZMQ::GetId()
Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ add_testsuite(FairMQ.Parts
TIMEOUT 5
)

add_testsuite(FairMQ.MessageResize
add_testsuite(FairMQ.Message
SOURCES
${CMAKE_CURRENT_BINARY_DIR}/runner.cxx
message_resize/_message_resize.cxx
message/_message.cxx

LINKS FairMQ
INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/message_resize
${CMAKE_CURRENT_SOURCE_DIR}/message
${CMAKE_CURRENT_BINARY_DIR}
TIMEOUT 5
${definitions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace

using namespace std;

auto RunPushPullWithMsgResize(string transport, string address) -> void {

void RunPushPullWithMsgResize(const string& transport, const string& address)
{
size_t session{fair::mq::tools::UuidHash()};

FairMQProgOptions config;
Expand Down Expand Up @@ -53,6 +53,29 @@ auto RunPushPullWithMsgResize(string transport, string address) -> void {
ASSERT_EQ(inMsg->GetSize(), 250);
}

void RunMsgRebuild(const string& transport)
{
size_t session{fair::mq::tools::UuidHash()};

FairMQProgOptions config;
config.SetValue<string>("session", to_string(session));

auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);

FairMQMessagePtr msg(factory->CreateMessage());
EXPECT_EQ(msg->GetSize(), 0);
msg->Rebuild(100);
EXPECT_EQ(msg->GetSize(), 100);
string* str = new string("asdf");
msg->Rebuild(const_cast<char*>(str->c_str()),
str->length(),
[](void* /*data*/, void* obj) { delete static_cast<string*>(obj); },
str);
EXPECT_NE(msg->GetSize(), 100);
EXPECT_EQ(msg->GetSize(), string("asdf").length());
EXPECT_EQ(string(static_cast<char*>(msg->GetData()), msg->GetSize()), string("asdf"));
}

TEST(MessageResize, ZeroMQ)
{
RunPushPullWithMsgResize("zeromq", "ipc://test_message_resize");
Expand All @@ -70,4 +93,21 @@ TEST(MessageResize, nanomsg)
}
#endif /* BUILD_NANOMSG_TRANSPORT */

TEST(MessageRebuild, ZeroMQ)
{
RunMsgRebuild("zeromq");
}

TEST(MessageRebuild, shmem)
{
RunMsgRebuild("shmem");
}

#ifdef BUILD_NANOMSG_TRANSPORT
TEST(MessageRebuild, nanomsg)
{
RunMsgRebuild("nanomsg");
}
#endif /* BUILD_NANOMSG_TRANSPORT */

} // namespace

0 comments on commit a9df367

Please sign in to comment.