Changeset - 25642926dd9d
[Not reviewed]
0 2 0
HanzZ - 14 years ago 2011-10-20 20:52:42
hanzz.k@gmail.com
more tests
2 files changed with 33 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/tests/usermanager.cpp
Show inline comments
 
@@ -55,16 +55,19 @@ class TestingFactory : public Factory {
 
		}
 
};
 

	
 
class UserManagerTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPParserClient {
 
	CPPUNIT_TEST_SUITE(UserManagerTest);
 
	CPPUNIT_TEST(connectUser);
 
	CPPUNIT_TEST(handleProbePresence);
 
	CPPUNIT_TEST(disconnectUser);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		void setUp (void) {
 
			streamEnded = false;
 
			std::istringstream ifs("service.server_mode = 1\n");
 
			cfg = new Config();
 
			cfg->load(ifs);
 

	
 
			factory = new TestingFactory();
 

	
 
@@ -116,13 +119,13 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPPars
 

	
 
	void handleElement(boost::shared_ptr<Swift::Element> element) {
 
		received.push_back(element);
 
	}
 

	
 
	void handleStreamEnd() {
 
		</i>
 
		streamEnded = true;
 
	}
 

	
 
	void connectUser() {
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		loop->processEvents();
 
@@ -135,22 +138,51 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPPars
 
		CPPUNIT_ASSERT_EQUAL(std::string("password"), userInfo.password);
 
		CPPUNIT_ASSERT(user->isReadyToConnect() == true);
 
		CPPUNIT_ASSERT(user->isConnected() == false);
 

	
 
		user->setConnected(true);
 
		CPPUNIT_ASSERT(user->isConnected() == true);
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
 
	}
 

	
 
	void disconnectUser() {
 
		connectUser();
 
		received.clear();
 

	
 
		userManager->disconnectUser("user@localhost");
 
		dynamic_cast<Swift::DummyTimerFactory *>(factories->getTimerFactory())->setTime(10);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
	}
 

	
 
	void handleProbePresence() {
 
		Swift::Presence::ref response = Swift::Presence::create();
 
		response->setTo("localhost");
 
		response->setFrom("user@localhost/resource");
 
		response->setType(Swift::Presence::Probe);
 
		dynamic_cast<Swift::ServerStanzaChannel *>(component->getStanzaChannel())->onPresenceReceived(response);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
		CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::DiscoInfo>());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
	}
 

	
 
	Swift::Stanza *getStanza(boost::shared_ptr<Swift::Element> element) {
 
		Swift::Stanza *stanza = dynamic_cast<Swift::Stanza *>(element.get());
 
		CPPUNIT_ASSERT(stanza);
 
		return stanza;
 
	}
 

	
 
	private:
 
		bool streamEnded;
 
		UserManager *userManager;
 
		boost::shared_ptr<Swift::ServerFromClientSession> serverFromClientSession;
 
		Swift::FullPayloadSerializerCollection* payloadSerializers;
 
		Swift::FullPayloadParserFactoryCollection* payloadParserFactories;
 
		Swift::XMPPParser *parser;
 
		UserRegistry *userRegistry;
src/transport.cpp
Show inline comments
 
@@ -248,13 +248,12 @@ void Component::handlePresence(Swift::Presence::ref presence) {
 
	// filter out bad presences
 
	if (!presence->getFrom().isValid()) {
 
		return;
 
	}
 

	
 
	// check if we have this client's capabilities and ask for them
 
// 	bool haveFeatures = false;
 
	if (presence->getType() != Swift::Presence::Unavailable) {
 
		boost::shared_ptr<CapsInfo> capsInfo = presence->getPayload<CapsInfo>();
 
		if (capsInfo && capsInfo->getHash() == "sha-1") {
 
			/*haveFeatures = */m_entityCapsManager->getCaps(presence->getFrom()) != DiscoInfo::ref();
 
		}
 
#ifdef SUPPORT_LEGACY_CAPS
0 comments (0 inline, 0 general)