Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added option to populate a CalDAV calendar in the unit testing application
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 2 May 2016 08:16:49 +0000 (09:16 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 2 May 2016 08:16:49 +0000 (09:16 +0100)
source/tests/xestiacalendar_populate.cpp [new file with mode: 0644]
source/tests/xestiacalendar_populate.h [new file with mode: 0644]
source/tests/xestiacalendar_test.cpp

diff --git a/source/tests/xestiacalendar_populate.cpp b/source/tests/xestiacalendar_populate.cpp
new file mode 100644 (file)
index 0000000..9c87cc9
--- /dev/null
@@ -0,0 +1,264 @@
+// xestiacalendar_populate.cpp - Xestia Calendar Unit Testing Suite Populate Functions
+//
+// (c) 2016 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 "xestiacalendar_populate.h"
+void populatecaldav(){
+       
+       CalDAV PopulateCalDAV;
+       
+       // Load the connection settings.
+       
+       CalDAVConnectionData ConnNormal;
+       ProcessConnectionDataFileResult DataFileResult;
+       bool ValidDataNormal = false;
+       
+       DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
+       if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
+               ValidDataNormal = true;
+       } else {
+               
+               // Cannot read the caldavtest.auth file properly.
+               
+               cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
+               cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
+               cout << "server=localname" << endl;
+               cout << "port=8080" << endl;
+               cout << "user=username" << endl;
+               cout << "pass=password" << endl;
+               cout << "ssl=false" << endl;
+               cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
+               
+       }
+       
+       // Connect to the server and create
+       // the calendar.
+       
+       string ServerAddress = "";
+       string ServerUserPass = "";
+       
+       // Setup the server address.
+       
+       string CalendarName = "Unit Testing Calendar";
+       string CalendarShortName = "unittestcal";
+       
+       PopulateCalDAV.SetupConnectionData(&ConnNormal);
+       
+       CalDAVServerResult ServerResult;
+       
+       ServerResult = PopulateCalDAV.Connect();
+       
+       if (ServerResult.Code != CURLE_OK){
+               
+               cout << "Error while connecting to the CalDAV server." << endl;
+               cout << "Xestia Calendar Code: " << ServerResult.Result << endl;
+               cout << "cURL Code: " << ServerResult.Code << endl;
+               cout << "HTTP Code: " << ServerResult.HTTPCode << endl;
+               return;
+               
+       }
+       
+       // Get the list of calendars.
+       
+       CalDAVCalendarList CalendarList = PopulateCalDAV.GetCalendars();
+
+       if (CalendarList.Name.size() == 0){
+               
+               cout << "Error while getting the list of calendars." << endl;
+               return;
+               
+       }
+       
+       string CalendarURI = "";
+
+       // Look for the Unit testing calendar.
+       
+       for (std::map<int,string>::iterator CalNameIter = CalendarList.Name.begin();
+               CalNameIter != CalendarList.Name.end(); CalNameIter++){
+
+               if (CalNameIter->second == "Unit Testing Calendar"){
+                       CalendarURI = CalendarList.HREF.find(CalNameIter->first)->second;
+                       break;
+               }
+       
+       }
+       
+       if (CalendarURI == ""){
+               
+               cout << "Error while getting the unit testing calendar URI" << endl;
+               return;
+               
+       }
+       
+       // Delete the previous calendar.
+       
+       ServerResult = PopulateCalDAV.DeleteCalendar(&CalendarURI);
+       
+       if (ServerResult.Code != CURLE_OK){
+
+               cout << "Error while deleting a calendar." << endl;
+               cout << "Xestia Calendar Code: " << ServerResult.Result << endl;
+               cout << "cURL Code: " << ServerResult.Code << endl;
+               cout << "HTTP Code: " << ServerResult.HTTPCode << endl;
+               return;
+               
+       }
+       
+       // Create the calendar.
+       
+       ServerResult = PopulateCalDAV.AddCalendar(&CalendarName, &CalendarShortName);
+       
+       if (ServerResult.Code != CURLE_OK){
+
+               cout << "Error while adding a calendar." << endl;
+               cout << "Xestia Calendar Code: " << ServerResult.Result << endl;
+               cout << "cURL Code: " << ServerResult.Code << endl;
+               cout << "HTTP Code: " << ServerResult.HTTPCode << endl;
+               return;
+               
+       }
+       
+       // Get the list of calendars with the new calendar added.
+       
+       CalendarList = PopulateCalDAV.GetCalendars();
+
+       if (CalendarList.Name.size() == 0){
+               
+               cout << "Error while getting the list of calendars." << endl;
+               return;
+               
+       }
+       
+       CalendarURI = "";
+
+       // Look for the Unit testing calendar.
+       
+       for (std::map<int,string>::iterator CalNameIter = CalendarList.Name.begin();
+               CalNameIter != CalendarList.Name.end(); CalNameIter++){
+
+               if (CalNameIter->second == "Unit Testing Calendar"){
+                       CalendarURI = CalendarList.HREF.find(CalNameIter->first)->second;
+                       break;
+               }
+       
+       }
+       
+       if (CalendarURI == ""){
+               
+               cout << "Error while getting the unit testing calendar URI" << endl;
+               return;
+               
+       }
+       
+       // Create five entries.
+       
+       string EntryUUIDs[5] = { "XC-UT1", "XC-UT2", "XC-UT3", "XC-UT4", "XC-UT5" };
+       string EntryFilename[5] = { "xc-ut1.ics", "xc-ut2.ics", "xc-ut3.ics", "xc-ut4.ics", "xc-ut5.ics" };
+       string EntryData[5] = { 
+               
+               "BEGIN:VCALENDAR\n"
+               "VERSION:2.0\n"
+               "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
+               "BEGIN:VEVENT\n"
+               "UID:XC-UT1\n"
+               "DTSTAMP:20160116T190200Z\n"
+               "DTSTART:20160116T190200Z\n"
+               "DTEND:20160116T190200Z\n"
+               "SUMMARY: Xestia Calendar Unit Test Event 1\n"
+               "END:VEVENT\n"
+               "END:VCALENDAR\n",
+               
+               "BEGIN:VCALENDAR\n"
+               "VERSION:2.0\n"
+               "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
+               "BEGIN:VEVENT\n"
+               "UID:XC-UT2\n"
+               "DTSTAMP:20160116T190200Z\n"
+               "DTSTART:20160116T190200Z\n"
+               "DTEND:20160116T190200Z\n"
+               "SUMMARY: Xestia Calendar Unit Test Event 2\n"
+               "END:VEVENT\n"
+               "END:VCALENDAR",
+               
+               "BEGIN:VCALENDAR\n"
+               "VERSION:2.0\n"
+               "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
+               "BEGIN:VEVENT\n"
+               "UID:XC-UT3\n"
+               "DTSTAMP:20160116T190200Z\n"
+               "DTSTART:20160116T190200Z\n"
+               "DTEND:20160116T190200Z\n"
+               "SUMMARY: Xestia Calendar Unit Test Event 3\n"
+               "END:VEVENT\n"
+               "END:VCALENDAR",
+               
+               "BEGIN:VCALENDAR\n"
+               "VERSION:2.0\n"
+               "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
+               "BEGIN:VEVENT\n"
+               "UID:XC-UT4\n"
+               "DTSTAMP:20160116T190200Z\n"
+               "DTSTART:20160116T190200Z\n"
+               "DTEND:20160116T190200Z\n"
+               "SUMMARY: Xestia Calendar Unit Test Event 4\n"
+               "END:VEVENT\n"
+               "END:VCALENDAR",
+               
+               "BEGIN:VCALENDAR\n"
+               "VERSION:2.0\n"
+               "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
+               "BEGIN:VEVENT\n"
+               "UID:XC-UT5\n"
+               "DTSTAMP:20160116T190200Z\n"
+               "DTSTART:20160116T190200Z\n"
+               "DTEND:20160116T190200Z\n"
+               "SUMMARY: Xestia Calendar Unit Test Event 5\n"
+               "END:VEVENT\n"
+               "END:VCALENDAR"
+               
+       };
+       
+       // Place the entries into the calendar.
+       
+       string CalendarEntryURI = "";
+       
+       for (int EntrySeek = 0; EntrySeek < 5; EntrySeek++){
+               
+               CalendarEntryURI = CalendarURI;
+               CalendarEntryURI += EntryFilename[EntrySeek];
+               
+               ServerResult = PopulateCalDAV.AddEntry(&CalendarEntryURI, &EntryData[EntrySeek]);
+               
+               if (ServerResult.Code != CURLE_OK){
+
+                       cout << "Error while adding an entry to the unit testing calendar." << endl;
+                       cout << "Xestia Calendar Code: " << ServerResult.Result << endl;
+                       cout << "cURL Code: " << ServerResult.Code << endl;
+                       cout << "HTTP Code: " << ServerResult.HTTPCode << endl;
+                       cout << "URI address: " << CalendarEntryURI << endl;
+                       return;
+               
+               }
+               
+               CalendarEntryURI.clear();
+               
+       }
+       
+       cout << "CalDAV calendar populating completed." << endl;
+       
+}
\ No newline at end of file
diff --git a/source/tests/xestiacalendar_populate.h b/source/tests/xestiacalendar_populate.h
new file mode 100644 (file)
index 0000000..2d5b645
--- /dev/null
@@ -0,0 +1,30 @@
+// xestiacalendar_populate.h - Xestia Calendar Unit Testing Suite Populate Functions Header
+//
+// (c) 2016 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 <curl/curl.h>
+#include <string>
+
+#include "xestiacalendar_testcommon.h"
+#include "../objects/CalDAV/CalDAV.h"
+
+#ifndef __TESTS_XESTIACALENDAR_POPULATE_H__
+#define __TESTS_XESTIACALENDAR_POPULATE_H__
+
+void populatecaldav();
+
+#endif
\ No newline at end of file
index 198a232..e3e2bed 100644 (file)
@@ -22,8 +22,9 @@
 #include <string>
 #include <stdexcept>
 
-#include "xestiacalendar_icaleventload.h"
 #include "xestiacalendar_commonfunctions.h"
+#include "xestiacalendar_populate.h"
+#include "xestiacalendar_icaleventload.h"
 #include "xestiacalendar_icaltaskload.h"
 #include "xestiacalendar_icaljournalload.h"
 #include "xestiacalendar_icalfreebusyload.h"
@@ -38,9 +39,15 @@ enum MenuOpts {
        TESTS_ICALLOADTIMEZONE,
        TESTS_CALDAV,
        TESTS_COMMONFUNCTIONS,
+       TESTS_EXTRA,
        TESTS_QUIT
 };
 
+enum ExtraMenuOpts{
+       EXTRA_POPULATECALDAV = 1,
+       EXTRA_RETURN
+};
+
 void printn(std::string text){
 // printn: Print a line and end with a newline (\n).
 
@@ -59,11 +66,75 @@ void printmenu(){
        std::cout << TESTS_ICALLOADTIMEZONE << ". iCalendar Timezone Component Load" << std::endl;
        std::cout << TESTS_CALDAV << ". CalDAV Object" << std::endl;
        std::cout << TESTS_COMMONFUNCTIONS << ". Common Functions" << std::endl;
+       std::cout << TESTS_EXTRA << ". Extra Functions Menu" << std::endl;
        std::cout << TESTS_QUIT << ". Quit" << std::endl;
        std::cout << std::endl;
 
 }
 
+void printextramenu(){
+
+       std::cout << "Extra Functions Menu" << std::endl << std::endl;
+       std::cout << "Select an option:" << std::endl << std::endl;     
+       std::cout << EXTRA_POPULATECALDAV << ". Populate CalDAV calendar" << std::endl;
+       std::cout << EXTRA_RETURN << ". Return to previous menu" << std::endl;
+       std::cout << std::endl;
+       
+}
+
+void runextramenu(){
+       
+       bool ExitEnabled = false;
+       std::string StringOption = "";
+       int TestResult = 0;
+
+       while(ExitEnabled == false){
+       
+               printextramenu();
+
+               // Get user input.
+
+               std::cout << "Select Option: "; 
+               std::cin >> StringOption;
+               
+               int IntOption = -1;
+               
+               // Check if input is a number.
+               
+               try{
+                       IntOption = stoi(StringOption);
+               }
+               
+               // Return to the top of the while statement if input
+               // really isn't a number.
+               
+               catch(std::invalid_argument e){
+                       printn("Error: Selected option is not a number.");
+                       continue;
+               }
+               
+               // Find which option has been selected from the
+               // input.
+               
+               switch(IntOption){
+               
+                       case EXTRA_POPULATECALDAV:
+                               printn("Populating CalDAV calendar...");
+                               populatecaldav();
+                               break;
+                       case EXTRA_RETURN:
+                               return;
+                               break;
+                       default:
+                               printn("Invalid menu number given."); 
+                               break;
+               
+               }
+       
+       }
+       
+}
+
 int main(int argc, char* argv[]){
 
        // Initialise the several libraries that have
@@ -146,6 +217,9 @@ int main(int argc, char* argv[]){
                                ::testing::GTEST_FLAG(filter) = "CommonFunctions*";
                                TestResult = RUN_ALL_TESTS();
                                break;
+                       case TESTS_EXTRA:
+                               runextramenu();
+                               break;
                        case TESTS_QUIT:
                                return 0;
                                break;
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