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 EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
45 EXPECT_EQ(8080, FakeConnection1.GetServerPort());
46 EXPECT_EQ("user", FakeConnection1.GetServerUser());
47 EXPECT_EQ("pass", FakeConnection1.GetServerPass());
48 EXPECT_EQ(true, FakeConnection1.GetServerSSL());
49 EXPECT_EQ(true, FakeConnection1.GetTestMode());
51 EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
52 EXPECT_EQ(8800, FakeConnection2.GetServerPort());
53 EXPECT_EQ("user2", FakeConnection2.GetServerUser());
54 EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
55 EXPECT_EQ(true, FakeConnection2.GetServerSSL());
56 EXPECT_EQ(true, FakeConnection2.GetTestMode());
58 EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
59 EXPECT_EQ(8008, FakeConnection3.GetServerPort());
60 EXPECT_EQ("user3", FakeConnection3.GetServerUser());
61 EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
62 EXPECT_EQ(false, FakeConnection3.GetServerSSL());
63 EXPECT_EQ(true, FakeConnection3.GetTestMode());
67 TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_False){
69 std::string ServerAddress1 = "gibberish.invalid";
70 std::string ServerUser1 = "user";
71 std::string ServerPass1 = "pass";
72 std::string ServerPrefix1 = "/prefix";
73 std::string ServerAccount1 = "Account1";
75 std::string ServerAddress2 = "gibberish2.invalid";
76 std::string ServerUser2 = "user2";
77 std::string ServerPass2 = "pass2";
78 std::string ServerPrefix2 = "/prefix2";
79 std::string ServerAccount2 = "Account2";
81 std::string ServerAddress3 = "gibberish3.invalid";
82 std::string ServerUser3 = "user3";
83 std::string ServerPass3 = "pass3";
84 std::string ServerPrefix3 = "/prefix3";
85 std::string ServerAccount3 = "Account3";
87 FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
88 FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true, "/prefix2", "Account2");
89 FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false, "/prefix3", "Account3");
91 EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
92 EXPECT_EQ(8080, FakeConnection1.GetServerPort());
93 EXPECT_EQ("user", FakeConnection1.GetServerUser());
94 EXPECT_EQ("pass", FakeConnection1.GetServerPass());
95 EXPECT_EQ(true, FakeConnection1.GetServerSSL());
96 EXPECT_EQ(false, FakeConnection1.GetTestMode());
97 EXPECT_EQ("/prefix", FakeConnection1.GetServerPrefix());
98 EXPECT_EQ("Account1", FakeConnection1.GetServerAccount());
100 EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
101 EXPECT_EQ(8800, FakeConnection2.GetServerPort());
102 EXPECT_EQ("user2", FakeConnection2.GetServerUser());
103 EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
104 EXPECT_EQ(true, FakeConnection2.GetServerSSL());
105 EXPECT_EQ(false, FakeConnection2.GetTestMode());
106 EXPECT_EQ("/prefix2", FakeConnection2.GetServerPrefix());
107 EXPECT_EQ("Account2", FakeConnection2.GetServerAccount());
109 EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
110 EXPECT_EQ(8008, FakeConnection3.GetServerPort());
111 EXPECT_EQ("user3", FakeConnection3.GetServerUser());
112 EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
113 EXPECT_EQ(false, FakeConnection3.GetServerSSL());
114 EXPECT_EQ(false, FakeConnection3.GetTestMode());
115 EXPECT_EQ("/prefix3", FakeConnection3.GetServerPrefix());
116 EXPECT_EQ("Account3", FakeConnection3.GetServerAccount());
120 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Success){
122 std::string ServerAddress1 = "gibberish.invalid";
123 std::string ServerUser1 = "user";
124 std::string ServerPass1 = "pass";
126 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
127 FakeConnection.ResultStatus = COCONNECT_OK;
129 EXPECT_EQ(COCONNECT_OK, FakeConnection.Connect(false));
133 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_InvalidAddress){
135 std::string ServerAddress1 = "gibberish.invalid";
136 std::string ServerUser1 = "user";
137 std::string ServerPass1 = "pass";
139 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
140 FakeConnection.ResultStatus = COCONNECT_INVALID;
142 EXPECT_EQ(COCONNECT_INVALID, FakeConnection.Connect(false));
146 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Timeout){
148 std::string ServerAddress1 = "gibberish.invalid";
149 std::string ServerUser1 = "user";
150 std::string ServerPass1 = "pass";
152 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
153 FakeConnection.ResultStatus = COCONNECT_TIMEOUT;
155 EXPECT_EQ(COCONNECT_TIMEOUT, FakeConnection.Connect(false));
159 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Authentication_Failure){
161 std::string ServerAddress1 = "gibberish.invalid";
162 std::string ServerUser1 = "user";
163 std::string ServerPass1 = "pass";
165 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
166 FakeConnection.ResultStatus = COCONNECT_AUTHFAIL;
168 EXPECT_EQ(COCONNECT_AUTHFAIL, FakeConnection.Connect(false));
172 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Able_To_Login){
174 std::string ServerAddress1 = "gibberish.invalid";
175 std::string ServerUser1 = "user";
176 std::string ServerPass1 = "pass";
178 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
179 FakeConnection.ResultAuthPassed = true;
180 FakeConnection.Connect(false);
182 EXPECT_EQ(true, FakeConnection.AbleToLogin());
186 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Unable_To_Login){
188 std::string ServerAddress1 = "gibberish.invalid";
189 std::string ServerUser1 = "user";
190 std::string ServerPass1 = "pass";
192 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
193 FakeConnection.ResultAuthPassed = false;
194 FakeConnection.Connect(false);
196 EXPECT_EQ(false, FakeConnection.AbleToLogin());
200 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Can_Do_Processing){
202 std::string ServerAddress1 = "gibberish.invalid";
203 std::string ServerUser1 = "user";
204 std::string ServerPass1 = "pass";
206 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
207 FakeConnection.ResultCanProcess = true;
208 FakeConnection.Connect(false);
210 EXPECT_EQ(true, FakeConnection.CanDoProcessing());
214 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Supports_SSL){
216 std::string ServerAddress1 = "gibberish.invalid";
217 std::string ServerUser1 = "user";
218 std::string ServerPass1 = "pass";
220 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
221 FakeConnection.ResultSSLStatus = true;
222 FakeConnection.Connect(false);
224 EXPECT_EQ(true, FakeConnection.CanDoSSL());
228 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Does_Not_Support_SSL){
230 std::string ServerAddress1 = "gibberish.invalid";
231 std::string ServerUser1 = "user";
232 std::string ServerPass1 = "pass";
234 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
235 FakeConnection.ResultSSLStatus = false;
236 FakeConnection.Connect(false);
238 EXPECT_EQ(false, FakeConnection.CanDoSSL());
242 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Valid_SSL_Certificate_Data){
244 std::string ServerAddress1 = "gibberish.invalid";
245 std::string ServerUser1 = "user";
246 std::string ServerPass1 = "pass";
248 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
249 FakeConnection.ResultSSLVerified = COSSL_VERIFIED;
250 FakeConnection.Connect(false);
252 EXPECT_EQ(COSSL_VERIFIED, FakeConnection.SSLVerify());
256 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Invalid_SSL_Certificate_Data){
258 std::string ServerAddress1 = "gibberish.invalid";
259 std::string ServerUser1 = "user";
260 std::string ServerPass1 = "pass";
262 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
263 FakeConnection.ResultSSLVerified = COSSL_UNABLETOVERIFY;
264 FakeConnection.ResultStatus = COCONNECT_SSLFAIL;
266 EXPECT_EQ(COCONNECT_SSLFAIL, FakeConnection.Connect(false));
267 EXPECT_EQ(COSSL_UNABLETOVERIFY, FakeConnection.SSLVerify());
271 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_User_Verified_SSL_Cerficiate_Data){
273 std::string ServerAddress1 = "gibberish.invalid";
274 std::string ServerUser1 = "user";
275 std::string ServerPass1 = "pass";
277 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
278 FakeConnection.ResultSSLVerified = COSSL_VERIFIED_USER;
279 FakeConnection.Connect(false);
281 EXPECT_EQ(COSSL_VERIFIED_USER, FakeConnection.SSLVerify());
285 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_SSL_Return_Not_Applicable_SSL_Result){
287 std::string ServerAddress1 = "gibberish.invalid";
288 std::string ServerUser1 = "user";
289 std::string ServerPass1 = "pass";
291 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, false);
292 FakeConnection.ResultSSLVerified = COSSL_NOTAPPLICABLE;
293 FakeConnection.Connect(false);
295 EXPECT_EQ(COSSL_NOTAPPLICABLE, FakeConnection.SSLVerify());
299 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Valid_Response){
301 std::string ServerAddress1 = "gibberish.invalid";
302 std::string ServerUser1 = "user";
303 std::string ServerPass1 = "pass";
305 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
306 FakeConnection.ResultValidResponse = true;
307 FakeConnection.Connect(false);
309 EXPECT_EQ(true, FakeConnection.HasValidResponse());
313 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Invalid_Response){
315 std::string ServerAddress1 = "gibberish.invalid";
316 std::string ServerUser1 = "user";
317 std::string ServerPass1 = "pass";
319 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
320 FakeConnection.ResultValidResponse = false;
321 FakeConnection.Connect(false);
323 EXPECT_EQ(false, FakeConnection.HasValidResponse());
327 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Uses_A_Self_Signed_SSL_Certificate){
329 std::string ServerAddress1 = "gibberish.invalid";
330 std::string ServerUser1 = "user";
331 std::string ServerPass1 = "pass";
333 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
334 FakeConnection.ResultSelfSigned = true;
335 FakeConnection.Connect(false);
337 EXPECT_EQ(true, FakeConnection.IsSelfSigned());
341 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_A_Self_Signed_SSL_Certificate){
343 std::string ServerAddress1 = "gibberish.invalid";
344 std::string ServerUser1 = "user";
345 std::string ServerPass1 = "pass";
347 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
348 FakeConnection.ResultSelfSigned = false;
349 FakeConnection.Connect(false);
351 EXPECT_EQ(false, FakeConnection.IsSelfSigned());
355 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_A){
357 std::string ServerAddress1 = "gibberish.invalid";
358 std::string ServerUser1 = "user";
359 std::string ServerPass1 = "pass";
361 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
362 FakeConnection.ResultServerPrefix = "/prefix/test/a";
363 FakeConnection.Connect(false);
365 EXPECT_EQ("/prefix/test/a", FakeConnection.GetDefaultPrefix());
369 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_B){
371 std::string ServerAddress1 = "gibberish.invalid";
372 std::string ServerUser1 = "user";
373 std::string ServerPass1 = "pass";
375 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
376 FakeConnection.ResultServerPrefix = "/prefix/test/b";
377 FakeConnection.Connect(false);
379 EXPECT_EQ("/prefix/test/b", FakeConnection.GetDefaultPrefix());
383 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully){
385 std::string ServerAddress1 = "gibberish.invalid";
386 std::string ServerUser1 = "user";
387 std::string ServerPass1 = "pass";
389 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
390 FakeConnection.ResultServerPrefix = "/prefix/test/b";
391 FakeConnection.Connect(false);
393 std::string ContactFile =
396 "UID:84q2ioj13jofiujqwr\n"
401 FakeConnection.TestRequestResult = COREQUEST_OK;
402 FakeConnection.TestEntityTag = "4324svafhuiaffsdhui";
403 FakeConnection.TestResultCode = 201;
404 FakeConnection.TestSessionCode = 0;
405 FakeConnection.TestResultMessage = "";
407 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
409 EXPECT_EQ(COREQUEST_OK, AddContactResult.RequestResult);
410 EXPECT_EQ("4324svafhuiaffsdhui", AddContactResult.EntityTag);
411 EXPECT_EQ(201, AddContactResult.ResultCode);
412 EXPECT_EQ(0, AddContactResult.SessionCode);
413 EXPECT_EQ("", AddContactResult.ResultMessage);
417 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Permissions){
419 std::string ServerAddress1 = "gibberish.invalid";
420 std::string ServerUser1 = "user";
421 std::string ServerPass1 = "pass";
423 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
424 FakeConnection.ResultServerPrefix = "/prefix/test/b";
425 FakeConnection.Connect(false);
427 std::string ContactFile =
430 "UID:84q2ioj13jofiujqwr\n"
435 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
436 FakeConnection.TestEntityTag = "";
437 FakeConnection.TestResultCode = 403;
438 FakeConnection.TestSessionCode = 22;
439 FakeConnection.TestResultMessage = "You do not have permission to add this resource.";
441 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
443 EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult);
444 EXPECT_EQ("", AddContactResult.EntityTag);
445 EXPECT_EQ(403, AddContactResult.ResultCode);
446 EXPECT_EQ(22, AddContactResult.SessionCode);
447 EXPECT_EQ("You do not have permission to add this resource.", AddContactResult.ResultMessage);
451 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Invalid_Path){
453 std::string ServerAddress1 = "gibberish.invalid";
454 std::string ServerUser1 = "user";
455 std::string ServerPass1 = "pass";
457 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
458 FakeConnection.ResultServerPrefix = "/prefix/test/b";
459 FakeConnection.Connect(false);
461 std::string ContactFile =
464 "UID:84q2ioj13jofiujqwr\n"
469 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
470 FakeConnection.TestEntityTag = "";
471 FakeConnection.TestResultCode = 404;
472 FakeConnection.TestSessionCode = 22;
473 FakeConnection.TestResultMessage = "The location cannot be found.";
475 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
477 EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult);
478 EXPECT_EQ("", AddContactResult.EntityTag);
479 EXPECT_EQ(404, AddContactResult.ResultCode);
480 EXPECT_EQ(22, AddContactResult.SessionCode);
481 EXPECT_EQ("The location cannot be found.", AddContactResult.ResultMessage);
485 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_No_Connection){
487 std::string ServerAddress1 = "gibberish.invalid";
488 std::string ServerUser1 = "user";
489 std::string ServerPass1 = "pass";
491 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
492 FakeConnection.ResultServerPrefix = "/prefix/test/b";
493 FakeConnection.Connect(false);
495 std::string ContactFile =
498 "UID:84q2ioj13jofiujqwr\n"
503 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
504 FakeConnection.TestEntityTag = "";
505 FakeConnection.TestResultCode = 0;
506 FakeConnection.TestSessionCode = 0;
507 FakeConnection.TestResultMessage = "";
509 COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
511 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, AddContactResult.RequestResult);
512 EXPECT_EQ("", AddContactResult.EntityTag);
513 EXPECT_EQ(0, AddContactResult.ResultCode);
514 EXPECT_EQ(0, AddContactResult.SessionCode);
515 EXPECT_EQ("", AddContactResult.ResultMessage);
519 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Edits_A_Server_Contact){
521 std::string ServerAddress1 = "gibberish.invalid";
522 std::string ServerUser1 = "user";
523 std::string ServerPass1 = "pass";
525 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
526 FakeConnection.ResultServerPrefix = "/prefix/test/b";
527 FakeConnection.Connect(false);
529 std::string ContactFile =
532 "UID:84q2ioj13jofiujqwrAAA\n"
537 FakeConnection.TestRequestResult = COREQUEST_OK;
538 FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
539 FakeConnection.TestResultCode = 200;
540 FakeConnection.TestSessionCode = 0;
541 FakeConnection.TestResultMessage = "";
543 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
545 EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult);
546 EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EditContactResult.EntityTag);
547 EXPECT_EQ(200, EditContactResult.ResultCode);
548 EXPECT_EQ(0, EditContactResult.SessionCode);
549 EXPECT_EQ("", EditContactResult.ResultMessage);
551 FakeConnection.TestRequestResult = COREQUEST_OK;
552 FakeConnection.TestEntityTag = "asf84sa484saf614as64asvada4s6fas";
553 FakeConnection.TestResultCode = 204;
554 FakeConnection.TestSessionCode = 0;
555 FakeConnection.TestResultMessage = "";
557 EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
559 EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult);
560 EXPECT_EQ("asf84sa484saf614as64asvada4s6fas", EditContactResult.EntityTag);
561 EXPECT_EQ(204, EditContactResult.ResultCode);
562 EXPECT_EQ(0, EditContactResult.SessionCode);
563 EXPECT_EQ("", EditContactResult.ResultMessage);
567 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Permissions){
569 std::string ServerAddress1 = "gibberish.invalid";
570 std::string ServerUser1 = "user";
571 std::string ServerPass1 = "pass";
573 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
574 FakeConnection.ResultServerPrefix = "/prefix/test/b";
575 FakeConnection.Connect(false);
577 std::string ContactFile =
580 "UID:84q2ioj13jofiujqwrAAA\n"
585 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
586 FakeConnection.TestEntityTag = "";
587 FakeConnection.TestResultCode = 403;
588 FakeConnection.TestSessionCode = 22;
589 FakeConnection.TestResultMessage = "You do not have permission to add this resource.";
591 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
593 EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult);
594 EXPECT_EQ("", EditContactResult.EntityTag);
595 EXPECT_EQ(403, EditContactResult.ResultCode);
596 EXPECT_EQ(22, EditContactResult.SessionCode);
597 EXPECT_EQ("You do not have permission to add this resource.", EditContactResult.ResultMessage);
601 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Location){
603 std::string ServerAddress1 = "gibberish.invalid";
604 std::string ServerUser1 = "user";
605 std::string ServerPass1 = "pass";
607 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
608 FakeConnection.ResultServerPrefix = "/prefix/test/b";
609 FakeConnection.Connect(false);
611 std::string ContactFile =
614 "UID:84q2ioj13jofiujqwrAAA\n"
619 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
620 FakeConnection.TestEntityTag = "";
621 FakeConnection.TestResultCode = 404;
622 FakeConnection.TestSessionCode = 22;
623 FakeConnection.TestResultMessage = "The resource could not be found.";
625 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
627 EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult);
628 EXPECT_EQ("", EditContactResult.EntityTag);
629 EXPECT_EQ(404, EditContactResult.ResultCode);
630 EXPECT_EQ(22, EditContactResult.SessionCode);
631 EXPECT_EQ("The resource could not be found.", EditContactResult.ResultMessage);
635 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_No_Connection){
637 std::string ServerAddress1 = "gibberish.invalid";
638 std::string ServerUser1 = "user";
639 std::string ServerPass1 = "pass";
641 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
642 FakeConnection.ResultServerPrefix = "/prefix/test/b";
643 FakeConnection.Connect(false);
645 std::string ContactFile =
648 "UID:84q2ioj13jofiujqwrAAA\n"
653 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
654 FakeConnection.TestEntityTag = "";
655 FakeConnection.TestResultCode = 0;
656 FakeConnection.TestSessionCode = 0;
657 FakeConnection.TestResultMessage = "";
659 COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
661 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EditContactResult.RequestResult);
662 EXPECT_EQ("", EditContactResult.EntityTag);
663 EXPECT_EQ(0, EditContactResult.ResultCode);
664 EXPECT_EQ(0, EditContactResult.SessionCode);
665 EXPECT_EQ("", EditContactResult.ResultMessage);
669 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Deletes_A_Server_Contact){
671 std::string ServerAddress1 = "gibberish.invalid";
672 std::string ServerUser1 = "user";
673 std::string ServerPass1 = "pass";
675 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
676 FakeConnection.ResultServerPrefix = "/prefix/test/b";
677 FakeConnection.Connect(false);
679 FakeConnection.TestRequestResult = COREQUEST_OK;
680 FakeConnection.TestEntityTag = "";
681 FakeConnection.TestResultCode = 200;
682 FakeConnection.TestSessionCode = 0;
683 FakeConnection.TestResultMessage = "";
685 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
687 EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult);
688 EXPECT_EQ("", DeleteContactResult.EntityTag);
689 EXPECT_EQ(200, DeleteContactResult.ResultCode);
690 EXPECT_EQ(0, DeleteContactResult.SessionCode);
691 EXPECT_EQ("", DeleteContactResult.ResultMessage);
693 FakeConnection.TestRequestResult = COREQUEST_OK;
694 FakeConnection.TestEntityTag = "";
695 FakeConnection.TestResultCode = 204;
696 FakeConnection.TestSessionCode = 0;
697 FakeConnection.TestResultMessage = "";
699 DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
701 EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult);
702 EXPECT_EQ("", DeleteContactResult.EntityTag);
703 EXPECT_EQ(204, DeleteContactResult.ResultCode);
704 EXPECT_EQ(0, DeleteContactResult.SessionCode);
705 EXPECT_EQ("", DeleteContactResult.ResultMessage);
709 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Invalid_Permissions){
711 std::string ServerAddress1 = "gibberish.invalid";
712 std::string ServerUser1 = "user";
713 std::string ServerPass1 = "pass";
715 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
716 FakeConnection.ResultServerPrefix = "/prefix/test/b";
717 FakeConnection.Connect(false);
719 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
720 FakeConnection.TestEntityTag = "";
721 FakeConnection.TestResultCode = 403;
722 FakeConnection.TestSessionCode = 22;
723 FakeConnection.TestResultMessage = "You do not have permission to delete this resource.";
725 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
727 EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult);
728 EXPECT_EQ("", DeleteContactResult.EntityTag);
729 EXPECT_EQ(403, DeleteContactResult.ResultCode);
730 EXPECT_EQ(22, DeleteContactResult.SessionCode);
731 EXPECT_EQ("You do not have permission to delete this resource.", DeleteContactResult.ResultMessage);
735 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Missing_Location){
737 std::string ServerAddress1 = "gibberish.invalid";
738 std::string ServerUser1 = "user";
739 std::string ServerPass1 = "pass";
741 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
742 FakeConnection.ResultServerPrefix = "/prefix/test/b";
743 FakeConnection.Connect(false);
745 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
746 FakeConnection.TestEntityTag = "";
747 FakeConnection.TestResultCode = 404;
748 FakeConnection.TestSessionCode = 22;
749 FakeConnection.TestResultMessage = "The resource could not be found.";
751 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
753 EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult);
754 EXPECT_EQ("", DeleteContactResult.EntityTag);
755 EXPECT_EQ(404, DeleteContactResult.ResultCode);
756 EXPECT_EQ(22, DeleteContactResult.SessionCode);
757 EXPECT_EQ("The resource could not be found.", DeleteContactResult.ResultMessage);
761 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_No_Connection){
763 std::string ServerAddress1 = "gibberish.invalid";
764 std::string ServerUser1 = "user";
765 std::string ServerPass1 = "pass";
767 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
768 FakeConnection.ResultServerPrefix = "/prefix/test/b";
769 FakeConnection.Connect(false);
771 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
772 FakeConnection.TestEntityTag = "";
773 FakeConnection.TestResultCode = 0;
774 FakeConnection.TestSessionCode = 0;
775 FakeConnection.TestResultMessage = "";
777 COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
779 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, DeleteContactResult.RequestResult);
780 EXPECT_EQ("", DeleteContactResult.EntityTag);
781 EXPECT_EQ(0, DeleteContactResult.ResultCode);
782 EXPECT_EQ(0, DeleteContactResult.SessionCode);
783 EXPECT_EQ("", DeleteContactResult.ResultMessage);
787 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Entity_Tag_Value){
789 std::string ServerAddress1 = "gibberish.invalid";
790 std::string ServerUser1 = "user";
791 std::string ServerPass1 = "pass";
793 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
794 FakeConnection.ResultServerPrefix = "/prefix/test/b";
795 FakeConnection.Connect(false);
797 FakeConnection.TestRequestResult = COREQUEST_OK;
798 FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
799 FakeConnection.TestResultCode = 200;
800 FakeConnection.TestSessionCode = 0;
801 FakeConnection.TestResultMessage = "";
803 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
805 EXPECT_EQ(COREQUEST_OK, EntityTagResult.RequestResult);
806 EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EntityTagResult.EntityTag);
807 EXPECT_EQ(200, EntityTagResult.ResultCode);
808 EXPECT_EQ(0, EntityTagResult.SessionCode);
809 EXPECT_EQ("", EntityTagResult.ResultMessage);
813 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Invalid_Permissions){
815 std::string ServerAddress1 = "gibberish.invalid";
816 std::string ServerUser1 = "user";
817 std::string ServerPass1 = "pass";
819 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
820 FakeConnection.ResultServerPrefix = "/prefix/test/b";
821 FakeConnection.Connect(false);
823 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
824 FakeConnection.TestEntityTag = "";
825 FakeConnection.TestResultCode = 403;
826 FakeConnection.TestSessionCode = 22;
827 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
829 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
831 EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult);
832 EXPECT_EQ("", EntityTagResult.EntityTag);
833 EXPECT_EQ(403, EntityTagResult.ResultCode);
834 EXPECT_EQ(22, EntityTagResult.SessionCode);
835 EXPECT_EQ("You do not have permission to access this resource.", EntityTagResult.ResultMessage);
839 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Missing_Resource){
841 std::string ServerAddress1 = "gibberish.invalid";
842 std::string ServerUser1 = "user";
843 std::string ServerPass1 = "pass";
845 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
846 FakeConnection.ResultServerPrefix = "/prefix/test/b";
847 FakeConnection.Connect(false);
849 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
850 FakeConnection.TestEntityTag = "";
851 FakeConnection.TestResultCode = 404;
852 FakeConnection.TestSessionCode = 22;
853 FakeConnection.TestResultMessage = "The resource cannot be found.";
855 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
857 EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult);
858 EXPECT_EQ("", EntityTagResult.EntityTag);
859 EXPECT_EQ(404, EntityTagResult.ResultCode);
860 EXPECT_EQ(22, EntityTagResult.SessionCode);
861 EXPECT_EQ("The resource cannot be found.", EntityTagResult.ResultMessage);
865 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_No_Connection){
867 std::string ServerAddress1 = "gibberish.invalid";
868 std::string ServerUser1 = "user";
869 std::string ServerPass1 = "pass";
871 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
872 FakeConnection.ResultServerPrefix = "/prefix/test/b";
873 FakeConnection.Connect(false);
875 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
876 FakeConnection.TestEntityTag = "";
877 FakeConnection.TestResultCode = 0;
878 FakeConnection.TestSessionCode = 0;
879 FakeConnection.TestResultMessage = "";
881 COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
883 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EntityTagResult.RequestResult);
884 EXPECT_EQ("", EntityTagResult.EntityTag);
885 EXPECT_EQ(0, EntityTagResult.ResultCode);
886 EXPECT_EQ(0, EntityTagResult.SessionCode);
887 EXPECT_EQ("", EntityTagResult.ResultMessage);
891 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Contact_Data){
893 std::string ServerAddress1 = "gibberish.invalid";
894 std::string ServerUser1 = "user";
895 std::string ServerPass1 = "pass";
897 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
898 FakeConnection.ResultServerPrefix = "/prefix/test/b";
899 FakeConnection.Connect(false);
901 std::string ContactFile =
904 "UID:84q2ioj13jofiujqwrAAA\n"
909 FakeConnection.TestRequestResult = COREQUEST_OK;
910 FakeConnection.TestEntityTag = "";
911 FakeConnection.TestResultCode = 200;
912 FakeConnection.TestSessionCode = 0;
913 FakeConnection.TestResultMessage = ContactFile;
915 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
917 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
918 EXPECT_EQ("", ServerDataResult.EntityTag);
919 EXPECT_EQ(200, ServerDataResult.ResultCode);
920 EXPECT_EQ(0, ServerDataResult.SessionCode);
921 EXPECT_EQ(ContactFile, ServerDataResult.ResultMessage);
925 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Invalid_Permissions){
927 std::string ServerAddress1 = "gibberish.invalid";
928 std::string ServerUser1 = "user";
929 std::string ServerPass1 = "pass";
931 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
932 FakeConnection.ResultServerPrefix = "/prefix/test/b";
933 FakeConnection.Connect(false);
935 FakeConnection.TestRequestResult = COREQUEST_OK;
936 FakeConnection.TestEntityTag = "";
937 FakeConnection.TestResultCode = 403;
938 FakeConnection.TestSessionCode = 22;
939 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
941 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
943 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
944 EXPECT_EQ("", ServerDataResult.EntityTag);
945 EXPECT_EQ(403, ServerDataResult.ResultCode);
946 EXPECT_EQ(22, ServerDataResult.SessionCode);
947 EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ResultMessage);
951 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Missing_Resource){
953 std::string ServerAddress1 = "gibberish.invalid";
954 std::string ServerUser1 = "user";
955 std::string ServerPass1 = "pass";
957 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
958 FakeConnection.ResultServerPrefix = "/prefix/test/b";
959 FakeConnection.Connect(false);
961 FakeConnection.TestRequestResult = COREQUEST_OK;
962 FakeConnection.TestEntityTag = "";
963 FakeConnection.TestResultCode = 404;
964 FakeConnection.TestSessionCode = 22;
965 FakeConnection.TestResultMessage = "The resource could not be found.";
967 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
969 EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult);
970 EXPECT_EQ("", ServerDataResult.EntityTag);
971 EXPECT_EQ(404, ServerDataResult.ResultCode);
972 EXPECT_EQ(22, ServerDataResult.SessionCode);
973 EXPECT_EQ("The resource could not be found.", ServerDataResult.ResultMessage);
977 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Contact_Data_Due_To_No_Connection){
979 std::string ServerAddress1 = "gibberish.invalid";
980 std::string ServerUser1 = "user";
981 std::string ServerPass1 = "pass";
983 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
984 FakeConnection.ResultServerPrefix = "/prefix/test/b";
985 FakeConnection.Connect(false);
987 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
988 FakeConnection.TestEntityTag = "";
989 FakeConnection.TestResultCode = 0;
990 FakeConnection.TestSessionCode = 0;
991 FakeConnection.TestResultMessage = "";
993 COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
995 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.RequestResult);
996 EXPECT_EQ("", ServerDataResult.EntityTag);
997 EXPECT_EQ(0, ServerDataResult.ResultCode);
998 EXPECT_EQ(0, ServerDataResult.SessionCode);
999 EXPECT_EQ("", ServerDataResult.ResultMessage);
1003 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Full_Server_Contact_List){
1005 std::string ServerAddress1 = "gibberish.invalid";
1006 std::string ServerUser1 = "user";
1007 std::string ServerPass1 = "pass";
1009 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1010 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1011 FakeConnection.Connect(false);
1013 std::string ContactFile1 =
1016 "UID:84q2ioj13jofiujqwrAAA-1\n"
1018 "FN:The Meep Moop\n"
1021 std::string ContactFile2 =
1024 "UID:84q2ioj13jofiujqwrAAA-2\n"
1026 "FN:The Meep Moop\n"
1029 std::string ContactFile3 =
1032 "UID:84q2ioj13jofiujqwrAAA-3\n"
1034 "FN:The Meep Moop\n"
1037 COContactList ContactListSetup;
1038 COContactData ContactPerson;
1040 ContactPerson.Location = "/location1.vcf";
1041 ContactPerson.Data = ContactFile1;
1042 ContactListSetup.ListData.push_back(ContactPerson);
1044 ContactPerson.Location = "/location2.vcf";
1045 ContactPerson.Data = ContactFile2;
1046 ContactListSetup.ListData.push_back(ContactPerson);
1048 ContactPerson.Location = "/location3.vcf";
1049 ContactPerson.Data = ContactFile3;
1050 ContactListSetup.ListData.push_back(ContactPerson);
1051 ContactListSetup.SyncToken = "2312312-12312312";
1053 FakeConnection.TestContactList = ContactListSetup;
1054 FakeConnection.TestRequestResult = COREQUEST_OK;
1055 FakeConnection.TestEntityTag = "";
1056 FakeConnection.TestResultCode = 200;
1057 FakeConnection.TestSessionCode = 0;
1058 FakeConnection.TestResultMessage = "";
1060 COContactList ServerDataResult = FakeConnection.GetContactList("");
1062 EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult);
1063 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1064 EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode);
1065 EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode);
1066 EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage);
1068 EXPECT_EQ("2312312-12312312", ServerDataResult.SyncToken);
1070 EXPECT_EQ(3, ServerDataResult.ListData.size());
1072 EXPECT_EQ("/location1.vcf", ServerDataResult.ListData[0].Location);
1073 EXPECT_EQ(ContactFile1, ServerDataResult.ListData[0].Data);
1075 EXPECT_EQ("/location2.vcf", ServerDataResult.ListData[1].Location);
1076 EXPECT_EQ(ContactFile2, ServerDataResult.ListData[1].Data);
1078 EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[2].Location);
1079 EXPECT_EQ(ContactFile3, ServerDataResult.ListData[2].Data);
1083 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Partial_Server_Contact_List){
1085 std::string ServerAddress1 = "gibberish.invalid";
1086 std::string ServerUser1 = "user";
1087 std::string ServerPass1 = "pass";
1089 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1090 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1091 FakeConnection.Connect(false);
1093 std::string ContactFile3 =
1096 "UID:84q2ioj13jofiujqwrAAA-3\n"
1098 "FN:The Meep Moop\n"
1101 COContactList ContactListSetup;
1102 COContactData ContactPerson;
1104 ContactPerson.Location = "/location3.vcf";
1105 ContactPerson.Data = ContactFile3;
1106 ContactListSetup.ListData.push_back(ContactPerson);
1107 ContactListSetup.SyncToken = "5964589-43543534";
1109 FakeConnection.TestContactList = ContactListSetup;
1110 FakeConnection.TestRequestResult = COREQUEST_OK;
1111 FakeConnection.TestEntityTag = "";
1112 FakeConnection.TestResultCode = 200;
1113 FakeConnection.TestSessionCode = 0;
1114 FakeConnection.TestResultMessage = "";
1116 COContactList ServerDataResult = FakeConnection.GetContactList("2312312-12312312");
1118 EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult);
1119 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1120 EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode);
1121 EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode);
1122 EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage);
1124 EXPECT_EQ("5964589-43543534", ServerDataResult.SyncToken);
1126 EXPECT_EQ(1, ServerDataResult.ListData.size());
1128 EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[0].Location);
1129 EXPECT_EQ(ContactFile3, ServerDataResult.ListData[0].Data);
1133 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Invalid_Permissions){
1135 std::string ServerAddress1 = "gibberish.invalid";
1136 std::string ServerUser1 = "user";
1137 std::string ServerPass1 = "pass";
1139 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1140 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1141 FakeConnection.Connect(false);
1143 COContactList ContactListSetup;
1144 ContactListSetup.SyncToken = "";
1146 FakeConnection.TestContactList = ContactListSetup;
1147 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
1148 FakeConnection.TestEntityTag = "";
1149 FakeConnection.TestResultCode = 403;
1150 FakeConnection.TestSessionCode = 22;
1151 FakeConnection.TestResultMessage = "You do not have permission to access this resource.";
1153 COContactList ServerDataResult = FakeConnection.GetContactList("");
1155 EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult);
1156 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1157 EXPECT_EQ(403, ServerDataResult.ServerResponse.ResultCode);
1158 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1159 EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ServerResponse.ResultMessage);
1161 EXPECT_EQ(0, ServerDataResult.ListData.size());
1165 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Missing_Resource){
1167 std::string ServerAddress1 = "gibberish.invalid";
1168 std::string ServerUser1 = "user";
1169 std::string ServerPass1 = "pass";
1171 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1172 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1173 FakeConnection.Connect(false);
1175 COContactList ContactListSetup;
1176 ContactListSetup.SyncToken = "";
1178 FakeConnection.TestContactList = ContactListSetup;
1179 FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER;
1180 FakeConnection.TestEntityTag = "";
1181 FakeConnection.TestResultCode = 404;
1182 FakeConnection.TestSessionCode = 22;
1183 FakeConnection.TestResultMessage = "The resource could not be found.";
1185 COContactList ServerDataResult = FakeConnection.GetContactList("");
1187 EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult);
1188 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1189 EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode);
1190 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1191 EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage);
1193 EXPECT_EQ(0, ServerDataResult.ListData.size());
1197 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_No_Connection){
1199 std::string ServerAddress1 = "gibberish.invalid";
1200 std::string ServerUser1 = "user";
1201 std::string ServerPass1 = "pass";
1203 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1204 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1205 FakeConnection.Connect(false);
1207 COContactList ContactListSetup;
1208 ContactListSetup.SyncToken = "";
1210 FakeConnection.TestContactList = ContactListSetup;
1211 FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
1212 FakeConnection.TestEntityTag = "";
1213 FakeConnection.TestResultCode = 404;
1214 FakeConnection.TestSessionCode = 22;
1215 FakeConnection.TestResultMessage = "The resource could not be found.";
1217 COContactList ServerDataResult = FakeConnection.GetContactList("");
1219 EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.ServerResponse.RequestResult);
1220 EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag);
1221 EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode);
1222 EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode);
1223 EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage);
1225 EXPECT_EQ(0, ServerDataResult.ListData.size());
1229 TEST(CardDAV, Use_Fake_To_Simulate_A_Wait_For_A_Completed_Task){
1231 std::string ServerAddress1 = "gibberish.invalid";
1232 std::string ServerUser1 = "user";
1233 std::string ServerPass1 = "pass";
1235 FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1236 FakeConnection.ResultServerPrefix = "/prefix/test/b";
1237 FakeConnection.Connect(false);
1238 FakeConnection.ResultTaskCompleted = false;
1240 while (!FakeConnection.IsTaskCompleted()){
1242 std::this_thread::sleep_for(std::chrono::milliseconds(250));
1243 FakeConnection.ResultTaskCompleted = true;
1247 EXPECT_TRUE(FakeConnection.ResultTaskCompleted);