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