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