Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added unit tests for verifying that the settings match in CalDAVNormal
[xestiacalendar/.git] / source / tests / xestiacalendar_caldav.h
1 // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "../objects/CalDAV/CalDAV.h"
20 #include "xestiacalendar_testcommon.h"
21 #include <iostream>
22 #include <map>
24 using namespace std;
26 TEST(CalDAV, BasicTests){
28         CalDAVConnectionData ConnPlain;
29         CalDAVConnectionData ConnNormal;
30         CalDAVConnectionData ConnInvalidSSL;
31         CalDAVConnectionData ConnTimeout;
32         ProcessConnectionDataFileResult DataFileResult;
34         bool ValidDataPlain = false;
35         bool ValidDataNormal = false;
36         bool ValidDataInvalidSSL = false;
37         bool ValidDataTimeout = false;
39         // Attempt to read the caldavtest-plain.auth file.
40         
41         DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain);
42         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
43                 ValidDataPlain = true;
44         }
45         
46         // Attempt to read the caldavtest.auth file.
48         DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
49         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
50                 ValidDataNormal = true;
51         }
52         
53         // Attempt to read the caldavtest-fail.auth file.
54         
55         DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL);
56         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
57                 ValidDataInvalidSSL = true;
58         }
59         
60         // Attempt to read the caldavtest-timeout.auth file.
61         
62         DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnTimeout);
63         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
64                 ValidDataTimeout = true;
65         }
67         if (ValidDataPlain == false){
68         
69                 // Cannot read the caldavtest-plain.auth file properly.
70                 
71                 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
72                 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
73                 cout << "server=localname" << endl;
74                 cout << "port=8080" << endl;
75                 cout << "user=username" << endl;
76                 cout << "pass=password" << endl;
77                 cout << "ssl=false" << endl;
78                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
79                 
80         }
81         
82         if (ValidDataNormal == false){
83         
84                 // Cannot read the caldavtest.auth file properly.
85                 
86                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
87                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
88                 cout << "server=localname" << endl;
89                 cout << "port=8080" << endl;
90                 cout << "user=username" << endl;
91                 cout << "pass=password" << endl;
92                 cout << "ssl=false" << endl;
93                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
94                 
95         }
96         
97         if (ValidDataInvalidSSL == false){
98         
99                 // Cannot read the caldavtest-fail.auth file properly.
100                 
101                 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
102                 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
103                 cout << "server=fail.localname" << endl;
104                 cout << "port=8080" << endl;
105                 cout << "user=username" << endl;
106                 cout << "pass=password" << endl;
107                 cout << "ssl=false" << endl;
108                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
109                 
110         }
111         
112         if (ValidDataTimeout == false){
113         
114                 // Cannot read the caldavtest-timeout.auth file properly.
115                 
116                 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
117                 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
118                 cout << "server=fail.localname" << endl;
119                 cout << "port=8080" << endl;
120                 cout << "user=username" << endl;
121                 cout << "pass=password" << endl;
122                 cout << "ssl=false" << endl;
123                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
124                 
125         }
126         
127         ASSERT_EQ(true, ValidDataPlain);
128         ASSERT_EQ(true, ValidDataNormal);
129         ASSERT_EQ(true, ValidDataInvalidSSL);
130         ASSERT_EQ(true, ValidDataTimeout);
132         // (*nix version) Setup an initial connection (just plain
133         // text).
134         
135         CalDAV CalDAVPlain;
136         CalDAVPlain.SetupConnectionData(&ConnPlain);
137         
138         // Verify that the settings match with the CalDAVConnectionData
139         // passed.
140         
141         CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData();
142         
143         ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname);
144         ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username);
145         ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port);
146         ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix);
147         ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL);
148         
149         // Verify that the connection was successful.
150         
151         CalDAVServerResult ConnResult = CalDAVPlain.Connect();
152         
153         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
154         ASSERT_EQ(200, ConnResult.HTTPCode);
155         ASSERT_EQ(CURLE_OK, ConnResult.Code);
156         
157         // Do another connection and this time the connection should
158         // fail due to being an invalid host name.
159         
160         CalDAVConnectionData ConnPlainFail;
161         ConnPlainFail.Hostname = "server.invalid";
162         ConnPlainFail.Username = "fail";
163         ConnPlainFail.Password = "fail";
164         ConnPlainFail.Port = 80;
165         ConnPlainFail.UseSSL = false;
166         
167         // Setup the CalDAV connection object.
168         
169         CalDAV CalDAVPlainFail;
170         CalDAVPlainFail.SetupConnectionData(&ConnPlainFail);
171         
172         // Setup the CalDAVStatus object.
173         
174         CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData();
175         
176         // Connect and fail.
177         
178         ConnResult = CalDAVPlainFail.Connect();
179         
180         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
181         ASSERT_EQ(0, ConnResult.HTTPCode);
182         ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code);
183         
184         // (*nix version) Setup an initial connection (with a valid
185         // SSL certificate).
187         CalDAV CalDAVNormal;
188         CalDAVNormal.SetupConnectionData(&ConnNormal);
190         // Verify that the settings match with the CalDAVConnectionData
191         // passed.
192         
193         CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData();
194         
195         ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname);
196         ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username);
197         ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port);
198         ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix);
199         ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL);
201         // Verify that the connection was successful (with a valid
202         // SSL certificate).
203         
204         // (*nix version) Setup an initial connection on a server that
205         // will fail due to having an invalid SSL certificate.
207         // Verify that the connection had failed. (with an invalid
208         // SSL certificate).
209         
210         // (*nix version) Setup an inital connection on a server where
211         // a timeout occurs.
212         
213         // Verify that the connection had timed out.
214         
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