summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2019-01-15 10:53:33 (GMT)
committerTobias Markmann <tm@ayena.de>2019-01-15 10:55:04 (GMT)
commite618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e (patch)
tree8e84092fba2f6a01b75b8cf313208aa2c8897216 /Swiften/VCards/UnitTest/VCardManagerTest.cpp
parent6f6ad903d9e248f59bddedb3ab4cae41a7d8bec0 (diff)
parent6874d64ed2684d83cb3e340f58f6c8c5089aa857 (diff)
downloadswift-e618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e.zip
swift-e618ab44aa09d6b69b08b14d43ee9ff2dd6abb0e.tar.bz2
Merge tag 'swift-4.x' into master
* branch 'swift-4.x': Update for Debian Don't crash on missing bookmark result Add missing include for QAbstractItemModel Update Debian changelog Fix convertToWindowsVersion() function to handle more RCs Fix error response handling when requesting VCards Test-Information: ./scons test=all succeeded on macOS 10.14.2. Change-Id: I99d20a8b0e1b0be501fbbe95adebbff15f510184
Diffstat (limited to 'Swiften/VCards/UnitTest/VCardManagerTest.cpp')
-rw-r--r--Swiften/VCards/UnitTest/VCardManagerTest.cpp127
1 files changed, 114 insertions, 13 deletions
diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
index 3d5338d..669c3ff 100644
--- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp
+++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -31,7 +31,17 @@ class VCardManagerTest : public CppUnit::TestFixture {
31 CPPUNIT_TEST(testRequest_Error); 31 CPPUNIT_TEST(testRequest_Error);
32 CPPUNIT_TEST(testRequest_VCardAlreadyRequested); 32 CPPUNIT_TEST(testRequest_VCardAlreadyRequested);
33 CPPUNIT_TEST(testRequest_AfterPreviousRequest); 33 CPPUNIT_TEST(testRequest_AfterPreviousRequest);
34 CPPUNIT_TEST(testRequestOwnVCard); 34
35 CPPUNIT_TEST(testRequestVCard_ReturnFullVCard);
36 CPPUNIT_TEST(testRequestVCard_ReturnEmptyVCard);
37 CPPUNIT_TEST(testRequestVCard_ReturnItemNotFoundError);
38 CPPUNIT_TEST(testRequestVCard_ReturnFeatureNotImplementedError);
39
40 CPPUNIT_TEST(testRequestOwnVCard_ReturnFullVCard);
41 CPPUNIT_TEST(testRequestOwnVCard_ReturnEmptyVCard);
42 CPPUNIT_TEST(testRequestOwnVCard_ReturnItemNotFoundError);
43 CPPUNIT_TEST(testRequestOwnVCard_ReturnFeatureNotImplementedError);
44
35 CPPUNIT_TEST(testCreateSetVCardRequest); 45 CPPUNIT_TEST(testCreateSetVCardRequest);
36 CPPUNIT_TEST(testCreateSetVCardRequest_Error); 46 CPPUNIT_TEST(testCreateSetVCardRequest_Error);
37 CPPUNIT_TEST_SUITE_END(); 47 CPPUNIT_TEST_SUITE_END();
@@ -54,7 +64,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
54 } 64 }
55 65
56 void testGet_NewVCardRequestsVCard() { 66 void testGet_NewVCardRequestsVCard() {
57 std::shared_ptr<VCardManager> testling = createManager(); 67 auto testling = createManager();
58 VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz")); 68 VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
59 69
60 CPPUNIT_ASSERT(!result); 70 CPPUNIT_ASSERT(!result);
@@ -63,7 +73,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
63 } 73 }
64 74
65 void testGet_ExistingVCard() { 75 void testGet_ExistingVCard() {
66 std::shared_ptr<VCardManager> testling = createManager(); 76 auto testling = createManager();
67 VCard::ref vcard(new VCard()); 77 VCard::ref vcard(new VCard());
68 vcard->setFullName("Foo Bar"); 78 vcard->setFullName("Foo Bar");
69 vcardStorage->setVCard(JID("foo@bar.com/baz"), vcard); 79 vcardStorage->setVCard(JID("foo@bar.com/baz"), vcard);
@@ -75,7 +85,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
75 } 85 }
76 86
77 void testRequest_RequestsVCard() { 87 void testRequest_RequestsVCard() {
78 std::shared_ptr<VCardManager> testling = createManager(); 88 auto testling = createManager();
79 testling->requestVCard(JID("foo@bar.com/baz")); 89 testling->requestVCard(JID("foo@bar.com/baz"));
80 90
81 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size())); 91 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
@@ -83,7 +93,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
83 } 93 }
84 94
85 void testRequest_ReceiveEmitsNotification() { 95 void testRequest_ReceiveEmitsNotification() {
86 std::shared_ptr<VCardManager> testling = createManager(); 96 auto testling = createManager();
87 testling->requestVCard(JID("foo@bar.com/baz")); 97 testling->requestVCard(JID("foo@bar.com/baz"));
88 stanzaChannel->onIQReceived(createVCardResult()); 98 stanzaChannel->onIQReceived(createVCardResult());
89 99
@@ -96,7 +106,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
96 } 106 }
97 107
98 void testRequest_Error() { 108 void testRequest_Error() {
99 std::shared_ptr<VCardManager> testling = createManager(); 109 auto testling = createManager();
100 testling->requestVCard(JID("foo@bar.com/baz")); 110 testling->requestVCard(JID("foo@bar.com/baz"));
101 stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID())); 111 stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
102 112
@@ -105,7 +115,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
105 } 115 }
106 116
107 void testRequest_VCardAlreadyRequested() { 117 void testRequest_VCardAlreadyRequested() {
108 std::shared_ptr<VCardManager> testling = createManager(); 118 auto testling = createManager();
109 testling->requestVCard(JID("foo@bar.com/baz")); 119 testling->requestVCard(JID("foo@bar.com/baz"));
110 VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz")); 120 VCard::ref result = testling->getVCardAndRequestWhenNeeded(JID("foo@bar.com/baz"));
111 121
@@ -114,7 +124,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
114 } 124 }
115 125
116 void testRequest_AfterPreviousRequest() { 126 void testRequest_AfterPreviousRequest() {
117 std::shared_ptr<VCardManager> testling = createManager(); 127 auto testling = createManager();
118 testling->requestVCard(JID("foo@bar.com/baz")); 128 testling->requestVCard(JID("foo@bar.com/baz"));
119 stanzaChannel->onIQReceived(createVCardResult()); 129 stanzaChannel->onIQReceived(createVCardResult());
120 testling->requestVCard(JID("foo@bar.com/baz")); 130 testling->requestVCard(JID("foo@bar.com/baz"));
@@ -123,8 +133,60 @@ class VCardManagerTest : public CppUnit::TestFixture {
123 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(1, JID("foo@bar.com/baz"), IQ::Get)); 133 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(1, JID("foo@bar.com/baz"), IQ::Get));
124 } 134 }
125 135
126 void testRequestOwnVCard() { 136 void testRequestVCard_ReturnFullVCard() {
127 std::shared_ptr<VCardManager> testling = createManager(); 137 auto testling = createManager();
138 testling->requestVCard(JID("foo@bar.com/baz"));
139 stanzaChannel->onIQReceived(createVCardResult());
140
141 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
142 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
143 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
144 CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first);
145 CPPUNIT_ASSERT_EQUAL(std::string("Foo Bar"), changes[0].second->getFullName());
146 CPPUNIT_ASSERT_EQUAL(false, changes[0].second->isEmpty());
147 }
148
149 void testRequestVCard_ReturnEmptyVCard() {
150 auto testling = createManager();
151 testling->requestVCard(JID("foo@bar.com/baz"));
152 stanzaChannel->onIQReceived([&](){
153 auto vcard = std::make_shared<VCard>();
154 return IQ::createResult(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
155 }());
156
157 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
158 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
159 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
160 CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty());
161 }
162
163 void testRequestVCard_ReturnItemNotFoundError() {
164 auto testling = createManager();
165 testling->requestVCard(JID("foo@bar.com/baz"));
166 stanzaChannel->onIQReceived([&](){
167 return IQ::createError(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::ItemNotFound);
168 }());
169
170 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
171 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
172 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
173 CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty());
174 }
175
176 void testRequestVCard_ReturnFeatureNotImplementedError() {
177 auto testling = createManager();
178 testling->requestVCard(JID("foo@bar.com/baz"));
179 stanzaChannel->onIQReceived([&](){
180 return IQ::createError(JID("foo@bar.com/baz"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::FeatureNotImplemented);
181 }());
182
183 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
184 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID("foo@bar.com/baz"), IQ::Get));
185 CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
186 }
187
188 void testRequestOwnVCard_ReturnFullVCard() {
189 auto testling = createManager();
128 testling->requestVCard(ownJID); 190 testling->requestVCard(ownJID);
129 stanzaChannel->onIQReceived(createOwnVCardResult()); 191 stanzaChannel->onIQReceived(createOwnVCardResult());
130 192
@@ -139,8 +201,47 @@ class VCardManagerTest : public CppUnit::TestFixture {
139 CPPUNIT_ASSERT_EQUAL(std::string("Myself"), ownChanges[0]->getFullName()); 201 CPPUNIT_ASSERT_EQUAL(std::string("Myself"), ownChanges[0]->getFullName());
140 } 202 }
141 203
204 void testRequestOwnVCard_ReturnEmptyVCard() {
205 auto testling = createManager();
206 testling->requestVCard(ownJID);
207 stanzaChannel->onIQReceived([&](){
208 auto vcard = std::make_shared<VCard>();
209 return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
210 }());
211
212 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
213 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get));
214 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
215 CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty());
216 }
217
218 void testRequestOwnVCard_ReturnItemNotFoundError() {
219 auto testling = createManager();
220 testling->requestVCard(ownJID);
221 stanzaChannel->onIQReceived([&](){
222 return IQ::createError(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::ItemNotFound);
223 }());
224
225 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
226 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get));
227 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
228 CPPUNIT_ASSERT_EQUAL(true, changes[0].second->isEmpty());
229 }
230
231 void testRequestOwnVCard_ReturnFeatureNotImplementedError() {
232 auto testling = createManager();
233 testling->requestVCard(ownJID);
234 stanzaChannel->onIQReceived([&](){
235 return IQ::createError(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), ErrorPayload::FeatureNotImplemented);
236 }());
237
238 CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
239 CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<VCard>(0, JID(), IQ::Get));
240 CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(changes.size()));
241 }
242
142 void testCreateSetVCardRequest() { 243 void testCreateSetVCardRequest() {
143 std::shared_ptr<VCardManager> testling = createManager(); 244 auto testling = createManager();
144 VCard::ref vcard = std::make_shared<VCard>(); 245 VCard::ref vcard = std::make_shared<VCard>();
145 vcard->setFullName("New Name"); 246 vcard->setFullName("New Name");
146 SetVCardRequest::ref request = testling->createSetVCardRequest(vcard); 247 SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);
@@ -154,7 +255,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
154 } 255 }
155 256
156 void testCreateSetVCardRequest_Error() { 257 void testCreateSetVCardRequest_Error() {
157 std::shared_ptr<VCardManager> testling = createManager(); 258 auto testling = createManager();
158 VCard::ref vcard = std::make_shared<VCard>(); 259 VCard::ref vcard = std::make_shared<VCard>();
159 vcard->setFullName("New Name"); 260 vcard->setFullName("New Name");
160 SetVCardRequest::ref request = testling->createSetVCardRequest(vcard); 261 SetVCardRequest::ref request = testling->createSetVCardRequest(vcard);