summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
committerTobias Markmann <tm@ayena.de>2016-03-31 14:57:35 (GMT)
commitcfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch)
tree18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Elements/UnitTest
parent1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff)
downloadswift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip
swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines in the process. Changed CheckTabs.py tool to disallow hard tabs in source files. Test-Information: Manually checked 30 random files that the conversion worked as expected. Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Elements/UnitTest')
-rw-r--r--Swiften/Elements/UnitTest/FormTest.cpp54
-rw-r--r--Swiften/Elements/UnitTest/IQTest.cpp74
-rw-r--r--Swiften/Elements/UnitTest/StanzaTest.cpp416
3 files changed, 272 insertions, 272 deletions
diff --git a/Swiften/Elements/UnitTest/FormTest.cpp b/Swiften/Elements/UnitTest/FormTest.cpp
index ea680f9..9255fa8 100644
--- a/Swiften/Elements/UnitTest/FormTest.cpp
+++ b/Swiften/Elements/UnitTest/FormTest.cpp
@@ -15,44 +15,44 @@
using namespace Swift;
class FormTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(FormTest);
- CPPUNIT_TEST(testGetFormType);
- CPPUNIT_TEST(testGetFormType_InvalidFormType);
- CPPUNIT_TEST(testGetFormType_NoFormType);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(FormTest);
+ CPPUNIT_TEST(testGetFormType);
+ CPPUNIT_TEST(testGetFormType_InvalidFormType);
+ CPPUNIT_TEST(testGetFormType_NoFormType);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void testGetFormType() {
- Form form;
+ public:
+ void testGetFormType() {
+ Form form;
- form.addField(boost::make_shared<FormField>(FormField::FixedType, "Foo"));
+ form.addField(boost::make_shared<FormField>(FormField::FixedType, "Foo"));
- FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:bot");
- field->setName("FORM_TYPE");
- form.addField(field);
+ FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:bot");
+ field->setName("FORM_TYPE");
+ form.addField(field);
- form.addField(boost::make_shared<FormField>(FormField::FixedType, "Bar"));
+ form.addField(boost::make_shared<FormField>(FormField::FixedType, "Bar"));
- CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), form.getFormType());
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), form.getFormType());
+ }
- void testGetFormType_InvalidFormType() {
- Form form;
+ void testGetFormType_InvalidFormType() {
+ Form form;
- FormField::ref field = boost::make_shared<FormField>(FormField::FixedType, "jabber:bot");
- field->setName("FORM_TYPE");
- form.addField(field);
+ FormField::ref field = boost::make_shared<FormField>(FormField::FixedType, "jabber:bot");
+ field->setName("FORM_TYPE");
+ form.addField(field);
- CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
- }
+ CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
+ }
- void testGetFormType_NoFormType() {
- Form form;
+ void testGetFormType_NoFormType() {
+ Form form;
- form.addField(boost::make_shared<FormField>(FormField::FixedType, "Foo"));
+ form.addField(boost::make_shared<FormField>(FormField::FixedType, "Foo"));
- CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
- }
+ CPPUNIT_ASSERT_EQUAL(std::string(""), form.getFormType());
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(FormTest);
diff --git a/Swiften/Elements/UnitTest/IQTest.cpp b/Swiften/Elements/UnitTest/IQTest.cpp
index 7cc78c6..a88e2d6 100644
--- a/Swiften/Elements/UnitTest/IQTest.cpp
+++ b/Swiften/Elements/UnitTest/IQTest.cpp
@@ -16,43 +16,43 @@ using namespace Swift;
class IQTest : public CppUnit::TestFixture
{
- CPPUNIT_TEST_SUITE(IQTest);
- CPPUNIT_TEST(testCreateResult);
- CPPUNIT_TEST(testCreateResult_WithoutPayload);
- CPPUNIT_TEST(testCreateError);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- IQTest() {}
-
- void testCreateResult() {
- boost::shared_ptr<Payload> payload(new SoftwareVersion("myclient"));
- boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid", payload));
-
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
- CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
- CPPUNIT_ASSERT(iq->getPayload<SoftwareVersion>());
- CPPUNIT_ASSERT(payload == iq->getPayload<SoftwareVersion>());
- }
-
- void testCreateResult_WithoutPayload() {
- boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid"));
-
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
- CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
- CPPUNIT_ASSERT(!iq->getPayload<SoftwareVersion>());
- }
-
- void testCreateError() {
- boost::shared_ptr<IQ> iq(IQ::createError(JID("foo@bar/fum"), "myid", ErrorPayload::BadRequest, ErrorPayload::Modify));
-
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
- CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
- boost::shared_ptr<ErrorPayload> error(iq->getPayload<ErrorPayload>());
- CPPUNIT_ASSERT(error);
- CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, error->getCondition());
- CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, error->getType());
- }
+ CPPUNIT_TEST_SUITE(IQTest);
+ CPPUNIT_TEST(testCreateResult);
+ CPPUNIT_TEST(testCreateResult_WithoutPayload);
+ CPPUNIT_TEST(testCreateError);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ IQTest() {}
+
+ void testCreateResult() {
+ boost::shared_ptr<Payload> payload(new SoftwareVersion("myclient"));
+ boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid", payload));
+
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
+ CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
+ CPPUNIT_ASSERT(iq->getPayload<SoftwareVersion>());
+ CPPUNIT_ASSERT(payload == iq->getPayload<SoftwareVersion>());
+ }
+
+ void testCreateResult_WithoutPayload() {
+ boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid"));
+
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
+ CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
+ CPPUNIT_ASSERT(!iq->getPayload<SoftwareVersion>());
+ }
+
+ void testCreateError() {
+ boost::shared_ptr<IQ> iq(IQ::createError(JID("foo@bar/fum"), "myid", ErrorPayload::BadRequest, ErrorPayload::Modify));
+
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
+ CPPUNIT_ASSERT_EQUAL(std::string("myid"), iq->getID());
+ boost::shared_ptr<ErrorPayload> error(iq->getPayload<ErrorPayload>());
+ CPPUNIT_ASSERT(error);
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, error->getCondition());
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, error->getType());
+ }
};
diff --git a/Swiften/Elements/UnitTest/StanzaTest.cpp b/Swiften/Elements/UnitTest/StanzaTest.cpp
index de5779c..13c038c 100644
--- a/Swiften/Elements/UnitTest/StanzaTest.cpp
+++ b/Swiften/Elements/UnitTest/StanzaTest.cpp
@@ -19,214 +19,214 @@ using namespace Swift;
class StanzaTest : public CppUnit::TestFixture
{
- CPPUNIT_TEST_SUITE(StanzaTest);
- CPPUNIT_TEST(testConstructor_Copy);
- CPPUNIT_TEST(testGetPayload);
- CPPUNIT_TEST(testGetPayloads);
- CPPUNIT_TEST(testGetPayload_NoSuchPayload);
- CPPUNIT_TEST(testDestructor);
- CPPUNIT_TEST(testDestructor_Copy);
- CPPUNIT_TEST(testUpdatePayload_ExistingPayload);
- CPPUNIT_TEST(testUpdatePayload_NewPayload);
- CPPUNIT_TEST(testGetPayloadOfSameType);
- CPPUNIT_TEST(testGetPayloadOfSameType_NoSuchPayload);
- CPPUNIT_TEST(testGetTimestamp);
- CPPUNIT_TEST(testGetTimestamp_TimestampWithFrom);
- CPPUNIT_TEST(testGetTimestamp_NoDelay);
- CPPUNIT_TEST(testGetTimestampFrom);
- CPPUNIT_TEST(testGetTimestampFrom_Fallsback);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- class MyPayload1 : public Payload {
- public:
- MyPayload1() {}
- };
-
- class MyPayload2 : public Payload {
- public:
- MyPayload2(const std::string& s = "") : text_(s) {}
-
- std::string text_;
- };
-
- class MyPayload3 : public Payload {
- public:
- MyPayload3() {}
- };
-
- class DestroyingPayload : public Payload {
- public:
- DestroyingPayload(bool* alive) : alive_(alive) {
- }
-
- ~DestroyingPayload() {
- (*alive_) = false;
- }
-
- private:
- bool* alive_;
- };
-
- void testConstructor_Copy() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload2>());
- Message copy(m);
-
- CPPUNIT_ASSERT(copy.getPayload<MyPayload1>());
- CPPUNIT_ASSERT(copy.getPayload<MyPayload2>());
- }
-
- void testDestructor() {
- bool payloadAlive = true;
- {
- Message m;
- m.addPayload(boost::make_shared<DestroyingPayload>(&payloadAlive));
- }
-
- CPPUNIT_ASSERT(!payloadAlive);
- }
-
- void testDestructor_Copy() {
- bool payloadAlive = true;
- Message* m1 = new Message();
- m1->addPayload(boost::make_shared<DestroyingPayload>(&payloadAlive));
- Message* m2 = new Message(*m1);
-
- delete m1;
- CPPUNIT_ASSERT(payloadAlive);
-
- delete m2;
- CPPUNIT_ASSERT(!payloadAlive);
- }
-
- void testGetPayload() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload2>());
- m.addPayload(boost::make_shared<MyPayload3>());
-
- boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
- CPPUNIT_ASSERT(p);
- }
-
- void testGetPayload_NoSuchPayload() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload3>());
-
- boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
- CPPUNIT_ASSERT(!p);
- }
-
- void testGetPayloads() {
- Message m;
- boost::shared_ptr<MyPayload2> payload1(new MyPayload2());
- boost::shared_ptr<MyPayload2> payload2(new MyPayload2());
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(payload1);
- m.addPayload(boost::make_shared<MyPayload3>());
- m.addPayload(payload2);
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m.getPayloads<MyPayload2>().size());
- CPPUNIT_ASSERT_EQUAL(payload1, m.getPayloads<MyPayload2>()[0]);
- CPPUNIT_ASSERT_EQUAL(payload2, m.getPayloads<MyPayload2>()[1]);
- }
-
-
- void testUpdatePayload_ExistingPayload() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload2>("foo"));
- m.addPayload(boost::make_shared<MyPayload3>());
-
- m.updatePayload(boost::make_shared<MyPayload2>("bar"));
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size());
- boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
- CPPUNIT_ASSERT_EQUAL(std::string("bar"), p->text_);
- }
-
- void testUpdatePayload_NewPayload() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload3>());
-
- m.updatePayload(boost::make_shared<MyPayload2>("bar"));
-
- CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size());
- boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
- CPPUNIT_ASSERT_EQUAL(std::string("bar"), p->text_);
- }
-
- void testGetPayloadOfSameType() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload2>("foo"));
- m.addPayload(boost::make_shared<MyPayload3>());
-
- boost::shared_ptr<MyPayload2> payload(boost::dynamic_pointer_cast<MyPayload2>(m.getPayloadOfSameType(boost::make_shared<MyPayload2>("bar"))));
- CPPUNIT_ASSERT(payload);
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->text_);
- }
-
- void testGetPayloadOfSameType_NoSuchPayload() {
- Message m;
- m.addPayload(boost::make_shared<MyPayload1>());
- m.addPayload(boost::make_shared<MyPayload3>());
-
- CPPUNIT_ASSERT(!m.getPayloadOfSameType(boost::make_shared<MyPayload2>("bar")));
- }
-
- void testGetTimestamp() {
- Message m;
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1)));
-
- boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
-
- CPPUNIT_ASSERT(timestamp);
- CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
- }
-
- void testGetTimestamp_TimestampWithFrom() {
- Message m;
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo@bar.com")));
-
- boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
-
- CPPUNIT_ASSERT(timestamp);
- CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
- }
-
- void testGetTimestamp_NoDelay() {
- Message m;
- CPPUNIT_ASSERT(!m.getTimestamp());
- }
-
- void testGetTimestampFrom() {
- Message m;
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(0)));
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo1@bar.com")));
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(2), JID("foo2@bar.com")));
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(3), JID("foo3@bar.com")));
-
- boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
-
- CPPUNIT_ASSERT(timestamp);
- CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:02"), boost::posix_time::to_simple_string(*timestamp));
- }
-
- void testGetTimestampFrom_Fallsback() {
- Message m;
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo1@bar.com")));
- m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(3), JID("foo3@bar.com")));
-
- boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
-
- CPPUNIT_ASSERT(timestamp);
- CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
- }
+ CPPUNIT_TEST_SUITE(StanzaTest);
+ CPPUNIT_TEST(testConstructor_Copy);
+ CPPUNIT_TEST(testGetPayload);
+ CPPUNIT_TEST(testGetPayloads);
+ CPPUNIT_TEST(testGetPayload_NoSuchPayload);
+ CPPUNIT_TEST(testDestructor);
+ CPPUNIT_TEST(testDestructor_Copy);
+ CPPUNIT_TEST(testUpdatePayload_ExistingPayload);
+ CPPUNIT_TEST(testUpdatePayload_NewPayload);
+ CPPUNIT_TEST(testGetPayloadOfSameType);
+ CPPUNIT_TEST(testGetPayloadOfSameType_NoSuchPayload);
+ CPPUNIT_TEST(testGetTimestamp);
+ CPPUNIT_TEST(testGetTimestamp_TimestampWithFrom);
+ CPPUNIT_TEST(testGetTimestamp_NoDelay);
+ CPPUNIT_TEST(testGetTimestampFrom);
+ CPPUNIT_TEST(testGetTimestampFrom_Fallsback);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ class MyPayload1 : public Payload {
+ public:
+ MyPayload1() {}
+ };
+
+ class MyPayload2 : public Payload {
+ public:
+ MyPayload2(const std::string& s = "") : text_(s) {}
+
+ std::string text_;
+ };
+
+ class MyPayload3 : public Payload {
+ public:
+ MyPayload3() {}
+ };
+
+ class DestroyingPayload : public Payload {
+ public:
+ DestroyingPayload(bool* alive) : alive_(alive) {
+ }
+
+ ~DestroyingPayload() {
+ (*alive_) = false;
+ }
+
+ private:
+ bool* alive_;
+ };
+
+ void testConstructor_Copy() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload2>());
+ Message copy(m);
+
+ CPPUNIT_ASSERT(copy.getPayload<MyPayload1>());
+ CPPUNIT_ASSERT(copy.getPayload<MyPayload2>());
+ }
+
+ void testDestructor() {
+ bool payloadAlive = true;
+ {
+ Message m;
+ m.addPayload(boost::make_shared<DestroyingPayload>(&payloadAlive));
+ }
+
+ CPPUNIT_ASSERT(!payloadAlive);
+ }
+
+ void testDestructor_Copy() {
+ bool payloadAlive = true;
+ Message* m1 = new Message();
+ m1->addPayload(boost::make_shared<DestroyingPayload>(&payloadAlive));
+ Message* m2 = new Message(*m1);
+
+ delete m1;
+ CPPUNIT_ASSERT(payloadAlive);
+
+ delete m2;
+ CPPUNIT_ASSERT(!payloadAlive);
+ }
+
+ void testGetPayload() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload2>());
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
+ CPPUNIT_ASSERT(p);
+ }
+
+ void testGetPayload_NoSuchPayload() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
+ CPPUNIT_ASSERT(!p);
+ }
+
+ void testGetPayloads() {
+ Message m;
+ boost::shared_ptr<MyPayload2> payload1(new MyPayload2());
+ boost::shared_ptr<MyPayload2> payload2(new MyPayload2());
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(payload1);
+ m.addPayload(boost::make_shared<MyPayload3>());
+ m.addPayload(payload2);
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m.getPayloads<MyPayload2>().size());
+ CPPUNIT_ASSERT_EQUAL(payload1, m.getPayloads<MyPayload2>()[0]);
+ CPPUNIT_ASSERT_EQUAL(payload2, m.getPayloads<MyPayload2>()[1]);
+ }
+
+
+ void testUpdatePayload_ExistingPayload() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload2>("foo"));
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ m.updatePayload(boost::make_shared<MyPayload2>("bar"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size());
+ boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), p->text_);
+ }
+
+ void testUpdatePayload_NewPayload() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ m.updatePayload(boost::make_shared<MyPayload2>("bar"));
+
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size());
+ boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>());
+ CPPUNIT_ASSERT_EQUAL(std::string("bar"), p->text_);
+ }
+
+ void testGetPayloadOfSameType() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload2>("foo"));
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ boost::shared_ptr<MyPayload2> payload(boost::dynamic_pointer_cast<MyPayload2>(m.getPayloadOfSameType(boost::make_shared<MyPayload2>("bar"))));
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->text_);
+ }
+
+ void testGetPayloadOfSameType_NoSuchPayload() {
+ Message m;
+ m.addPayload(boost::make_shared<MyPayload1>());
+ m.addPayload(boost::make_shared<MyPayload3>());
+
+ CPPUNIT_ASSERT(!m.getPayloadOfSameType(boost::make_shared<MyPayload2>("bar")));
+ }
+
+ void testGetTimestamp() {
+ Message m;
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1)));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestamp_TimestampWithFrom() {
+ Message m;
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo@bar.com")));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestamp();
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestamp_NoDelay() {
+ Message m;
+ CPPUNIT_ASSERT(!m.getTimestamp());
+ }
+
+ void testGetTimestampFrom() {
+ Message m;
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(0)));
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo1@bar.com")));
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(2), JID("foo2@bar.com")));
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(3), JID("foo3@bar.com")));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:02"), boost::posix_time::to_simple_string(*timestamp));
+ }
+
+ void testGetTimestampFrom_Fallsback() {
+ Message m;
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(1), JID("foo1@bar.com")));
+ m.addPayload(boost::make_shared<Delay>(boost::posix_time::from_time_t(3), JID("foo3@bar.com")));
+
+ boost::optional<boost::posix_time::ptime> timestamp = m.getTimestampFrom(JID("foo2@bar.com"));
+
+ CPPUNIT_ASSERT(timestamp);
+ CPPUNIT_ASSERT_EQUAL(std::string("1970-Jan-01 00:00:01"), boost::posix_time::to_simple_string(*timestamp));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(StanzaTest);