void getSafeName() { 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@test", "Buddy 1", grp, BUDDY_JID_ESCAPING); CPPUNIT_ASSERT_EQUAL(std::string("buddy1\\40test"), buddy->getSafeName()); buddy->setFlags(BUDDY_NO_FLAG); CPPUNIT_ASSERT_EQUAL(std::string("buddy1%test"), buddy->getSafeName()); }
void BasicTest::add2Buddies() { 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); std::vector<std::string> grp2; grp2.push_back("group2"); buddy = new LocalBuddy(user->getRosterManager(), -1, "buddy2", "Buddy 2", grp2, BUDDY_JID_ESCAPING); buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status2"); user->getRosterManager()->setBuddy(buddy); }
void sendPresenceTypeNone() { 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), ""); user->getRosterManager()->setBuddy(buddy); received.clear(); buddy->setStatus(Swift::StatusShow(Swift::StatusShow::None), ""); CPPUNIT_ASSERT_EQUAL(1, (int) received.size()); CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0]))); CPPUNIT_ASSERT_EQUAL(Swift::StatusShow::None, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getShow()); }
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 createWithInvalidName() { User *user = userManager->getUser("user@localhost"); CPPUNIT_ASSERT(user); std::vector<std::string> grp; grp.push_back("group"); // with BUDDY_JID_ESCAPING it escapes / LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "msn/something", "Buddy 1", grp, BUDDY_JID_ESCAPING); CPPUNIT_ASSERT(buddy->isValid()); CPPUNIT_ASSERT_EQUAL(std::string("msn\\2fsomething@localhost/bot"), buddy->getJID().toString()); delete buddy; // without BUDDY_JID_ESCAPING it shoudl fail buddy = new LocalBuddy(user->getRosterManager(), -1, "msn/something", "Buddy 1", grp); CPPUNIT_ASSERT(!buddy->isValid()); delete buddy; buddy = new LocalBuddy(user->getRosterManager(), -1, "\xd7\x92\xd7\x9c\xd7\x99\xd7\[email protected]", "Buddy 1", grp); CPPUNIT_ASSERT(!buddy->isValid()); delete buddy; }
void add2Buddies() { User *user = userManager->getUser("user@localhost"); CPPUNIT_ASSERT(user); LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1); buddy->setFlags(BUDDY_JID_ESCAPING); buddy->setName("buddy1"); buddy->setAlias("Buddy 1"); std::vector<std::string> grp; grp.push_back("group1"); buddy->setGroups(grp); buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status1"); user->getRosterManager()->setBuddy(buddy); buddy = new LocalBuddy(user->getRosterManager(), -1); buddy->setFlags(BUDDY_JID_ESCAPING); buddy->setName("buddy2"); buddy->setAlias("Buddy 2"); std::vector<std::string> grp2; grp2.push_back("group2"); buddy->setGroups(grp2); buddy->setStatus(Swift::StatusShow(Swift::StatusShow::Away), "status2"); user->getRosterManager()->setBuddy(buddy); }