void testSerialize_ItemWithUnknownContent() { RosterSerializer testling; std::shared_ptr<RosterPayload> roster(new RosterPayload()); RosterItemPayload item; item.setJID(JID("*****@*****.**")); item.setName("Baz"); item.addGroup("Group 1"); item.addGroup("Group 2"); item.addUnknownContent(std::string( "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>")); roster->addItem(item); std::string expectedResult = "<query xmlns=\"jabber:iq:roster\">" "<item jid=\"[email protected]\" name=\"Baz\" subscription=\"none\">" "<group>Group 1</group>" "<group>Group 2</group>" "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" "</item>" "</query>"; CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); }
static int sluift_client_add_contact(lua_State* L) { try { eventLoop.runOnce(); SluiftClient* client = getClient(L); RosterItemPayload item; if (lua_type(L, 2) == LUA_TTABLE) { lua_getfield(L, 2, "jid"); const char* rawJID = lua_tostring(L, -1); if (rawJID) { item.setJID(std::string(rawJID)); } lua_getfield(L, 2, "name"); const char* rawName = lua_tostring(L, -1); if (rawName) { item.setName(rawName); } lua_getfield(L, 2, "groups"); if (!lua_isnil(L, -1)) { if (lua_type(L, -1) == LUA_TTABLE) { for (size_t i = 1; i <= lua_objlen(L, -1); ++i) { lua_rawgeti(L, -1, i); const char* rawGroup = lua_tostring(L, -1); if (rawGroup) { item.addGroup(rawGroup); } lua_pop(L, 1); } } else { return luaL_error(L, "Groups should be a table"); } } } else { item.setJID(luaL_checkstring(L, 2)); } client->getRoster(); if (!client->getClient()->getRoster()->containsJID(item.getJID())) { RosterPayload::ref roster = boost::make_shared<RosterPayload>(); roster->addItem(item); ResponseSink<RosterPayload> sink; SetRosterRequest::ref request = SetRosterRequest::create(roster, client->getClient()->getIQRouter()); boost::signals::scoped_connection c = request->onResponse.connect(boost::ref(sink)); request->send(); while (!sink.hasResponse()) { eventLoop.runUntilEvents(); } if (sink.getResponseError()) { lua_pushboolean(L, false); return 1; } } client->getClient()->getSubscriptionManager()->requestSubscription(item.getJID()); lua_pushboolean(L, true); return 1; } catch (const SluiftException& e) { return luaL_error(L, e.getReason().c_str()); } }