Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added initial code and UID unit test for the CalendarJournalObject
[xestiacalendar/.git] / source / tests / xestiacalendar_test.cpp
1 // xestiacalendar_test.cpp - Xestia Calendar Unit Testing Suite.
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 <curl/curl.h>
20 #include <gtest/gtest.h>
21 #include <iostream>
22 #include <string>
23 #include <stdexcept>
25 #include "xestiacalendar_commonfunctions.h"
26 #include "xestiacalendar_populate.h"
27 #include "xestiacalendar_icaleventload.h"
28 #include "xestiacalendar_icaleventsave.h"
29 #include "xestiacalendar_icaltaskload.h"
30 #include "xestiacalendar_icaljournalload.h"
31 #include "xestiacalendar_icaljournalsave.h"
32 #include "xestiacalendar_icalfreebusyload.h"
33 #include "xestiacalendar_icalfreebusysave.h"
34 #include "xestiacalendar_icaltimezoneload.h"
35 #include "xestiacalendar_caldav.h"
37 enum MenuOpts {
38         TESTS_ICALLOADEVENT = 1,
39         TESTS_ICALSAVEEVENT,
40         TESTS_ICALLOADTODO,
41         TESTS_ICALSAVEJOURNAL,
42         TESTS_ICALLOADJOURNAL,
43         TESTS_ICALLOADFREEBUSY,
44         TESTS_ICALSAVEFREEBUSY,
45         TESTS_ICALLOADTIMEZONE,
46         TESTS_CALDAV,
47         TESTS_COMMONFUNCTIONS,
48         TESTS_EXTRA,
49         TESTS_QUIT
50 };
52 enum ExtraMenuOpts{
53         EXTRA_POPULATECALDAV = 1,
54         EXTRA_RETURN
55 };
57 void printn(std::string text){
58 // printn: Print a line and end with a newline (\n).
60         std::cout << text << std::endl;
62 }
64 void printmenu(){
65 // printmenu: Print the menu.
67         std::cout << "Select an option:" << std::endl << std::endl;
68         std::cout << TESTS_ICALLOADEVENT << ". iCalendar Event Component Load" << std::endl;
69         std::cout << TESTS_ICALSAVEEVENT << ". iCalendar Event Component Save" << std::endl;
70         std::cout << TESTS_ICALLOADTODO << ". iCalendar Task Component Load" << std::endl;
71         std::cout << TESTS_ICALLOADJOURNAL << ". iCalendar Journal Component Load" << std::endl;
72         std::cout << TESTS_ICALSAVEJOURNAL << ". iCalendar Journal Component Save" << std::endl;
73         std::cout << TESTS_ICALLOADFREEBUSY << ". iCalendar FreeBusy Component Load" << std::endl;
74         std::cout << TESTS_ICALSAVEFREEBUSY << ". iCalendar FreeBusy Component Save" << std::endl;
75         std::cout << TESTS_ICALLOADTIMEZONE << ". iCalendar Timezone Component Load" << std::endl;
76         std::cout << TESTS_CALDAV << ". CalDAV Object" << std::endl;
77         std::cout << TESTS_COMMONFUNCTIONS << ". Common Functions" << std::endl;
78         std::cout << TESTS_EXTRA << ". Extra Functions Menu" << std::endl;
79         std::cout << TESTS_QUIT << ". Quit" << std::endl;
80         std::cout << std::endl;
82 }
84 void printextramenu(){
86         std::cout << "Extra Functions Menu" << std::endl << std::endl;
87         std::cout << "Select an option:" << std::endl << std::endl;     
88         std::cout << EXTRA_POPULATECALDAV << ". Populate CalDAV calendar" << std::endl;
89         std::cout << EXTRA_RETURN << ". Return to previous menu" << std::endl;
90         std::cout << std::endl;
91         
92 }
94 void runextramenu(){
95         
96         bool ExitEnabled = false;
97         std::string StringOption = "";
98         int TestResult = 0;
100         while(ExitEnabled == false){
101         
102                 printextramenu();
104                 // Get user input.
106                 std::cout << "Select Option: "; 
107                 std::cin >> StringOption;
108                 
109                 int IntOption = -1;
110                 
111                 // Check if input is a number.
112                 
113                 try{
114                         IntOption = stoi(StringOption);
115                 }
116                 
117                 // Return to the top of the while statement if input
118                 // really isn't a number.
119                 
120                 catch(std::invalid_argument e){
121                         printn("Error: Selected option is not a number.");
122                         continue;
123                 }
124                 
125                 // Find which option has been selected from the
126                 // input.
127                 
128                 switch(IntOption){
129                 
130                         case EXTRA_POPULATECALDAV:
131                                 printn("Populating CalDAV calendar...");
132                                 populatecaldav();
133                                 break;
134                         case EXTRA_RETURN:
135                                 return;
136                                 break;
137                         default:
138                                 printn("Invalid menu number given."); 
139                                 break;
140                 
141                 }
142         
143         }
144         
147 int main(int argc, char* argv[]){
149         // Initialise the several libraries that have
150         // been included.
151         
152         ::testing::InitGoogleTest(&argc, argv);
153         curl_global_init(CURL_GLOBAL_ALL);
154         
155         printn("Xestia Calendar Unit Testing Application");
156         printn("(c)2016 Xestia Software Development");
157         printn("Note: Unit testing is currently in development");
158         printn("");
160         bool ExitEnabled = false;
161         std::string StringOption = "";
162         int TestResult = 0;
164         while(ExitEnabled == false){
165         
166                 printmenu();
168                 // Get user input.
170                 std::cout << "Select Option: "; 
171                 std::cin >> StringOption;
172                 
173                 int IntOption = -1;
174                 
175                 // Check if input is a number.
176                 
177                 try{
178                         IntOption = stoi(StringOption);
179                 }
180                 
181                 // Return to the top of the while statement if input
182                 // really isn't a number.
183                 
184                 catch(std::invalid_argument e){
185                         printn("Error: Selected option is not a number.");
186                         continue;
187                 }
188                 
189                 // Find which option has been selected from the
190                 // input.
191                 
192                 switch(IntOption){
193                 
194                         case TESTS_ICALLOADEVENT:
195                                 printn("Running iCalendar Event Component tests...");
196                                 ::testing::GTEST_FLAG(filter) = "iCalendarEvent*";
197                                 TestResult = RUN_ALL_TESTS();
198                                 break;
199                         case TESTS_ICALSAVEEVENT:
200                                 printn("Running iCalendar Event Component Save tests...");
201                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveEvent*";
202                                 TestResult = RUN_ALL_TESTS();
203                                 break;
204                         case TESTS_ICALLOADTODO:
205                                 printn("Running iCalendar Task Component tests...");
206                                 ::testing::GTEST_FLAG(filter) = "iCalendarTask*";
207                                 TestResult = RUN_ALL_TESTS();
208                                 break;
209                         case TESTS_ICALLOADJOURNAL:
210                                 printn("Running iCalendar Journal Component tests...");
211                                 ::testing::GTEST_FLAG(filter) = "iCalendarJournal*";
212                                 TestResult = RUN_ALL_TESTS();
213                                 break;
214                         case TESTS_ICALSAVEJOURNAL:
215                                 printn("Running iCalendar Journal Component Save tests...");
216                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveJournal*";
217                                 TestResult = RUN_ALL_TESTS();
218                                 break;
219                         case TESTS_ICALLOADFREEBUSY:
220                                 printn("Running iCalendar Free Busy Component tests...");
221                                 ::testing::GTEST_FLAG(filter) = "iCalendarFreeBusy*";
222                                 TestResult = RUN_ALL_TESTS();
223                                 break;
224                         case TESTS_ICALSAVEFREEBUSY:
225                                 printn("Running iCalendar Free Busy Component Save tests...");
226                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveFreeBusy*";
227                                 TestResult = RUN_ALL_TESTS();
228                                 break;
229                         case TESTS_ICALLOADTIMEZONE:
230                                 printn("Running iCalendar Timezone Component tests...");
231                                 ::testing::GTEST_FLAG(filter) = "iCalendarTimezone*";
232                                 TestResult = RUN_ALL_TESTS();
233                                 break;
234                         case TESTS_CALDAV:
235                                 printn("Running CalDAV tests...");
236                                 ::testing::GTEST_FLAG(filter) = "CalDAV*";
237                                 TestResult = RUN_ALL_TESTS();
238                                 break;
239                         case TESTS_COMMONFUNCTIONS:
240                                 printn("Running Commmon Functions tests...");
241                                 ::testing::GTEST_FLAG(filter) = "CommonFunctions*";
242                                 TestResult = RUN_ALL_TESTS();
243                                 break;
244                         case TESTS_EXTRA:
245                                 runextramenu();
246                                 break;
247                         case TESTS_QUIT:
248                                 return 0;
249                                 break;
250                         default:
251                                 printn("Invalid menu number given."); 
252                                 break;
253                 
254                 }
255         
256         }
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