The following testcode creates a server- and a clientsocket. Then client sends a message to server and server replies. Thats all. But I can’t compile. All ASSERT_EQ in the threadfunctions raise the error "error: void value not ignored as it ought to be". I have no clue what this should tell me. What is the problem in here? Type is irrelevant as ASSERT_EQ(1, 1); raises the errors too.
EDIT Found this in FAQ from google:
Q:My compiler complains “void value not ignored as it ought to be.” What does this mean?
A: You’re probably using an ASSERT_XY() in a function that doesn’t return void. ASSERT_XY() can only be used in void functions.
How shall I understand this?
void * serverfunc(void * ptr);
void * clientfunc(void * ptr);
TEST(netTest, insert)
{
pthread_t mThreadID1, mThreadID2;
::pthread_create(&mThreadID1, nullptr, serverfunc, nullptr);
::sleep(1);
::pthread_create(&mThreadID1, nullptr, clientfunc, nullptr);
::pthread_join(mThreadID1, nullptr);
::pthread_join(mThreadID2, nullptr);
}
void * serverfunc(void * ptr)
{
net::ServerSocket serv(IPV4, TCP, 55555,5);
net::ServerSocket * conn = serv.accept();
net::Message msg;
conn->recvmsg(&msg);
ASSERT_EQ(msg.size(),5);
ASSERT_EQ(msg[0],1);
ASSERT_EQ(msg[1],2);
ASSERT_EQ(msg[2],3);
ASSERT_EQ(msg[3],4);
ASSERT_EQ(msg[4],5);
msg = {9,8,6};
ASSERT_EQ(msg.size(),3);
ASSERT_EQ(msg[0],9);
ASSERT_EQ(msg[1],8);
ASSERT_EQ(msg[2],6);
conn->sendmsg(msg);
::sleep(1);
delete conn;
return 0;
}
void * clientfunc(void * ptr)
{
net::ClientSocket clie(IPV4, TCP, "localhost",55555);
net::Message msg;
msg = {1,2,3,4,5};
ASSERT_EQ(msg.size(),5);
ASSERT_EQ(msg[0],1);
ASSERT_EQ(msg[1],2);
ASSERT_EQ(msg[2],3);
ASSERT_EQ(msg[3],4);
ASSERT_EQ(msg[4],5);
clie.sendmsg(msg);
clie.recvmsg(&msg);
ASSERT_EQ(msg.size(),3);
ASSERT_EQ(msg[0],9);
ASSERT_EQ(msg[1],8);
ASSERT_EQ(msg[2],6);
return 0;
}
Your functions don’t return
void, they returnvoid*– i.e. they return something (void*is a pointer-to-anything) while they should return nothing. The FAQ says it is required for the functions which use ASSERT_EQ() to have thevoidreturn type.