summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-03-21 22:33:09 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-03-22 14:54:54 (GMT)
commitf5c2750f56c78d115bb9e8a7c5d50316da98b6d5 (patch)
tree661c761e7ebb526e1d71848c127046605e036729 /Swiften/Presence/UnitTest
parent37a3ff6afe96c39bbf075d05da72e5f2c684dfa4 (diff)
downloadswift-f5c2750f56c78d115bb9e8a7c5d50316da98b6d5.zip
swift-f5c2750f56c78d115bb9e8a7c5d50316da98b6d5.tar.bz2
Lots of plumbing for event view.
This isn't ready yet, but clicking on a message in the event view will now cause the chat to pop up, and the plumbing is there for doing something with subscription requests - I just don't, yet.
Diffstat (limited to 'Swiften/Presence/UnitTest')
-rw-r--r--Swiften/Presence/UnitTest/PresenceOracleTest.cpp58
1 files changed, 43 insertions, 15 deletions
diff --git a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
index e6f56b2..2c9c526 100644
--- a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
+++ b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
@@ -15,11 +15,18 @@ class PresencePointerPair {
boost::shared_ptr<Presence> two;
};
+class SubscriptionRequestInfo {
+ public:
+ boost::optional<JID> jid;
+ boost::optional<String> reason;
+};
+
class PresenceOracleTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(PresenceOracleTest);
CPPUNIT_TEST(testFirstPresence);
CPPUNIT_TEST(testSecondPresence);
+ CPPUNIT_TEST(testSubscriptionRequest);
CPPUNIT_TEST_SUITE_END();
private:
@@ -37,11 +44,11 @@ class PresenceOracleTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(newPresence, out->one);
}
- void handlePresenceSubscriptionRequest(const JID& jid, const String& reason, boost::optional<JID>& outJID, boost::optional<String>& outReason) {
- CPPUNIT_ASSERT(!outJID);
- CPPUNIT_ASSERT(!outReason);
- outJID = jid;
- outReason = reason;
+ void handlePresenceSubscriptionRequest(const JID& jid, const String& reason, SubscriptionRequestInfo* info) {
+ CPPUNIT_ASSERT(!info->jid);
+ CPPUNIT_ASSERT(!info->reason);
+ info->jid = jid;
+ info->reason = reason;
}
void setUp() {
@@ -58,15 +65,14 @@ class PresenceOracleTest : public CppUnit::TestFixture
PresencePointerPair out;
oracle_->onPresenceChange.connect(boost::bind(&PresenceOracleTest::handlePresenceChange, this, _1, _2, &out));
- boost::optional<JID> jid;
- boost::optional<String> reason;
- oracle_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2, jid, reason));
+ SubscriptionRequestInfo info;
+ oracle_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2, &info));
boost::shared_ptr<Presence> sentPresence(new Presence("blarb"));
stanzaChannel_->onPresenceReceived(sentPresence);
- CPPUNIT_ASSERT(!jid);
- CPPUNIT_ASSERT(!reason);
+ CPPUNIT_ASSERT(!info.jid);
+ CPPUNIT_ASSERT(!info.reason);
CPPUNIT_ASSERT(out.two.get() == NULL);
CPPUNIT_ASSERT_EQUAL(sentPresence, out.one);
}
@@ -80,19 +86,41 @@ class PresenceOracleTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(sentPresence1, out.one);
out.one = boost::shared_ptr<Presence>();
- boost::optional<JID> jid;
- boost::optional<String> reason;
- oracle_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2, jid, reason));
+ SubscriptionRequestInfo info;
+ oracle_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2, &info));
boost::shared_ptr<Presence> sentPresence2(new Presence("test2"));
stanzaChannel_->onPresenceReceived(sentPresence2);
- CPPUNIT_ASSERT(!jid);
- CPPUNIT_ASSERT(!reason);
+ CPPUNIT_ASSERT(!info.jid);
+ CPPUNIT_ASSERT(!info.reason);
CPPUNIT_ASSERT_EQUAL(sentPresence1, out.two);
CPPUNIT_ASSERT_EQUAL(sentPresence2, out.one);
}
+ void testSubscriptionRequest() {
+ PresencePointerPair out;
+ oracle_->onPresenceChange.connect(boost::bind(&PresenceOracleTest::handlePresenceChange, this, _1, _2, &out));
+ SubscriptionRequestInfo info;
+ oracle_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2, &info));
+
+ String reasonText = "Because I want to";
+ JID sentJID = JID("me@example.com");
+
+ boost::shared_ptr<Presence> sentPresence(new Presence());
+ sentPresence->setType(Presence::Subscribe);
+ sentPresence->setFrom(sentJID);
+ sentPresence->setStatus(reasonText);
+ stanzaChannel_->onPresenceReceived(sentPresence);
+
+ CPPUNIT_ASSERT(info.jid);
+ CPPUNIT_ASSERT(info.reason);
+ CPPUNIT_ASSERT_EQUAL(sentJID, info.jid.get());
+ CPPUNIT_ASSERT_EQUAL(reasonText, info.reason.get());
+
+ CPPUNIT_ASSERT(!out.two);
+ CPPUNIT_ASSERT(!out.one);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(PresenceOracleTest);