Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added ATTACH property for saving data from a CalendarEventObject.
[xestiacalendar/.git] / source / tests / xestiacalendar_testcommon.cpp
1 // xestiacalendar_testcommon.cpp - Xestia Calendar Unit Test Common Functions.
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 <fstream>
21 #include "xestiacalendar_testcommon.h"
22 #include "../common/file.h"
24 ProcessConnectionDataFileResult ProcessConnectionDataFile(string DataFilename, 
25         CalDAVConnectionData *ConnData){
26                 
27         ProcessConnectionDataFileResult ProcessResult = PROCESSCONNECTIONDATAFILE_UNITTESTFAIL;
28                 
29         // Check if the file exists and return 
30         // PROCESSCONNECTIONDATAFILE_MISSING if not.
31         
32         if (!FileExists(DataFilename)){
33                 return PROCESSCONNECTIONDATAFILE_MISSING;
34         }
35         
36         ifstream FileStream;
37         string ReceivedStringData = "";
38         
39         FileStream.open(DataFilename, ifstream::in);
40         
41         if (FileStream.rdstate() & ifstream::failbit){
42                 return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
43         }
45         if (FileStream.rdstate() & ifstream::badbit){
46                 return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
47         }
48         
49         // Process the file.
50         
51         char *BufferRead = new char[256];
52         
53         while (!FileStream.eof()){
54                 
55                 FileStream.getline(BufferRead, 256);
56                 ReceivedStringData.append(BufferRead);
57                 ReceivedStringData.append("\n");
58                 
59         }
60         
61         delete[] BufferRead;
62         
63         bool NewLine = false;
64         bool SkipMode = false;
65         bool EqualFound = false;
66         bool QuoteMode = false;
67         bool ServerNameFound = false;
68         bool ServerUserFound = false;
69         bool ServerPassFound = false;
70         bool ServerSSLFound = false;
71         bool ServerPortFound = false;
72         bool ServerPrefixFound = false;
73         char BufferChar = 0;
74         int StringDataSize = ReceivedStringData.size();
75         int SeekCount = 0;
76         string PropertyName;
77         string PropertyValue;
79         while (SeekCount < StringDataSize){
81                 if (ReceivedStringData[SeekCount] == '='){
82                 
83                         EqualFound = true;              
84                 
85                 } else if (ReceivedStringData[SeekCount] == '\n'){
86                 
87                         // Newline reached. Check for what type of
88                         // data it is.
89                 
90                         // Chceck that the equals sign has been found,
91                         // there is a values in the property name
92                         // and property value before doing anything.
93                                                 
94                         if (EqualFound == true &&
95                                 PropertyName.size() > 0 &&
96                                 PropertyValue.size() > 0){
97                         
98                                 if (PropertyName == "server" && ServerNameFound == false){
99                                 
100                                         // Setup the server hostname.
101                                 
102                                         ConnData->Hostname = PropertyValue;
103                                         ServerNameFound = true;
104                                 
105                                 } else if (PropertyName == "port" && ServerPortFound == false){
106                                 
107                                         // Setup the server port.
108                                 
109                                         int PortNum;
110                                         bool PortNumValid = true;
111                                 
112                                         try{
113                                                 PortNum = stoi(PropertyValue);
114                                         }
115                                         
116                                         catch(const invalid_argument &oor){
117                                                 PortNumValid = false;
118                                         }
119                                         
120                                         // Port Number is valid so add to the
121                                         // CalDAVConnectionData handle.
122                                         
123                                         if (PortNumValid == true){
124                                                 ConnData->Port = PortNum;
125                                                 ServerPortFound = true;
126                                         }
127                                 
128                                 } else if (PropertyName == "user" && ServerUserFound == false){
129                                 
130                                         // Setup the server user.
131                                         
132                                         ConnData->Username = PropertyValue;
133                                         ServerUserFound = true;
134                                 
135                                 } else if (PropertyName == "pass" && ServerPassFound == false){
136                                 
137                                         // Setup the server pass.
138                                         
139                                         ConnData->Password = PropertyValue;
140                                         ServerPassFound = true;                         
141                                 
142                                 } else if (PropertyName == "ssl" && ServerSSLFound == false){
143                                 
144                                         // Setup the server SSL status.
145                                         
146                                         if (PropertyValue == "true"){
147                                                 ConnData->UseSSL = true;
148                                         } else {
149                                                 ConnData->UseSSL = false;                                       
150                                         }
151                                         
152                                         ServerSSLFound = true;
153                                 
154                                 } else if (PropertyName == "prefix" && ServerPrefixFound == false){
155                                 
156                                         // Setup the server prefix.
157                                 
158                                         ConnData->Prefix = PropertyValue;
159                                         ServerPrefixFound = true;
160                                 
161                                 }
162                                 
163                         }
164                         
165                         // Reset the variables.
166                 
167                         EqualFound = false;
168                         PropertyName.clear();
169                         PropertyValue.clear();
170                 
171                 } else {
172                 
173                         // No special character so add it to the 
174                         // Property name or value depending on 
175                         // if the equal sign has been found.
176                 
177                         BufferChar = ReceivedStringData[SeekCount];
178                 
179                         if (EqualFound == true){
180                                 PropertyValue += BufferChar;
181                         } else {
182                                 PropertyName += BufferChar;                     
183                         }
184                         
185                         BufferChar = 0;
186                 
187                 }
189                 SeekCount++;
191         }
192         
193         // Check that the CalDAV connection data object 
194         // contains valid data.
195         
196         bool CalDAVConnDataResult = CalDAVObjectValidSettings(ConnData);
197         
198         if (CalDAVConnDataResult == false){
199                 ProcessResult = PROCESSCONNECTIONDATAFILE_INVALID;
200         } else {
201                 ProcessResult = PROCESSCONNECTIONDATAFILE_OK;
202         }
203         
204         return ProcessResult;
205                 
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