1 // xestiaab_carddav.h - Xestia Address Book CardDAV Object Unit Tests.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <gtest/gtest.h>
20 #include "classes/FakeConnectionObject.h"
24 // TODO: Add tests for the CardDAV object.
26 TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_True){
28 std::string ServerAddress1 = "gibberish.invalid";
29 std::string ServerUser1 = "user";
30 std::string ServerPass1 = "pass";
32 std::string ServerAddress2 = "gibberish2.invalid";
33 std::string ServerUser2 = "user2";
34 std::string ServerPass2 = "pass2";
36 std::string ServerAddress3 = "gibberish3.invalid";
37 std::string ServerUser3 = "user3";
38 std::string ServerPass3 = "pass3";
40 FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
41 FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true);
42 FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false);
44 FakeConnection1.ResultTestMode = true;
45 FakeConnection2.ResultTestMode = true;
46 FakeConnection3.ResultTestMode = true;
48 EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
49 EXPECT_EQ(8080, FakeConnection1.GetServerPort());
50 EXPECT_EQ("user", FakeConnection1.GetServerUser());
51 EXPECT_EQ("pass", FakeConnection1.GetServerPass());
52 EXPECT_EQ(true, FakeConnection1.GetServerSSL());
53 EXPECT_EQ(true, FakeConnection1.GetTestMode());
55 EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
56 EXPECT_EQ(8800, FakeConnection2.GetServerPort());
57 EXPECT_EQ("user2", FakeConnection2.GetServerUser());
58 EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
59 EXPECT_EQ(true, FakeConnection2.GetServerSSL());
60 EXPECT_EQ(true, FakeConnection2.GetTestMode());
62 EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
63 EXPECT_EQ(8008, FakeConnection3.GetServerPort());
64 EXPECT_EQ("user3", FakeConnection3.GetServerUser());
65 EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
66 EXPECT_EQ(false, FakeConnection3.GetServerSSL());
67 EXPECT_EQ(true, FakeConnection3.GetTestMode());
71 TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_False){
73 std::string ServerAddress1 = "gibberish.invalid";
74 std::string ServerUser1 = "user";
75 std::string ServerPass1 = "pass";
76 std::string ServerPrefix1 = "/prefix";
77 std::string ServerAccount1 = "Account1";
79 std::string ServerAddress2 = "gibberish2.invalid";
80 std::string ServerUser2 = "user2";
81 std::string ServerPass2 = "pass2";
82 std::string ServerPrefix2 = "/prefix2";
83 std::string ServerAccount2 = "Account2";
85 std::string ServerAddress3 = "gibberish3.invalid";
86 std::string ServerUser3 = "user3";
87 std::string ServerPass3 = "pass3";
88 std::string ServerPrefix3 = "/prefix3";
89 std::string ServerAccount3 = "Account3";
91 FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
92 FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true, "/prefix2", "Account2");
93 FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false, "/prefix3", "Account3");
95 FakeConnection1.ResultTestMode = false;
96 FakeConnection2.ResultTestMode = false;
97 FakeConnection3.ResultTestMode = false;
99 EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
100 EXPECT_EQ(8080, FakeConnection1.GetServerPort());
101 EXPECT_EQ("user", FakeConnection1.GetServerUser());
102 EXPECT_EQ("pass", FakeConnection1.GetServerPass());
103 EXPECT_EQ(true, FakeConnection1.GetServerSSL());
104 EXPECT_EQ(false, FakeConnection1.GetTestMode());
105 EXPECT_EQ("/prefix", FakeConnection1.GetServerPrefix());
106 EXPECT_EQ("Account1", FakeConnection1.GetServerAccount());
108 EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
109 EXPECT_EQ(8800, FakeConnection2.GetServerPort());
110 EXPECT_EQ("user2", FakeConnection2.GetServerUser());
111 EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
112 EXPECT_EQ(true, FakeConnection2.GetServerSSL());
113 EXPECT_EQ(false, FakeConnection2.GetTestMode());
114 EXPECT_EQ("/prefix2", FakeConnection2.GetServerPrefix());
115 EXPECT_EQ("Account2", FakeConnection2.GetServerAccount());
117 EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
118 EXPECT_EQ(8008, FakeConnection3.GetServerPort());
119 EXPECT_EQ("user3", FakeConnection3.GetServerUser());
120 EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
121 EXPECT_EQ(false, FakeConnection3.GetServerSSL());
122 EXPECT_EQ(false, FakeConnection3.GetTestMode());
123 EXPECT_EQ("/prefix3", FakeConnection3.GetServerPrefix());
124 EXPECT_EQ("Account3", FakeConnection3.GetServerAccount());
128 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Success){
130 std::string ServerAddress1 = "gibberish.invalid";
131 std::string ServerUser1 = "user";
132 std::string ServerPass1 = "pass";
134 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
135 FakeConnection.ResultStatus = COCONNECT_OK;
137 EXPECT_EQ(COCONNECT_OK, FakeConnection.Connect(false));
141 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_InvalidAddress){
143 std::string ServerAddress1 = "gibberish.invalid";
144 std::string ServerUser1 = "user";
145 std::string ServerPass1 = "pass";
147 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
148 FakeConnection.ResultStatus = COCONNECT_INVALID;
150 EXPECT_EQ(COCONNECT_INVALID, FakeConnection.Connect(false));
154 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Timeout){
156 std::string ServerAddress1 = "gibberish.invalid";
157 std::string ServerUser1 = "user";
158 std::string ServerPass1 = "pass";
160 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
161 FakeConnection.ResultStatus = COCONNECT_TIMEOUT;
163 EXPECT_EQ(COCONNECT_TIMEOUT, FakeConnection.Connect(false));
167 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Authentication_Failure){
169 std::string ServerAddress1 = "gibberish.invalid";
170 std::string ServerUser1 = "user";
171 std::string ServerPass1 = "pass";
173 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
174 FakeConnection.ResultStatus = COCONNECT_AUTHFAIL;
176 EXPECT_EQ(COCONNECT_AUTHFAIL, FakeConnection.Connect(false));
180 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Able_To_Login){
182 std::string ServerAddress1 = "gibberish.invalid";
183 std::string ServerUser1 = "user";
184 std::string ServerPass1 = "pass";
186 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
187 FakeConnection.ResultAuthPassed = true;
188 FakeConnection.Connect(false);
190 EXPECT_EQ(true, FakeConnection.AbleToLogin());
194 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Unable_To_Login){
196 std::string ServerAddress1 = "gibberish.invalid";
197 std::string ServerUser1 = "user";
198 std::string ServerPass1 = "pass";
200 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
201 FakeConnection.ResultAuthPassed = false;
202 FakeConnection.Connect(false);
204 EXPECT_EQ(false, FakeConnection.AbleToLogin());
208 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Can_Do_Processing){
210 std::string ServerAddress1 = "gibberish.invalid";
211 std::string ServerUser1 = "user";
212 std::string ServerPass1 = "pass";
214 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
215 FakeConnection.ResultCanProcess = true;
216 FakeConnection.Connect(false);
218 EXPECT_EQ(true, FakeConnection.CanDoProcessing());
222 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Supports_SSL){
224 std::string ServerAddress1 = "gibberish.invalid";
225 std::string ServerUser1 = "user";
226 std::string ServerPass1 = "pass";
228 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
229 FakeConnection.ResultSSLStatus = true;
230 FakeConnection.Connect(false);
232 EXPECT_EQ(true, FakeConnection.CanDoSSL());
236 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Does_Not_Support_SSL){
238 std::string ServerAddress1 = "gibberish.invalid";
239 std::string ServerUser1 = "user";
240 std::string ServerPass1 = "pass";
242 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
243 FakeConnection.ResultSSLStatus = false;
244 FakeConnection.Connect(false);
246 EXPECT_EQ(false, FakeConnection.CanDoSSL());
250 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Valid_SSL_Certificate_Data){
252 std::string ServerAddress1 = "gibberish.invalid";
253 std::string ServerUser1 = "user";
254 std::string ServerPass1 = "pass";
256 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
257 FakeConnection.ResultSSLVerified = COSSL_VERIFIED;
258 FakeConnection.Connect(false);
260 EXPECT_EQ(COSSL_VERIFIED, FakeConnection.SSLVerify());
264 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Invalid_SSL_Certificate_Data){
266 std::string ServerAddress1 = "gibberish.invalid";
267 std::string ServerUser1 = "user";
268 std::string ServerPass1 = "pass";
270 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
271 FakeConnection.ResultSSLVerified = COSSL_UNABLETOVERIFY;
272 FakeConnection.ResultStatus = COCONNECT_SSLFAIL;
274 EXPECT_EQ(COCONNECT_SSLFAIL, FakeConnection.Connect(false));
275 EXPECT_EQ(COSSL_UNABLETOVERIFY, FakeConnection.SSLVerify());
279 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_User_Verified_SSL_Cerficiate_Data){
281 std::string ServerAddress1 = "gibberish.invalid";
282 std::string ServerUser1 = "user";
283 std::string ServerPass1 = "pass";
285 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
286 FakeConnection.ResultSSLVerified = COSSL_VERIFIED_USER;
287 FakeConnection.Connect(false);
289 EXPECT_EQ(COSSL_VERIFIED_USER, FakeConnection.SSLVerify());
293 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_SSL_Return_Not_Applicable_SSL_Result){
295 std::string ServerAddress1 = "gibberish.invalid";
296 std::string ServerUser1 = "user";
297 std::string ServerPass1 = "pass";
299 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, false);
300 FakeConnection.ResultSSLVerified = COSSL_NOTAPPLICABLE;
301 FakeConnection.Connect(false);
303 EXPECT_EQ(COSSL_NOTAPPLICABLE, FakeConnection.SSLVerify());
307 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Valid_Response){
309 std::string ServerAddress1 = "gibberish.invalid";
310 std::string ServerUser1 = "user";
311 std::string ServerPass1 = "pass";
313 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
314 FakeConnection.ResultValidResponse = true;
315 FakeConnection.Connect(false);
317 EXPECT_EQ(true, FakeConnection.HasValidResponse());
321 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Invalid_Response){
323 std::string ServerAddress1 = "gibberish.invalid";
324 std::string ServerUser1 = "user";
325 std::string ServerPass1 = "pass";
327 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
328 FakeConnection.ResultValidResponse = false;
329 FakeConnection.Connect(false);
331 EXPECT_EQ(false, FakeConnection.HasValidResponse());
335 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Uses_A_Self_Signed_SSL_Certificate){
337 std::string ServerAddress1 = "gibberish.invalid";
338 std::string ServerUser1 = "user";
339 std::string ServerPass1 = "pass";
341 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
342 FakeConnection.ResultSelfSigned = true;
343 FakeConnection.Connect(false);
345 EXPECT_EQ(true, FakeConnection.IsSelfSigned());
349 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_A_Self_Signed_SSL_Certificate){
351 std::string ServerAddress1 = "gibberish.invalid";
352 std::string ServerUser1 = "user";
353 std::string ServerPass1 = "pass";
355 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
356 FakeConnection.ResultSelfSigned = false;
357 FakeConnection.Connect(false);
359 EXPECT_EQ(false, FakeConnection.IsSelfSigned());
363 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_A){
365 std::string ServerAddress1 = "gibberish.invalid";
366 std::string ServerUser1 = "user";
367 std::string ServerPass1 = "pass";
369 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
370 FakeConnection.ResultServerPrefix = "/prefix/test/a";
371 FakeConnection.Connect(false);
373 EXPECT_EQ("/prefix/test/a", FakeConnection.GetDefaultPrefix());
377 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_B){
379 std::string ServerAddress1 = "gibberish.invalid";
380 std::string ServerUser1 = "user";
381 std::string ServerPass1 = "pass";
383 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
384 FakeConnection.ResultServerPrefix = "/prefix/test/b";
385 FakeConnection.Connect(false);
387 EXPECT_EQ("/prefix/test/b", FakeConnection.GetDefaultPrefix());
391 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully){
393 std::string ServerAddress1 = "gibberish.invalid";
394 std::string ServerUser1 = "user";
395 std::string ServerPass1 = "pass";
397 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
398 FakeConnection.ResultServerPrefix = "/prefix/test/b";
399 FakeConnection.Connect(false);
401 std::string ContactFile =
404 "UID:84q2ioj13jofiujqwr\n"
409 FakeConnection.TestRequestResult = COREQUEST_OK;
410 FakeConnection.TestEntityTag = "4324svafhuiaffsdhui";
411 FakeConnection.TestResultCode = 201;
412 FakeConnection.TestSessionCode = 0;
413 FakeConnection.TestResultMessage = "";
415 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
417 EXPECT_EQ(COREQUEST_OK, AddContactResult.RequestResult);
418 EXPECT_EQ("4324svafhuiaffsdhui", AddContactResult.EntityTag);
419 EXPECT_EQ(201, AddContactResult.ResultCode);
420 EXPECT_EQ(0, AddContactResult.SessionCode);
421 EXPECT_EQ("", AddContactResult.ResultMessage);
425 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Permissions){
427 std::string ServerAddress1 = "gibberish.invalid";
428 std::string ServerUser1 = "user";
429 std::string ServerPass1 = "pass";
431 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
432 FakeConnection.ResultServerPrefix = "/prefix/test/b";
433 FakeConnection.Connect(false);
435 std::string ContactFile =
438 "UID:84q2ioj13jofiujqwr\n"
443 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
444 FakeConnection.TestEntityTag = "";
445 FakeConnection.TestResultCode = 403;
446 FakeConnection.TestSessionCode = 22;
447 FakeConnection.TestResultMessage = "You do not have permission to add this resource.";
449 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
451 EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult);
452 EXPECT_EQ("", AddContactResult.EntityTag);
453 EXPECT_EQ(403, AddContactResult.ResultCode);
454 EXPECT_EQ(22, AddContactResult.SessionCode);
455 EXPECT_EQ("You do not have permission to add this resource.", AddContactResult.ResultMessage);
459 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Invalid_Path){
461 std::string ServerAddress1 = "gibberish.invalid";
462 std::string ServerUser1 = "user";
463 std::string ServerPass1 = "pass";
465 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
466 FakeConnection.ResultServerPrefix = "/prefix/test/b";
467 FakeConnection.Connect(false);
469 std::string ContactFile =
472 "UID:84q2ioj13jofiujqwr\n"
477 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
478 FakeConnection.TestEntityTag = "";
479 FakeConnection.TestResultCode = 404;
480 FakeConnection.TestSessionCode = 22;
481 FakeConnection.TestResultMessage = "The location cannot be found.";
483 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
485 EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult);
486 EXPECT_EQ("", AddContactResult.EntityTag);
487 EXPECT_EQ(404, AddContactResult.ResultCode);
488 EXPECT_EQ(22, AddContactResult.SessionCode);
489 EXPECT_EQ("The location cannot be found.", AddContactResult.ResultMessage);
493 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_No_Connection){
495 std::string ServerAddress1 = "gibberish.invalid";
496 std::string ServerUser1 = "user";
497 std::string ServerPass1 = "pass";
499 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
500 FakeConnection.ResultServerPrefix = "/prefix/test/b";
501 FakeConnection.Connect(false);
503 std::string ContactFile =
506 "UID:84q2ioj13jofiujqwr\n"
511 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
512 FakeConnection.TestEntityTag = "";
513 FakeConnection.TestResultCode = 0;
514 FakeConnection.TestSessionCode = 0;
515 FakeConnection.TestResultMessage = "";
517 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
519 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, AddContactResult.RequestResult);
520 EXPECT_EQ("", AddContactResult.EntityTag);
521 EXPECT_EQ(0, AddContactResult.ResultCode);
522 EXPECT_EQ(0, AddContactResult.SessionCode);
523 EXPECT_EQ("", AddContactResult.ResultMessage);
527 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Edits_A_Server_Contact){
529 std::string ServerAddress1 = "gibberish.invalid";
530 std::string ServerUser1 = "user";
531 std::string ServerPass1 = "pass";
533 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
534 FakeConnection.ResultServerPrefix = "/prefix/test/b";
535 FakeConnection.Connect(false);
537 std::string ContactFile =
540 "UID:84q2ioj13jofiujqwrAAA\n"
545 FakeConnection.TestRequestResult = COREQUEST_OK;
546 FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
547 FakeConnection.TestResultCode = 200;
548 FakeConnection.TestSessionCode = 0;
549 FakeConnection.TestResultMessage = "";
551 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
553 EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult);
554 EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EditContactResult.EntityTag);
555 EXPECT_EQ(200, EditContactResult.ResultCode);
556 EXPECT_EQ(0, EditContactResult.SessionCode);
557 EXPECT_EQ("", EditContactResult.ResultMessage);
559 FakeConnection.TestRequestResult = COREQUEST_OK;
560 FakeConnection.TestEntityTag = "asf84sa484saf614as64asvada4s6fas";
561 FakeConnection.TestResultCode = 204;
562 FakeConnection.TestSessionCode = 0;
563 FakeConnection.TestResultMessage = "";
565 EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
567 EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult);
568 EXPECT_EQ("asf84sa484saf614as64asvada4s6fas", EditContactResult.EntityTag);
569 EXPECT_EQ(204, EditContactResult.ResultCode);
570 EXPECT_EQ(0, EditContactResult.SessionCode);
571 EXPECT_EQ("", EditContactResult.ResultMessage);
575 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Permissions){
577 std::string ServerAddress1 = "gibberish.invalid";
578 std::string ServerUser1 = "user";
579 std::string ServerPass1 = "pass";
581 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
582 FakeConnection.ResultServerPrefix = "/prefix/test/b";
583 FakeConnection.Connect(false);
585 std::string ContactFile =
588 "UID:84q2ioj13jofiujqwrAAA\n"
593 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
594 FakeConnection.TestEntityTag = "";
595 FakeConnection.TestResultCode = 403;
596 FakeConnection.TestSessionCode = 22;
597 FakeConnection.TestResultMessage = "You do not have permission to add this resource.";
599 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
601 EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult);
602 EXPECT_EQ("", EditContactResult.EntityTag);
603 EXPECT_EQ(403, EditContactResult.ResultCode);
604 EXPECT_EQ(22, EditContactResult.SessionCode);
605 EXPECT_EQ("You do not have permission to add this resource.", EditContactResult.ResultMessage);
609 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Location){
611 std::string ServerAddress1 = "gibberish.invalid";
612 std::string ServerUser1 = "user";
613 std::string ServerPass1 = "pass";
615 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
616 FakeConnection.ResultServerPrefix = "/prefix/test/b";
617 FakeConnection.Connect(false);
619 std::string ContactFile =
622 "UID:84q2ioj13jofiujqwrAAA\n"
627 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
628 FakeConnection.TestEntityTag = "";
629 FakeConnection.TestResultCode = 404;
630 FakeConnection.TestSessionCode = 22;
631 FakeConnection.TestResultMessage = "The resource could not be found.";
633 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
635 EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult);
636 EXPECT_EQ("", EditContactResult.EntityTag);
637 EXPECT_EQ(404, EditContactResult.ResultCode);
638 EXPECT_EQ(22, EditContactResult.SessionCode);
639 EXPECT_EQ("The resource could not be found.", EditContactResult.ResultMessage);
643 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_No_Connection){
645 std::string ServerAddress1 = "gibberish.invalid";
646 std::string ServerUser1 = "user";
647 std::string ServerPass1 = "pass";
649 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
650 FakeConnection.ResultServerPrefix = "/prefix/test/b";
651 FakeConnection.Connect(false);
653 std::string ContactFile =
656 "UID:84q2ioj13jofiujqwrAAA\n"
661 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
662 FakeConnection.TestEntityTag = "";
663 FakeConnection.TestResultCode = 0;
664 FakeConnection.TestSessionCode = 0;
665 FakeConnection.TestResultMessage = "";
667 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
669 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EditContactResult.RequestResult);
670 EXPECT_EQ("", EditContactResult.EntityTag);
671 EXPECT_EQ(0, EditContactResult.ResultCode);
672 EXPECT_EQ(0, EditContactResult.SessionCode);
673 EXPECT_EQ("", EditContactResult.ResultMessage);
677 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Deletes_A_Server_Contact){
679 std::string ServerAddress1 = "gibberish.invalid";
680 std::string ServerUser1 = "user";
681 std::string ServerPass1 = "pass";
683 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
684 FakeConnection.ResultServerPrefix = "/prefix/test/b";
685 FakeConnection.Connect(false);
687 FakeConnection.TestRequestResult = COREQUEST_OK;
688 FakeConnection.TestEntityTag = "";
689 FakeConnection.TestResultCode = 200;
690 FakeConnection.TestSessionCode = 0;
691 FakeConnection.TestResultMessage = "";
693 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
695 EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult);
696 EXPECT_EQ("", DeleteContactResult.EntityTag);
697 EXPECT_EQ(200, DeleteContactResult.ResultCode);
698 EXPECT_EQ(0, DeleteContactResult.SessionCode);
699 EXPECT_EQ("", DeleteContactResult.ResultMessage);
701 FakeConnection.TestRequestResult = COREQUEST_OK;
702 FakeConnection.TestEntityTag = "";
703 FakeConnection.TestResultCode = 204;
704 FakeConnection.TestSessionCode = 0;
705 FakeConnection.TestResultMessage = "";
707 DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
709 EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult);
710 EXPECT_EQ("", DeleteContactResult.EntityTag);
711 EXPECT_EQ(204, DeleteContactResult.ResultCode);
712 EXPECT_EQ(0, DeleteContactResult.SessionCode);
713 EXPECT_EQ("", DeleteContactResult.ResultMessage);
717 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Invalid_Permissions){
719 std::string ServerAddress1 = "gibberish.invalid";
720 std::string ServerUser1 = "user";
721 std::string ServerPass1 = "pass";
723 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
724 FakeConnection.ResultServerPrefix = "/prefix/test/b";
725 FakeConnection.Connect(false);
727 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
728 FakeConnection.TestEntityTag = "";
729 FakeConnection.TestResultCode = 403;
730 FakeConnection.TestSessionCode = 22;
731 FakeConnection.TestResultMessage = "You do not have permission to delete this resource.";
733 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
735 EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult);
736 EXPECT_EQ("", DeleteContactResult.EntityTag);
737 EXPECT_EQ(403, DeleteContactResult.ResultCode);
738 EXPECT_EQ(22, DeleteContactResult.SessionCode);
739 EXPECT_EQ("You do not have permission to delete this resource.", DeleteContactResult.ResultMessage);
743 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Missing_Location){
745 std::string ServerAddress1 = "gibberish.invalid";
746 std::string ServerUser1 = "user";
747 std::string ServerPass1 = "pass";
749 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
750 FakeConnection.ResultServerPrefix = "/prefix/test/b";
751 FakeConnection.Connect(false);
753 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
754 FakeConnection.TestEntityTag = "";
755 FakeConnection.TestResultCode = 404;
756 FakeConnection.TestSessionCode = 22;
757 FakeConnection.TestResultMessage = "The resource could not be found.";
759 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
761 EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult);
762 EXPECT_EQ("", DeleteContactResult.EntityTag);
763 EXPECT_EQ(404, DeleteContactResult.ResultCode);
764 EXPECT_EQ(22, DeleteContactResult.SessionCode);
765 EXPECT_EQ("The resource could not be found.", DeleteContactResult.ResultMessage);
769 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_No_Connection){
771 std::string ServerAddress1 = "gibberish.invalid";
772 std::string ServerUser1 = "user";
773 std::string ServerPass1 = "pass";
775 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
776 FakeConnection.ResultServerPrefix = "/prefix/test/b";
777 FakeConnection.Connect(false);
779 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
780 FakeConnection.TestEntityTag = "";
781 FakeConnection.TestResultCode = 0;
782 FakeConnection.TestSessionCode = 0;
783 FakeConnection.TestResultMessage = "";
785 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
787 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, DeleteContactResult.RequestResult);
788 EXPECT_EQ("", DeleteContactResult.EntityTag);
789 EXPECT_EQ(0, DeleteContactResult.ResultCode);
790 EXPECT_EQ(0, DeleteContactResult.SessionCode);
791 EXPECT_EQ("", DeleteContactResult.ResultMessage);
795 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Entity_Tag_Value){
797 std::string ServerAddress1 = "gibberish.invalid";
798 std::string ServerUser1 = "user";
799 std::string ServerPass1 = "pass";
801 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
802 FakeConnection.ResultServerPrefix = "/prefix/test/b";
803 FakeConnection.Connect(false);
805 FakeConnection.TestRequestResult = COREQUEST_OK;
806 FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
807 FakeConnection.TestResultCode = 200;
808 FakeConnection.TestSessionCode = 0;
809 FakeConnection.TestResultMessage = "";
811 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
813 EXPECT_EQ(COREQUEST_OK, EntityTagResult.RequestResult);
814 EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EntityTagResult.EntityTag);
815 EXPECT_EQ(200, EntityTagResult.ResultCode);
816 EXPECT_EQ(0, EntityTagResult.SessionCode);
817 EXPECT_EQ("", EntityTagResult.ResultMessage);
821 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Invalid_Permissions){
823 std::string ServerAddress1 = "gibberish.invalid";
824 std::string ServerUser1 = "user";
825 std::string ServerPass1 = "pass";
827 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
828 FakeConnection.ResultServerPrefix = "/prefix/test/b";
829 FakeConnection.Connect(false);
831 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
832 FakeConnection.TestEntityTag = "";
833 FakeConnection.TestResultCode = 403;
834 FakeConnection.TestSessionCode = 22;
835 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
837 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
839 EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult);
840 EXPECT_EQ("", EntityTagResult.EntityTag);
841 EXPECT_EQ(403, EntityTagResult.ResultCode);
842 EXPECT_EQ(22, EntityTagResult.SessionCode);
843 EXPECT_EQ("You do not have permission to access this resource.", EntityTagResult.ResultMessage);
847 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Missing_Resource){
849 std::string ServerAddress1 = "gibberish.invalid";
850 std::string ServerUser1 = "user";
851 std::string ServerPass1 = "pass";
853 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
854 FakeConnection.ResultServerPrefix = "/prefix/test/b";
855 FakeConnection.Connect(false);
857 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
858 FakeConnection.TestEntityTag = "";
859 FakeConnection.TestResultCode = 404;
860 FakeConnection.TestSessionCode = 22;
861 FakeConnection.TestResultMessage = "The resource cannot be found.";
863 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
865 EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult);
866 EXPECT_EQ("", EntityTagResult.EntityTag);
867 EXPECT_EQ(404, EntityTagResult.ResultCode);
868 EXPECT_EQ(22, EntityTagResult.SessionCode);
869 EXPECT_EQ("The resource cannot be found.", EntityTagResult.ResultMessage);
873 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_No_Connection){
875 std::string ServerAddress1 = "gibberish.invalid";
876 std::string ServerUser1 = "user";
877 std::string ServerPass1 = "pass";
879 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
880 FakeConnection.ResultServerPrefix = "/prefix/test/b";
881 FakeConnection.Connect(false);
883 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
884 FakeConnection.TestEntityTag = "";
885 FakeConnection.TestResultCode = 0;
886 FakeConnection.TestSessionCode = 0;
887 FakeConnection.TestResultMessage = "";
889 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
891 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EntityTagResult.RequestResult);
892 EXPECT_EQ("", EntityTagResult.EntityTag);
893 EXPECT_EQ(0, EntityTagResult.ResultCode);
894 EXPECT_EQ(0, EntityTagResult.SessionCode);
895 EXPECT_EQ("", EntityTagResult.ResultMessage);
899 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Contact_Data){
901 std::string ServerAddress1 = "gibberish.invalid";
902 std::string ServerUser1 = "user";
903 std::string ServerPass1 = "pass";
905 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
906 FakeConnection.ResultServerPrefix = "/prefix/test/b";
907 FakeConnection.Connect(false);
909 std::string ContactFile =
912 "UID:84q2ioj13jofiujqwrAAA\n"
917 FakeConnection.TestRequestResult = COREQUEST_OK;
918 FakeConnection.TestEntityTag = "";
919 FakeConnection.TestResultCode = 200;
920 FakeConnection.TestSessionCode = 0;
921 FakeConnection.TestResultMessage = ContactFile;
923 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
925 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
926 EXPECT_EQ("", ServerDataResult.EntityTag);
927 EXPECT_EQ(200, ServerDataResult.ResultCode);
928 EXPECT_EQ(0, ServerDataResult.SessionCode);
929 EXPECT_EQ(ContactFile, ServerDataResult.ResultMessage);
933 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Invalid_Permissions){
935 std::string ServerAddress1 = "gibberish.invalid";
936 std::string ServerUser1 = "user";
937 std::string ServerPass1 = "pass";
939 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
940 FakeConnection.ResultServerPrefix = "/prefix/test/b";
941 FakeConnection.Connect(false);
943 FakeConnection.TestRequestResult = COREQUEST_OK;
944 FakeConnection.TestEntityTag = "";
945 FakeConnection.TestResultCode = 403;
946 FakeConnection.TestSessionCode = 22;
947 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
949 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
951 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
952 EXPECT_EQ("", ServerDataResult.EntityTag);
953 EXPECT_EQ(403, ServerDataResult.ResultCode);
954 EXPECT_EQ(22, ServerDataResult.SessionCode);
955 EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ResultMessage);
959 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Missing_Resource){
961 std::string ServerAddress1 = "gibberish.invalid";
962 std::string ServerUser1 = "user";
963 std::string ServerPass1 = "pass";
965 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
966 FakeConnection.ResultServerPrefix = "/prefix/test/b";
967 FakeConnection.Connect(false);
969 FakeConnection.TestRequestResult = COREQUEST_OK;
970 FakeConnection.TestEntityTag = "";
971 FakeConnection.TestResultCode = 404;
972 FakeConnection.TestSessionCode = 22;
973 FakeConnection.TestResultMessage = "The resource could not be found.";
975 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
977 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
978 EXPECT_EQ("", ServerDataResult.EntityTag);
979 EXPECT_EQ(404, ServerDataResult.ResultCode);
980 EXPECT_EQ(22, ServerDataResult.SessionCode);
981 EXPECT_EQ("The resource could not be found.", ServerDataResult.ResultMessage);
985 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Contact_Data_Due_To_No_Connection){
987 std::string ServerAddress1 = "gibberish.invalid";
988 std::string ServerUser1 = "user";
989 std::string ServerPass1 = "pass";
991 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
992 FakeConnection.ResultServerPrefix = "/prefix/test/b";
993 FakeConnection.Connect(false);
995 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
996 FakeConnection.TestEntityTag = "";
997 FakeConnection.TestResultCode = 0;
998 FakeConnection.TestSessionCode = 0;
999 FakeConnection.TestResultMessage = "";
1001 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
1003 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.RequestResult);
1004 EXPECT_EQ("", ServerDataResult.EntityTag);
1005 EXPECT_EQ(0, ServerDataResult.ResultCode);
1006 EXPECT_EQ(0, ServerDataResult.SessionCode);
1007 EXPECT_EQ("", ServerDataResult.ResultMessage);
1011 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Full_Server_Contact_List){
1013 std::string ServerAddress1 = "gibberish.invalid";
1014 std::string ServerUser1 = "user";
1015 std::string ServerPass1 = "pass";
1017 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1018 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1019 FakeConnection.Connect(false);
1021 std::string ContactFile1 =
1024 "UID:84q2ioj13jofiujqwrAAA-1\n"
1026 "FN:The Meep Moop\n"
1029 std::string ContactFile2 =
1032 "UID:84q2ioj13jofiujqwrAAA-2\n"
1034 "FN:The Meep Moop\n"
1037 std::string ContactFile3 =
1040 "UID:84q2ioj13jofiujqwrAAA-3\n"
1042 "FN:The Meep Moop\n"
1045 COContactList ContactListSetup;
1046 COContactData ContactPerson;
1048 ContactPerson.Location = "/location1.vcf";
1049 ContactPerson.Data = ContactFile1;
1050 ContactListSetup.ListData.push_back(ContactPerson);
1052 ContactPerson.Location = "/location2.vcf";
1053 ContactPerson.Data = ContactFile2;
1054 ContactListSetup.ListData.push_back(ContactPerson);
1056 ContactPerson.Location = "/location3.vcf";
1057 ContactPerson.Data = ContactFile3;
1058 ContactListSetup.ListData.push_back(ContactPerson);
1059 ContactListSetup.SyncToken = "2312312-12312312";
1061 FakeConnection.TestContactList = ContactListSetup;
1062 FakeConnection.TestRequestResult = COREQUEST_OK;
1063 FakeConnection.TestEntityTag = "";
1064 FakeConnection.TestResultCode = 200;
1065 FakeConnection.TestSessionCode = 0;
1066 FakeConnection.TestResultMessage = "";
1068 COContactList ServerDataResult = FakeConnection.GetContactList("");
1070 EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult);
1071 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1072 EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode);
1073 EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode);
1074 EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage);
1076 EXPECT_EQ("2312312-12312312", ServerDataResult.SyncToken);
1078 EXPECT_EQ(3, ServerDataResult.ListData.size());
1080 EXPECT_EQ("/location1.vcf", ServerDataResult.ListData[0].Location);
1081 EXPECT_EQ(ContactFile1, ServerDataResult.ListData[0].Data);
1083 EXPECT_EQ("/location2.vcf", ServerDataResult.ListData[1].Location);
1084 EXPECT_EQ(ContactFile2, ServerDataResult.ListData[1].Data);
1086 EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[2].Location);
1087 EXPECT_EQ(ContactFile3, ServerDataResult.ListData[2].Data);
1091 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Partial_Server_Contact_List){
1093 std::string ServerAddress1 = "gibberish.invalid";
1094 std::string ServerUser1 = "user";
1095 std::string ServerPass1 = "pass";
1097 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1098 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1099 FakeConnection.Connect(false);
1101 std::string ContactFile3 =
1104 "UID:84q2ioj13jofiujqwrAAA-3\n"
1106 "FN:The Meep Moop\n"
1109 COContactList ContactListSetup;
1110 COContactData ContactPerson;
1112 ContactPerson.Location = "/location3.vcf";
1113 ContactPerson.Data = ContactFile3;
1114 ContactListSetup.ListData.push_back(ContactPerson);
1115 ContactListSetup.SyncToken = "5964589-43543534";
1117 FakeConnection.TestContactList = ContactListSetup;
1118 FakeConnection.TestRequestResult = COREQUEST_OK;
1119 FakeConnection.TestEntityTag = "";
1120 FakeConnection.TestResultCode = 200;
1121 FakeConnection.TestSessionCode = 0;
1122 FakeConnection.TestResultMessage = "";
1124 COContactList ServerDataResult = FakeConnection.GetContactList("2312312-12312312");
1126 EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult);
1127 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1128 EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode);
1129 EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode);
1130 EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage);
1132 EXPECT_EQ("5964589-43543534", ServerDataResult.SyncToken);
1134 EXPECT_EQ(1, ServerDataResult.ListData.size());
1136 EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[0].Location);
1137 EXPECT_EQ(ContactFile3, ServerDataResult.ListData[0].Data);
1141 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Invalid_Permissions){
1143 std::string ServerAddress1 = "gibberish.invalid";
1144 std::string ServerUser1 = "user";
1145 std::string ServerPass1 = "pass";
1147 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1148 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1149 FakeConnection.Connect(false);
1151 COContactList ContactListSetup;
1152 ContactListSetup.SyncToken = "";
1154 FakeConnection.TestContactList = ContactListSetup;
1155 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
1156 FakeConnection.TestEntityTag = "";
1157 FakeConnection.TestResultCode = 403;
1158 FakeConnection.TestSessionCode = 22;
1159 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
1161 COContactList ServerDataResult = FakeConnection.GetContactList("");
1163 EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult);
1164 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1165 EXPECT_EQ(403, ServerDataResult.ServerResponse.ResultCode);
1166 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1167 EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ServerResponse.ResultMessage);
1169 EXPECT_EQ(0, ServerDataResult.ListData.size());
1173 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Missing_Resource){
1175 std::string ServerAddress1 = "gibberish.invalid";
1176 std::string ServerUser1 = "user";
1177 std::string ServerPass1 = "pass";
1179 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1180 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1181 FakeConnection.Connect(false);
1183 COContactList ContactListSetup;
1184 ContactListSetup.SyncToken = "";
1186 FakeConnection.TestContactList = ContactListSetup;
1187 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
1188 FakeConnection.TestEntityTag = "";
1189 FakeConnection.TestResultCode = 404;
1190 FakeConnection.TestSessionCode = 22;
1191 FakeConnection.TestResultMessage = "The resource could not be found.";
1193 COContactList ServerDataResult = FakeConnection.GetContactList("");
1195 EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult);
1196 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1197 EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode);
1198 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1199 EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage);
1201 EXPECT_EQ(0, ServerDataResult.ListData.size());
1205 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_No_Connection){
1207 std::string ServerAddress1 = "gibberish.invalid";
1208 std::string ServerUser1 = "user";
1209 std::string ServerPass1 = "pass";
1211 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1212 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1213 FakeConnection.Connect(false);
1215 COContactList ContactListSetup;
1216 ContactListSetup.SyncToken = "";
1218 FakeConnection.TestContactList = ContactListSetup;
1219 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
1220 FakeConnection.TestEntityTag = "";
1221 FakeConnection.TestResultCode = 404;
1222 FakeConnection.TestSessionCode = 22;
1223 FakeConnection.TestResultMessage = "The resource could not be found.";
1225 COContactList ServerDataResult = FakeConnection.GetContactList("");
1227 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.ServerResponse.RequestResult);
1228 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1229 EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode);
1230 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1231 EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage);
1233 EXPECT_EQ(0, ServerDataResult.ListData.size());
1237 TEST(CardDAV, Use_Fake_To_Simulate_A_Wait_For_A_Completed_Task){
1239 std::string ServerAddress1 = "gibberish.invalid";
1240 std::string ServerUser1 = "user";
1241 std::string ServerPass1 = "pass";
1243 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1244 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1245 FakeConnection.Connect(false);
1246 FakeConnection.ResultTaskCompleted = false;
1248 while (!FakeConnection.IsTaskCompleted()){
1250 std::this_thread::sleep_for(std::chrono::milliseconds(250));
1251 FakeConnection.ResultTaskCompleted = true;
1255 EXPECT_TRUE(FakeConnection.ResultTaskCompleted);