Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted code in tests directory
[xestiacalendar/.git] / source / tests / xestiacalendar_testcommon.cpp
index 7e96498..af2a7ca 100644 (file)
@@ -1,9 +1,206 @@
+// xestiacalendar_testcommon.cpp - Xestia Calendar Unit Test Common Functions.
+//
+// (c) 2016-2017 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Calendar is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Calendar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
+
+#include <fstream>
+
 #include "xestiacalendar_testcommon.h"
+#include "../common/file.h"
 
-CalDAVConnectionData ProcessConnectionDataFile(string DataFilename){
+ProcessConnectionDataFileResult ProcessConnectionDataFile(string DataFilename, 
+       CalDAVConnectionData *ConnData){
+               
+       ProcessConnectionDataFileResult processResult = PROCESSCONNECTIONDATAFILE_UNITTESTFAIL;
+               
+       // Check if the file exists and return 
+       // PROCESSCONNECTIONDATAFILE_MISSING if not.
+       
+       if (!FileExists(dataFilename)){
+               return PROCESSCONNECTIONDATAFILE_MISSING;
+       }
+       
+       ifstream fileStream;
+       string receivedStringData = "";
+       
+       fileStream.open(dataFilename, ifstream::in);
+       
+       if (fileStream.rdstate() & ifstream::failbit){
+               return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
+       }
 
-       CalDAVConnectionData ConnData;
+       if (fileStream.rdstate() & ifstream::badbit){
+               return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
+       }
+       
+       // Process the file.
+       
+       char *bufferRead = new char[256];
+       
+       while (!FileStream.eof()){
+               
+               fileStream.getline(bufferRead, 256);
+               receivedStringData.append(bufferRead);
+               receivedStringData.append("\n");
+               
+       }
+       
+       delete[] bufferRead;
+       
+       bool newLine = false;
+       bool skipMode = false;
+       bool equalFound = false;
+       bool quoteMode = false;
+       bool serverNameFound = false;
+       bool serverUserFound = false;
+       bool serverPassFound = false;
+       bool serverSSLFound = false;
+       bool serverPortFound = false;
+       bool serverPrefixFound = false;
+       char bufferChar = 0;
+       int stringDataSize = receivedStringData.size();
+       int seekCount = 0;
+       string propertyName;
+       string propertyValue;
+
+       while (seekCount < stringDataSize){
+
+               if (receivedStringData[seekCount] == '='){
+               
+                       equalFound = true;              
+               
+               } else if (receivedStringData[seekCount] == '\n'){
+               
+                       // Newline reached. Check for what type of
+                       // data it is.
+               
+                       // Chceck that the equals sign has been found,
+                       // there is a values in the property name
+                       // and property value before doing anything.
+                                               
+                       if (equalFound == true &&
+                               propertyName.size() > 0 &&
+                               propertyValue.size() > 0){
+                       
+                               if (propertyName == "server" && serverNameFound == false){
+                               
+                                       // Setup the server hostname.
+                               
+                                       connData->hostname = propertyValue;
+                                       serverNameFound = true;
+                               
+                               } else if (propertyName == "port" && serverPortFound == false){
+                               
+                                       // Setup the server port.
+                               
+                                       int portNum;
+                                       bool portNumValid = true;
+                               
+                                       try{
+                                               portNum = stoi(propertyValue);
+                                       }
+                                       
+                                       catch(const invalid_argument &oor){
+                                               portNumValid = false;
+                                       }
+                                       
+                                       // Port Number is valid so add to the
+                                       // CalDAVConnectionData handle.
+                                       
+                                       if (portNumValid == true){
+                                               connData->Port = portNum;
+                                               serverPortFound = true;
+                                       }
+                               
+                               } else if (propertyName == "user" && serverUserFound == false){
+                               
+                                       // Setup the server user.
+                                       
+                                       connData->username = propertyValue;
+                                       serverUserFound = true;
+                               
+                               } else if (propertyName == "pass" && serverPassFound == false){
+                               
+                                       // Setup the server pass.
+                                       
+                                       connData->Password = propertyValue;
+                                       serverPassFound = true;                         
+                               
+                               } else if (propertyName == "ssl" && serverSSLFound == false){
+                               
+                                       // Setup the server SSL status.
+                                       
+                                       if (propertyValue == "true"){
+                                               connData->useSSL = true;
+                                       } else {
+                                               connData->useSSL = false;                                       
+                                       }
+                                       
+                                       serverSSLFound = true;
+                               
+                               } else if (propertyName == "prefix" && serverPrefixFound == false){
+                               
+                                       // Setup the server prefix.
+                               
+                                       connData->prefix = propertyValue;
+                                       serverPrefixFound = true;
+                               
+                               }
+                               
+                       }
+                       
+                       // Reset the variables.
+               
+                       equalFound = false;
+                       propertyName.clear();
+                       propertyValue.clear();
+               
+               } else {
+               
+                       // No special character so add it to the 
+                       // Property name or value depending on 
+                       // if the equal sign has been found.
+               
+                       bufferChar = receivedStringData[seekCount];
+               
+                       if (equalFound == true){
+                               propertyValue += bufferChar;
+                       } else {
+                               propertyName += bufferChar;
+                       }
+                       
+                       bufferChar = 0;
+               
+               }
+
+               seekCount++;
+
+       }
+       
+       // Check that the CalDAV connection data object 
+       // contains valid data.
+       
+       bool calDAVConnDataResult = CalDAVObjectValidSettings(connData);
        
-       return ConnData;
+       if (calDAVConnDataResult == false){
+               processResult = PROCESSCONNECTIONDATAFILE_INVALID;
+       } else {
+               processResult = PROCESSCONNECTIONDATAFILE_OK;
+       }
        
+       return processResult;
+               
 }
\ No newline at end of file
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