Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.20 release
[xestiaab/.git] / source / tests / xestiaab_carddav.cpp
1 // xestiaab_carddav.h - Xestia Address Book CardDAV Object Unit Tests.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
21 #include <chrono>
22 #include <thread>
24 // TODO: Add tests for the CardDAV object.
26 TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_True){
27         
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";
35         
36         std::string ServerAddress3 = "gibberish3.invalid";
37         std::string ServerUser3 = "user3";
38         std::string ServerPass3 = "pass3";
39         
40         FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
41         FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true);
42         FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false);
43         
44         FakeConnection1.ResultTestMode = true;
45         FakeConnection2.ResultTestMode = true;
46         FakeConnection3.ResultTestMode = true;
47         
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());
69 }
71 TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_False){
72         
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";
84         
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";
90         
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");
94         
95         FakeConnection1.ResultTestMode = false;
96         FakeConnection2.ResultTestMode = false;
97         FakeConnection3.ResultTestMode = false;
98         
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){
129         
130         std::string ServerAddress1 = "gibberish.invalid";
131         std::string ServerUser1 = "user";
132         std::string ServerPass1 = "pass";
133         
134         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
135         FakeConnection.ResultStatus = COCONNECT_OK;
136         
137         EXPECT_EQ(COCONNECT_OK, FakeConnection.Connect(false));
138         
141 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_InvalidAddress){
142         
143         std::string ServerAddress1 = "gibberish.invalid";
144         std::string ServerUser1 = "user";
145         std::string ServerPass1 = "pass";
146         
147         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
148         FakeConnection.ResultStatus = COCONNECT_INVALID;
149         
150         EXPECT_EQ(COCONNECT_INVALID, FakeConnection.Connect(false));
151         
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";
159         
160         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
161         FakeConnection.ResultStatus = COCONNECT_TIMEOUT;
162         
163         EXPECT_EQ(COCONNECT_TIMEOUT, FakeConnection.Connect(false));
164         
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";
172         
173         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
174         FakeConnection.ResultStatus = COCONNECT_AUTHFAIL;
175         
176         EXPECT_EQ(COCONNECT_AUTHFAIL, FakeConnection.Connect(false));
177         
180 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Able_To_Login){
181         
182         std::string ServerAddress1 = "gibberish.invalid";
183         std::string ServerUser1 = "user";
184         std::string ServerPass1 = "pass";
185         
186         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
187         FakeConnection.ResultAuthPassed = true;
188         FakeConnection.Connect(false);
189         
190         EXPECT_EQ(true, FakeConnection.AbleToLogin());
191         
194 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Unable_To_Login){
195         
196         std::string ServerAddress1 = "gibberish.invalid";
197         std::string ServerUser1 = "user";
198         std::string ServerPass1 = "pass";
199         
200         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
201         FakeConnection.ResultAuthPassed = false;
202         FakeConnection.Connect(false);
203         
204         EXPECT_EQ(false, FakeConnection.AbleToLogin());
205         
208 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Can_Do_Processing){
209         
210         std::string ServerAddress1 = "gibberish.invalid";
211         std::string ServerUser1 = "user";
212         std::string ServerPass1 = "pass";
213         
214         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
215         FakeConnection.ResultCanProcess = true;
216         FakeConnection.Connect(false);
217         
218         EXPECT_EQ(true, FakeConnection.CanDoProcessing());
219         
222 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Supports_SSL){
223         
224         std::string ServerAddress1 = "gibberish.invalid";
225         std::string ServerUser1 = "user";
226         std::string ServerPass1 = "pass";
227         
228         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
229         FakeConnection.ResultSSLStatus  = true;
230         FakeConnection.Connect(false);
231         
232         EXPECT_EQ(true, FakeConnection.CanDoSSL());
233         
236 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Does_Not_Support_SSL){
237         
238         std::string ServerAddress1 = "gibberish.invalid";
239         std::string ServerUser1 = "user";
240         std::string ServerPass1 = "pass";
241         
242         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
243         FakeConnection.ResultSSLStatus  = false;
244         FakeConnection.Connect(false);
245         
246         EXPECT_EQ(false, FakeConnection.CanDoSSL());
247         
250 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Valid_SSL_Certificate_Data){
251         
252         std::string ServerAddress1 = "gibberish.invalid";
253         std::string ServerUser1 = "user";
254         std::string ServerPass1 = "pass";
255         
256         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
257         FakeConnection.ResultSSLVerified = COSSL_VERIFIED;
258         FakeConnection.Connect(false);
259         
260         EXPECT_EQ(COSSL_VERIFIED, FakeConnection.SSLVerify());
261         
264 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Invalid_SSL_Certificate_Data){
265         
266         std::string ServerAddress1 = "gibberish.invalid";
267         std::string ServerUser1 = "user";
268         std::string ServerPass1 = "pass";
269         
270         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
271         FakeConnection.ResultSSLVerified = COSSL_UNABLETOVERIFY;
272         FakeConnection.ResultStatus = COCONNECT_SSLFAIL;
273         
274         EXPECT_EQ(COCONNECT_SSLFAIL, FakeConnection.Connect(false));
275         EXPECT_EQ(COSSL_UNABLETOVERIFY, FakeConnection.SSLVerify());
276         
279 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_User_Verified_SSL_Cerficiate_Data){
280         
281         std::string ServerAddress1 = "gibberish.invalid";
282         std::string ServerUser1 = "user";
283         std::string ServerPass1 = "pass";
284         
285         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
286         FakeConnection.ResultSSLVerified = COSSL_VERIFIED_USER;
287         FakeConnection.Connect(false);
288         
289         EXPECT_EQ(COSSL_VERIFIED_USER, FakeConnection.SSLVerify());
290         
293 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_SSL_Return_Not_Applicable_SSL_Result){
294         
295         std::string ServerAddress1 = "gibberish.invalid";
296         std::string ServerUser1 = "user";
297         std::string ServerPass1 = "pass";
298         
299         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, false);
300         FakeConnection.ResultSSLVerified = COSSL_NOTAPPLICABLE;
301         FakeConnection.Connect(false);
302         
303         EXPECT_EQ(COSSL_NOTAPPLICABLE, FakeConnection.SSLVerify());
304         
307 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Valid_Response){
308         
309         std::string ServerAddress1 = "gibberish.invalid";
310         std::string ServerUser1 = "user";
311         std::string ServerPass1 = "pass";
312         
313         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
314         FakeConnection.ResultValidResponse = true;
315         FakeConnection.Connect(false);
316         
317         EXPECT_EQ(true, FakeConnection.HasValidResponse());
318         
321 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Invalid_Response){
322         
323         std::string ServerAddress1 = "gibberish.invalid";
324         std::string ServerUser1 = "user";
325         std::string ServerPass1 = "pass";
326         
327         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
328         FakeConnection.ResultValidResponse = false;
329         FakeConnection.Connect(false);
330         
331         EXPECT_EQ(false, FakeConnection.HasValidResponse());
332         
335 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Uses_A_Self_Signed_SSL_Certificate){
336         
337         std::string ServerAddress1 = "gibberish.invalid";
338         std::string ServerUser1 = "user";
339         std::string ServerPass1 = "pass";
340         
341         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
342         FakeConnection.ResultSelfSigned = true;
343         FakeConnection.Connect(false);
344         
345         EXPECT_EQ(true, FakeConnection.IsSelfSigned());
346         
349 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_A_Self_Signed_SSL_Certificate){
350         
351         std::string ServerAddress1 = "gibberish.invalid";
352         std::string ServerUser1 = "user";
353         std::string ServerPass1 = "pass";
354         
355         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
356         FakeConnection.ResultSelfSigned = false;
357         FakeConnection.Connect(false);
358         
359         EXPECT_EQ(false, FakeConnection.IsSelfSigned());
360         
363 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_A){
364         
365         std::string ServerAddress1 = "gibberish.invalid";
366         std::string ServerUser1 = "user";
367         std::string ServerPass1 = "pass";
368         
369         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
370         FakeConnection.ResultServerPrefix = "/prefix/test/a";
371         FakeConnection.Connect(false);
372         
373         EXPECT_EQ("/prefix/test/a", FakeConnection.GetDefaultPrefix());
374         
377 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_B){
378         
379         std::string ServerAddress1 = "gibberish.invalid";
380         std::string ServerUser1 = "user";
381         std::string ServerPass1 = "pass";
382         
383         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
384         FakeConnection.ResultServerPrefix = "/prefix/test/b";
385         FakeConnection.Connect(false);
386         
387         EXPECT_EQ("/prefix/test/b", FakeConnection.GetDefaultPrefix());
388         
391 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully){
392         
393         std::string ServerAddress1 = "gibberish.invalid";
394         std::string ServerUser1 = "user";
395         std::string ServerPass1 = "pass";
396         
397         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
398         FakeConnection.ResultServerPrefix = "/prefix/test/b";
399         FakeConnection.Connect(false);
400         
401         std::string ContactFile =
402         "BEGIN:VCARD\n"
403         "VERSION:4.0\n"
404         "UID:84q2ioj13jofiujqwr\n"
405         "N:;;Meep;Moop;;\n"
406         "FN:The Meep Moop\n"
407         "END:VCARD";
408         
409         FakeConnection.TestRequestResult = COREQUEST_OK;
410         FakeConnection.TestEntityTag = "4324svafhuiaffsdhui";
411         FakeConnection.TestResultCode = 201;
412         FakeConnection.TestSessionCode = 0;
413         FakeConnection.TestResultMessage = "";
414         
415         COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
416         
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);
422         
425 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Permissions){
426         
427         std::string ServerAddress1 = "gibberish.invalid";
428         std::string ServerUser1 = "user";
429         std::string ServerPass1 = "pass";
430         
431         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
432         FakeConnection.ResultServerPrefix = "/prefix/test/b";
433         FakeConnection.Connect(false);
434         
435         std::string ContactFile =
436         "BEGIN:VCARD\n"
437         "VERSION:4.0\n"
438         "UID:84q2ioj13jofiujqwr\n"
439         "N:;;Meep;Moop;;\n"
440         "FN:The Meep Moop\n"
441         "END:VCARD";
442         
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.";
448         
449         COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
450         
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);
456         
459 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Invalid_Path){
460         
461         std::string ServerAddress1 = "gibberish.invalid";
462         std::string ServerUser1 = "user";
463         std::string ServerPass1 = "pass";
464         
465         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
466         FakeConnection.ResultServerPrefix = "/prefix/test/b";
467         FakeConnection.Connect(false);
468         
469         std::string ContactFile =
470         "BEGIN:VCARD\n"
471         "VERSION:4.0\n"
472         "UID:84q2ioj13jofiujqwr\n"
473         "N:;;Meep;Moop;;\n"
474         "FN:The Meep Moop\n"
475         "END:VCARD";
476         
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.";
482         
483         COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
484         
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);     
490         
493 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_No_Connection){
494         
495         std::string ServerAddress1 = "gibberish.invalid";
496         std::string ServerUser1 = "user";
497         std::string ServerPass1 = "pass";
498         
499         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
500         FakeConnection.ResultServerPrefix = "/prefix/test/b";
501         FakeConnection.Connect(false);
502         
503         std::string ContactFile =
504         "BEGIN:VCARD\n"
505         "VERSION:4.0\n"
506         "UID:84q2ioj13jofiujqwr\n"
507         "N:;;Meep;Moop;;\n"
508         "FN:The Meep Moop\n"
509         "END:VCARD";
510         
511         FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
512         FakeConnection.TestEntityTag = "";
513         FakeConnection.TestResultCode = 0;
514         FakeConnection.TestSessionCode = 0;
515         FakeConnection.TestResultMessage = "";
516         
517         COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
518         
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);  
524         
527 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Edits_A_Server_Contact){
528         
529         std::string ServerAddress1 = "gibberish.invalid";
530         std::string ServerUser1 = "user";
531         std::string ServerPass1 = "pass";
532         
533         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
534         FakeConnection.ResultServerPrefix = "/prefix/test/b";
535         FakeConnection.Connect(false);
536         
537         std::string ContactFile =
538         "BEGIN:VCARD\n"
539         "VERSION:4.0\n"
540         "UID:84q2ioj13jofiujqwrAAA\n"
541         "N:;;Meep;Moop;;\n"
542         "FN:The Meep Moop\n"
543         "END:VCARD";
544         
545         FakeConnection.TestRequestResult = COREQUEST_OK;
546         FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
547         FakeConnection.TestResultCode = 200;
548         FakeConnection.TestSessionCode = 0;
549         FakeConnection.TestResultMessage = "";
550         
551         COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
552         
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){
576         
577         std::string ServerAddress1 = "gibberish.invalid";
578         std::string ServerUser1 = "user";
579         std::string ServerPass1 = "pass";
580         
581         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
582         FakeConnection.ResultServerPrefix = "/prefix/test/b";
583         FakeConnection.Connect(false);
584         
585         std::string ContactFile =
586         "BEGIN:VCARD\n"
587         "VERSION:4.0\n"
588         "UID:84q2ioj13jofiujqwrAAA\n"
589         "N:;;Meep;Moop;;\n"
590         "FN:The Meep Moop\n"
591         "END:VCARD";
592         
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.";
598         
599         COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
600         
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){
610         
611         std::string ServerAddress1 = "gibberish.invalid";
612         std::string ServerUser1 = "user";
613         std::string ServerPass1 = "pass";
614         
615         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
616         FakeConnection.ResultServerPrefix = "/prefix/test/b";
617         FakeConnection.Connect(false);
618         
619         std::string ContactFile =
620         "BEGIN:VCARD\n"
621         "VERSION:4.0\n"
622         "UID:84q2ioj13jofiujqwrAAA\n"
623         "N:;;Meep;Moop;;\n"
624         "FN:The Meep Moop\n"
625         "END:VCARD";
626         
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.";
632         
633         COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
634         
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){
644         
645         std::string ServerAddress1 = "gibberish.invalid";
646         std::string ServerUser1 = "user";
647         std::string ServerPass1 = "pass";
648         
649         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
650         FakeConnection.ResultServerPrefix = "/prefix/test/b";
651         FakeConnection.Connect(false);
652         
653         std::string ContactFile =
654         "BEGIN:VCARD\n"
655         "VERSION:4.0\n"
656         "UID:84q2ioj13jofiujqwrAAA\n"
657         "N:;;Meep;Moop;;\n"
658         "FN:The Meep Moop\n"
659         "END:VCARD";
660         
661         FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
662         FakeConnection.TestEntityTag = "";
663         FakeConnection.TestResultCode = 0;
664         FakeConnection.TestSessionCode = 0;
665         FakeConnection.TestResultMessage = "";
666         
667         COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile);
668         
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){
678         
679         std::string ServerAddress1 = "gibberish.invalid";
680         std::string ServerUser1 = "user";
681         std::string ServerPass1 = "pass";
682         
683         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
684         FakeConnection.ResultServerPrefix = "/prefix/test/b";
685         FakeConnection.Connect(false);
686         
687         FakeConnection.TestRequestResult = COREQUEST_OK;
688         FakeConnection.TestEntityTag = "";
689         FakeConnection.TestResultCode = 200;
690         FakeConnection.TestSessionCode = 0;
691         FakeConnection.TestResultMessage = "";
692         
693         COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
694         
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){
718         
719         std::string ServerAddress1 = "gibberish.invalid";
720         std::string ServerUser1 = "user";
721         std::string ServerPass1 = "pass";
722         
723         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
724         FakeConnection.ResultServerPrefix = "/prefix/test/b";
725         FakeConnection.Connect(false);
726         
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.";
732         
733         COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
734         
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){
744         
745         std::string ServerAddress1 = "gibberish.invalid";
746         std::string ServerUser1 = "user";
747         std::string ServerPass1 = "pass";
748         
749         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
750         FakeConnection.ResultServerPrefix = "/prefix/test/b";
751         FakeConnection.Connect(false);
752         
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.";
758         
759         COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
760         
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){
770         
771         std::string ServerAddress1 = "gibberish.invalid";
772         std::string ServerUser1 = "user";
773         std::string ServerPass1 = "pass";
774         
775         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
776         FakeConnection.ResultServerPrefix = "/prefix/test/b";
777         FakeConnection.Connect(false);
778         
779         FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
780         FakeConnection.TestEntityTag = "";
781         FakeConnection.TestResultCode = 0;
782         FakeConnection.TestSessionCode = 0;
783         FakeConnection.TestResultMessage = "";
784         
785         COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
786         
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){
796         
797         std::string ServerAddress1 = "gibberish.invalid";
798         std::string ServerUser1 = "user";
799         std::string ServerPass1 = "pass";
800         
801         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
802         FakeConnection.ResultServerPrefix = "/prefix/test/b";
803         FakeConnection.Connect(false);
804         
805         FakeConnection.TestRequestResult = COREQUEST_OK;
806         FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf";
807         FakeConnection.TestResultCode = 200;
808         FakeConnection.TestSessionCode = 0;
809         FakeConnection.TestResultMessage = "";
810         
811         COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
812         
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);   
818         
821 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Invalid_Permissions){
822         
823         std::string ServerAddress1 = "gibberish.invalid";
824         std::string ServerUser1 = "user";
825         std::string ServerPass1 = "pass";
826         
827         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
828         FakeConnection.ResultServerPrefix = "/prefix/test/b";
829         FakeConnection.Connect(false);
830         
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.";
836         
837         COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
838         
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);        
844         
847 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Missing_Resource){
848         
849         std::string ServerAddress1 = "gibberish.invalid";
850         std::string ServerUser1 = "user";
851         std::string ServerPass1 = "pass";
852         
853         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
854         FakeConnection.ResultServerPrefix = "/prefix/test/b";
855         FakeConnection.Connect(false);
856         
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.";
862         
863         COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
864         
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);      
870         
873 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_No_Connection){
874         
875         std::string ServerAddress1 = "gibberish.invalid";
876         std::string ServerUser1 = "user";
877         std::string ServerPass1 = "pass";
878         
879         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
880         FakeConnection.ResultServerPrefix = "/prefix/test/b";
881         FakeConnection.Connect(false);
882         
883         FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
884         FakeConnection.TestEntityTag = "";
885         FakeConnection.TestResultCode = 0;
886         FakeConnection.TestSessionCode = 0;
887         FakeConnection.TestResultMessage = "";
888         
889         COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf");
890         
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);
896         
899 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Contact_Data){
900         
901         std::string ServerAddress1 = "gibberish.invalid";
902         std::string ServerUser1 = "user";
903         std::string ServerPass1 = "pass";
904         
905         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
906         FakeConnection.ResultServerPrefix = "/prefix/test/b";
907         FakeConnection.Connect(false);
908         
909         std::string ContactFile =
910         "BEGIN:VCARD\n"
911         "VERSION:4.0\n"
912         "UID:84q2ioj13jofiujqwrAAA\n"
913         "N:;;Meep;Moop;;\n"
914         "FN:The Meep Moop\n"
915         "END:VCARD";
916         
917         FakeConnection.TestRequestResult = COREQUEST_OK;
918         FakeConnection.TestEntityTag = "";
919         FakeConnection.TestResultCode = 200;
920         FakeConnection.TestSessionCode = 0;
921         FakeConnection.TestResultMessage = ContactFile;
922         
923         COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
924         
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); 
930         
933 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Invalid_Permissions){
934         
935         std::string ServerAddress1 = "gibberish.invalid";
936         std::string ServerUser1 = "user";
937         std::string ServerPass1 = "pass";
938         
939         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
940         FakeConnection.ResultServerPrefix = "/prefix/test/b";
941         FakeConnection.Connect(false);
942         
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.";
948         
949         COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
950         
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);       
956         
959 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Missing_Resource){
960         
961         std::string ServerAddress1 = "gibberish.invalid";
962         std::string ServerUser1 = "user";
963         std::string ServerPass1 = "pass";
964         
965         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
966         FakeConnection.ResultServerPrefix = "/prefix/test/b";
967         FakeConnection.Connect(false);
968         
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.";
974         
975         COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
976         
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);  
982         
985 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Contact_Data_Due_To_No_Connection){
986         
987         std::string ServerAddress1 = "gibberish.invalid";
988         std::string ServerUser1 = "user";
989         std::string ServerPass1 = "pass";
990         
991         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
992         FakeConnection.ResultServerPrefix = "/prefix/test/b";
993         FakeConnection.Connect(false);
994         
995         FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
996         FakeConnection.TestEntityTag = "";
997         FakeConnection.TestResultCode = 0;
998         FakeConnection.TestSessionCode = 0;
999         FakeConnection.TestResultMessage = "";
1000         
1001         COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf");
1002         
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);
1008         
1011 TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Full_Server_Contact_List){
1012         
1013         std::string ServerAddress1 = "gibberish.invalid";
1014         std::string ServerUser1 = "user";
1015         std::string ServerPass1 = "pass";
1016         
1017         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1018         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1019         FakeConnection.Connect(false);  
1020         
1021         std::string ContactFile1 =
1022         "BEGIN:VCARD\n"
1023         "VERSION:4.0\n"
1024         "UID:84q2ioj13jofiujqwrAAA-1\n"
1025         "N:;;Meep;Moop;;\n"
1026         "FN:The Meep Moop\n"
1027         "END:VCARD";
1029         std::string ContactFile2 =
1030         "BEGIN:VCARD\n"
1031         "VERSION:4.0\n"
1032         "UID:84q2ioj13jofiujqwrAAA-2\n"
1033         "N:;;Meep;Moop;;\n"
1034         "FN:The Meep Moop\n"
1035         "END:VCARD";
1036         
1037         std::string ContactFile3 =
1038         "BEGIN:VCARD\n"
1039         "VERSION:4.0\n"
1040         "UID:84q2ioj13jofiujqwrAAA-3\n"
1041         "N:;;Meep;Moop;;\n"
1042         "FN:The Meep Moop\n"
1043         "END:VCARD";
1044         
1045         COContactList ContactListSetup;
1046         COContactData ContactPerson;
1047         
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 = "";
1067         
1068         COContactList ServerDataResult = FakeConnection.GetContactList("");
1069         
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);
1085         
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){
1092         
1093         std::string ServerAddress1 = "gibberish.invalid";
1094         std::string ServerUser1 = "user";
1095         std::string ServerPass1 = "pass";
1096         
1097         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1098         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1099         FakeConnection.Connect(false);  
1100         
1101         std::string ContactFile3 =
1102         "BEGIN:VCARD\n"
1103         "VERSION:4.0\n"
1104         "UID:84q2ioj13jofiujqwrAAA-3\n"
1105         "N:;;Meep;Moop;;\n"
1106         "FN:The Meep Moop\n"
1107         "END:VCARD";
1108         
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 = "";
1123         
1124         COContactList ServerDataResult = FakeConnection.GetContactList("2312312-12312312");
1125         
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){
1142         
1143         std::string ServerAddress1 = "gibberish.invalid";
1144         std::string ServerUser1 = "user";
1145         std::string ServerPass1 = "pass";
1146         
1147         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1148         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1149         FakeConnection.Connect(false);
1150         
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.";
1160         
1161         COContactList ServerDataResult = FakeConnection.GetContactList("");
1162         
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){
1174         
1175         std::string ServerAddress1 = "gibberish.invalid";
1176         std::string ServerUser1 = "user";
1177         std::string ServerPass1 = "pass";
1178         
1179         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1180         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1181         FakeConnection.Connect(false);
1182         
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.";
1192         
1193         COContactList ServerDataResult = FakeConnection.GetContactList("");
1194         
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){
1206         
1207         std::string ServerAddress1 = "gibberish.invalid";
1208         std::string ServerUser1 = "user";
1209         std::string ServerPass1 = "pass";
1210         
1211         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1212         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1213         FakeConnection.Connect(false);
1214         
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.";
1224         
1225         COContactList ServerDataResult = FakeConnection.GetContactList("");
1226         
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){
1238         
1239         std::string ServerAddress1 = "gibberish.invalid";
1240         std::string ServerUser1 = "user";
1241         std::string ServerPass1 = "pass";
1242         
1243         FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
1244         FakeConnection.ResultServerPrefix = "/prefix/test/b";
1245         FakeConnection.Connect(false);
1246         FakeConnection.ResultTaskCompleted = false;
1247         
1248         while (!FakeConnection.IsTaskCompleted()){
1249                 
1250                 std::this_thread::sleep_for(std::chrono::milliseconds(250));
1251                 FakeConnection.ResultTaskCompleted = true;
1252                 
1253         }
1254         
1255         EXPECT_TRUE(FakeConnection.ResultTaskCompleted);
1256         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy