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
 
@@ -49,28 +49,31 @@ class TestingFactory : public Factory {
 
			buddy->setSubscription(buddyInfo.subscription);
 
			buddy->setGroups(buddyInfo.groups);
 
			buddy->setFlags((BuddyFlag) buddyInfo.flags);
 
			if (buddyInfo.settings.find("icon_hash") != buddyInfo.settings.end())
 
				buddy->setIconHash(buddyInfo.settings.find("icon_hash")->second.s);
 
			return buddy;
 
		}
 
};
 

	
 
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();
 

	
 
			loop = new Swift::DummyEventLoop();
 
			factories = new Swift::DummyNetworkFactories(loop);
 

	
 
			userRegistry = new UserRegistry(cfg, factories);
 

	
 
			component = new Component(loop, factories, cfg, factory, userRegistry);
 
@@ -110,53 +113,82 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public Swift::XMPPPars
 
		parser->parse(safeByteArrayToString(data));
 
	}
 

	
 
	void handleStreamStart(const Swift::ProtocolHeader&) {
 
		
 
	}
 

	
 
	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();
 
		CPPUNIT_ASSERT_EQUAL(1, userManager->getUserCount());
 

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

	
 
		UserInfo userInfo = user->getUserInfo();
 
		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;
 
		Config *cfg;
 
		Swift::Server *server;
 
		Swift::DummyNetworkFactories *factories;
 
		Swift::DummyEventLoop *loop;
 
		TestingFactory *factory;
 
		Component *component;
src/transport.cpp
Show inline comments
 
@@ -242,25 +242,24 @@ void Component::handleDataWritten(const Swift::SafeByteArray &data) {
 
void Component::handlePresence(Swift::Presence::ref presence) {
 
	bool isMUC = presence->getPayload<MUCPayload>() != NULL || *presence->getTo().getNode().c_str() == '#';
 
	// filter out login/logout presence spam
 
	if (!presence->getTo().getNode().empty() && isMUC == false)
 
		return;
 

	
 
	// 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
 
		else {
 
			GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(presence->getFrom(), m_iqRouter);
 
			discoInfoRequest->onResponse.connect(boost::bind(&Component::handleDiscoInfoResponse, this, _1, _2, presence->getFrom()));
 
			discoInfoRequest->send();
 
		}
 
#endif
0 comments (0 inline, 0 general)