Changeset - 8d64493eef2a
[Not reviewed]
0 3 0
Jan Kaluza - 9 years ago 2016-01-23 21:58:48
jkaluza@redhat.com
Fix #86 - Use utf8 aware to_lower function
3 files changed with 32 insertions and 8 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -80,7 +80,7 @@ if (WIN32)
 
	set(Boost_USE_STATIC_LIBS      ON)
 
	set(Boost_USE_MULTITHREADED      ON)
 
	set(Boost_USE_STATIC_RUNTIME    OFF)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals locale REQUIRED)
 
else(WIN32)
 
	LIST_CONTAINS(contains -lboost_program_options ${SWIFTEN_LIBRARY})
 
	if(contains)
 
@@ -88,10 +88,10 @@ else(WIN32)
 
		set(Boost_USE_MULTITHREADED 0)
 
	endif(contains)
 
	set(Boost_FIND_QUIETLY ON)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals locale)
 
	if (NOT Boost_FOUND)
 
		set(Boost_FIND_QUIETLY OFF)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals locale REQUIRED)
 
	endif()
 
endif(WIN32)
 

	
libtransport/RosterManager.cpp
Show inline comments
 
@@ -34,6 +34,7 @@
 
#include <boost/foreach.hpp>
 
#include <boost/make_shared.hpp>
 
#include <boost/algorithm/string.hpp>
 
#include <boost/locale.hpp>
 

	
 
#include <map>
 
#include <iterator>
 
@@ -46,6 +47,9 @@ RosterManager::RosterManager(User *user, Component *component){
 
	m_rosterStorage = NULL;
 
	m_user = user;
 
	m_component = component;
 

	
 
	boost::locale::generator gen;
 
	std::locale::global(gen("en_GB.UTF8"));
 
}
 

	
 
RosterManager::~RosterManager() {
 
@@ -71,7 +75,7 @@ RosterManager::~RosterManager() {
 

	
 
void RosterManager::removeBuddy(const std::string &_name) {
 
	std::string name = _name;
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	Buddy *buddy = getBuddy(name);
 
	if (!buddy) {
 
		LOG4CXX_WARN(logger, m_user->getJID().toString() << ": Tried to remove unknown buddy " << name);
 
@@ -118,7 +122,7 @@ void RosterManager::handleBuddyChanged(Buddy *buddy) {
 

	
 
void RosterManager::setBuddy(Buddy *buddy) {
 
	std::string name = buddy->getName();
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	LOG4CXX_INFO(logger, "Associating buddy " << name << " with " << m_user->getJID().toString());
 
	m_buddies[name] = buddy;
 
	onBuddySet(buddy);
 
@@ -131,7 +135,7 @@ void RosterManager::setBuddy(Buddy *buddy) {
 

	
 
void RosterManager::unsetBuddy(Buddy *buddy) {
 
	std::string name = buddy->getName();
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	m_buddies.erase(name);
 
	if (m_rosterStorage)
 
		m_rosterStorage->removeBuddyFromQueue(buddy);
 
@@ -146,7 +150,7 @@ void RosterManager::storeBuddy(Buddy *buddy) {
 

	
 
Buddy *RosterManager::getBuddy(const std::string &_name) {
 
	std::string name = _name;
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	return m_buddies[name];
 
}
 

	
 
@@ -349,7 +353,7 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
 
		if (buddy) {
 
			LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Adding cached buddy " << buddy->getName() << " fom database");
 
			std::string name = buddy->getName();
 
			boost::algorithm::to_lower(name);
 
			name = boost::locale::to_lower(name);
 
			m_buddies[name] = buddy;
 
			onBuddySet(buddy);
 
		}
tests/libtransport/rostermanager.cpp
Show inline comments
 
@@ -15,6 +15,7 @@ using namespace Transport;
 
class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(RosterManagerTest);
 
	CPPUNIT_TEST(setBuddy);
 
	CPPUNIT_TEST(setBuddyUTF8);
 
	CPPUNIT_TEST(setBuddyNoAlias);
 
	CPPUNIT_TEST(sendCurrentPresences);
 
	CPPUNIT_TEST(sendUnavailablePresences);
 
@@ -85,6 +86,25 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), item.getName());
 
	}
 

	
 
	void setBuddyUTF8() {
 
		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, "Катя антонова", "", grp, BUDDY_JID_ESCAPING);
 
		user->getRosterManager()->setBuddy(buddy);
 

	
 
		CPPUNIT_ASSERT(user->getRosterManager()->getBuddy("катя антонова"));
 

	
 
		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("Катя антонова"), Buddy::JIDToLegacyName(item.getJID(), user));
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), item.getName());
 
	}
 

	
 
	void setBuddy() {
 
		User *user = userManager->getUser("user@localhost");
 
		add2Buddies();
0 comments (0 inline, 0 general)