Test for chatstates

This commit is contained in:
HanzZ 2012-09-16 15:13:11 +02:00
parent 9f1a88bec8
commit c1e478774f

View file

@ -25,6 +25,7 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
CPPUNIT_TEST_SUITE(ConversationManagerTest);
CPPUNIT_TEST(handleNormalMessages);
CPPUNIT_TEST(handleGroupchatMessages);
CPPUNIT_TEST(handleChatstateMessages);
CPPUNIT_TEST(handleParticipantChanged);
CPPUNIT_TEST(handlePMFromXMPP);
CPPUNIT_TEST_SUITE_END();
@ -55,6 +56,38 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
m_msg = _msg;
}
void handleChatstateMessages() {
User *user = userManager->getUser("user@localhost");
TestingConversation *conv = new TestingConversation(user->getConversationManager(), "buddy1");
user->getConversationManager()->addConversation(conv);
conv->onMessageToSend.connect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
boost::shared_ptr<Swift::Message> msg(new Swift::Message());
msg->addPayload(boost::make_shared<Swift::ChatState>(Swift::ChatState::Composing));
// Forward it
conv->handleMessage(msg);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0]))->getPayload<Swift::ChatState>());
received.clear();
// send response
msg->setFrom("user@localhost/resource");
msg->setTo("buddy1@localhost/bot");
injectMessage(msg);
loop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
CPPUNIT_ASSERT(m_msg);
CPPUNIT_ASSERT(m_msg->getPayload<Swift::ChatState>());
received.clear();
}
void handleNormalMessages() {
User *user = userManager->getUser("user@localhost");