X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;ds=inline;f=source%2Ftests%2Fxestiacalendar_testcommon.cpp;h=37ec06a0062e10e7a4dd66de1e2fa80b9ce2ffd5;hb=df7f1973d6e4ce9e5d8cf98c57247e1d4f0682bc;hp=7e96498a86303fe33ad446410faa4de1cbbc6534;hpb=cd689032d169aa5946b2550dd76710107a851c5c;p=xestiacalendar%2F.git
diff --git a/source/tests/xestiacalendar_testcommon.cpp b/source/tests/xestiacalendar_testcommon.cpp
index 7e96498..37ec06a 100644
--- a/source/tests/xestiacalendar_testcommon.cpp
+++ b/source/tests/xestiacalendar_testcommon.cpp
@@ -1,9 +1,206 @@
+// xestiacalendar_testcommon.cpp - Xestia Calendar Unit Test Common Functions.
+//
+// (c) 2016 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Address Book 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 Address Book 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
+
+#include
+
#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