Changeset - 31b80dbe76f2
[Not reviewed]
0 3 0
HanzZ - 13 years ago 2012-08-13 08:29:44
hanzz.k@gmail.com
More tests
3 files changed with 151 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/rostermanager.cpp
Show inline comments
 
@@ -374,6 +374,8 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
					break;
 
				case Swift::Presence::Unsubscribe:
 
					onBuddyRemoved(buddy);
 
					removeBuddy(buddy->getName());
 
					buddy = NULL;
 
					response->setType(Swift::Presence::Unsubscribed);
 
					break;
 
				case Swift::Presence::Subscribed:
 
@@ -405,8 +407,17 @@ void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
				case Swift::Presence::Subscribed:
 
// 					onBuddyAdded(buddy);
 
					return;
 
				// buddy is already there, so nothing to do, just answer
 
				// buddy is not there, so nothing to do, just answer
 
				case Swift::Presence::Unsubscribe:
 
					buddyInfo.id = -1;
 
					buddyInfo.alias = "";
 
					buddyInfo.legacyName = Buddy::JIDToLegacyName(presence->getTo());
 
					buddyInfo.subscription = "both";
 
					buddyInfo.flags = Buddy::buddyFlagsFromJID(presence->getTo());
 

	
 
					buddy = m_component->getFactory()->createBuddy(this, buddyInfo);
 
					onBuddyRemoved(buddy);
 
					delete buddy;
 
					response->setType(Swift::Presence::Unsubscribed);
 
					break;
 
				default:
src/tests/localbuddy.cpp
Show inline comments
 
@@ -26,6 +26,7 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST(buddyFlagsFromJID);
 
	CPPUNIT_TEST(JIDToLegacyName);
 
	CPPUNIT_TEST(handleBuddyChanged);
 
	CPPUNIT_TEST(setAlias);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
@@ -114,6 +115,27 @@ class LocalBuddyTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT_EQUAL(std::string("status1"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getStatus());
 
	}
 

	
 
	void setAlias() {
 
		User *user = userManager->getUser("user@localhost");
 
		CPPUNIT_ASSERT(user);
 

	
 
		std::vector<std::string> grp;
 
		grp.push_back("group1");
 
		LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy1", "Buddy 1", grp, BUDDY_JID_ESCAPING);
 
		buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1");
 
		user->getRosterManager()->setBuddy(buddy);
 
		received.clear();
 

	
 
		buddy->setAlias("Buddy 2");
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
 
		CPPUNIT_ASSERT(payload1);
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Buddy 2"), item.getName());
 
	}
 

	
 
	void disconnectUser() {
 
		userManager->disconnectUser("user@localhost");
 
		dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
src/tests/rostermanager.cpp
Show inline comments
 
@@ -25,13 +25,23 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST(setBuddy);
 
	CPPUNIT_TEST(sendCurrentPresences);
 
	CPPUNIT_TEST(sendCurrentPresence);
 
	CPPUNIT_TEST(removeBuddy);
 
	CPPUNIT_TEST(subscribeExistingBuddy);
 
	CPPUNIT_TEST(subscribeNewBuddy);
 
	CPPUNIT_TEST(unsubscribeExistingBuddy);
 
	CPPUNIT_TEST(unsubscribeNewBuddy);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		std::string m_buddy;
 

	
 
		void setUp (void) {
 
			m_buddy.clear();
 
			setMeUp();
 
			userManager->onUserCreated.connect(boost::bind(&RosterManagerTest::handleUserCreated, this, _1));
 
			connectUser();
 
			User *user = userManager->getUser("user@localhost");
 
			user->getRosterManager()->onBuddyAdded.connect(boost::bind(&RosterManagerTest::handleBuddyAdded, this, _1));
 
			user->getRosterManager()->onBuddyRemoved.connect(boost::bind(&RosterManagerTest::handleBuddyRemoved, this, _1));
 
			received.clear();
 
		}
 

	
 
@@ -41,8 +51,12 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
			tearMeDown();
 
		}
 

	
 
	void handleUserCreated(User *user) {
 
		
 
	void handleBuddyAdded(Buddy *buddy) {
 
		m_buddy = buddy->getName();
 
	}
 

	
 
	void handleBuddyRemoved(Buddy *buddy) {
 
		m_buddy = buddy->getName();
 
	}
 

	
 
	void connectUser() {
 
@@ -153,6 +167,106 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getTo().toString());
 
	}
 

	
 
	void removeBuddy() {
 
		add2Buddies();
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
		received.clear();
 
		User *user = userManager->getUser("user@localhost");
 
		user->getRosterManager()->removeBuddy("buddy1");
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
 
		CPPUNIT_ASSERT(payload1);
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
 
		CPPUNIT_ASSERT_EQUAL(Swift::RosterItemPayload::Remove, item.getSubscription());
 
	}
 

	
 
	void subscribeExistingBuddy() {
 
		add2Buddies();
 
		received.clear();
 

	
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("buddy1@localhost");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Subscribe);
 

	
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribed, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), m_buddy);
 
	}
 

	
 
	void subscribeNewBuddy() {
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("buddy1@localhost");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Subscribe);
 

	
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribed, dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getType());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), m_buddy);
 
	}
 

	
 
	void unsubscribeExistingBuddy() {
 
		add2Buddies();
 
		received.clear();
 

	
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("buddy1@localhost");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Unsubscribe);
 

	
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID()));
 

	
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribed, dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getType());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), m_buddy);
 
	}
 

	
 
	void unsubscribeNewBuddy() {
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("buddy1@localhost");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Unsubscribe);
 

	
 
		injectPresence(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribed, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 

	
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), m_buddy);
 
	}
 

	
 
	void disconnectUser() {
 
		userManager->disconnectUser("user@localhost");
 
		dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
0 comments (0 inline, 0 general)