Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Implemented UTF8 support in DeleteCalendar function
[xestiacalendar/.git] / source / tests / xestiacalendar_test.cpp
1 // xestiacalendar_test.cpp - Xestia Calendar Unit Testing Suite.
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar 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 Calendar 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_calendardatastorage.h"
38 #include "xestiacalendar_caldav.h"
40 enum MenuOpts {
41         TESTS_ICALLOADEVENT = 1,
42         TESTS_ICALSAVEEVENT,
43         TESTS_ICALLOADTODO,
44         TESTS_ICALSAVETODO,
45         TESTS_ICALLOADJOURNAL,
46         TESTS_ICALSAVEJOURNAL,
47         TESTS_ICALLOADFREEBUSY,
48         TESTS_ICALSAVEFREEBUSY,
49         TESTS_ICALLOADTIMEZONE,
50         TESTS_ICALSAVETIMEZONE,
51         TESTS_CALENDARDATASTORAGE,
52         TESTS_CALDAV,
53         TESTS_COMMONFUNCTIONS,
54         TESTS_EXTRA,
55         TESTS_QUIT
56 };
58 enum ExtraMenuOpts{
59         EXTRA_POPULATECALDAV = 1,
60         EXTRA_RETURN
61 };
63 void printn(std::string text){
64 // printn: Print a line and end with a newline (\n).
66         std::cout << text << std::endl;
68 }
70 void printmenu(){
71 // printmenu: Print the menu.
73         std::cout << "Select an option:" << std::endl << std::endl;
74         std::cout << TESTS_ICALLOADEVENT << ". iCalendar Event Component Load" << std::endl;
75         std::cout << TESTS_ICALSAVEEVENT << ". iCalendar Event Component Save" << std::endl;
76         std::cout << TESTS_ICALLOADTODO << ". iCalendar Task Component Load" << std::endl;
77         std::cout << TESTS_ICALSAVETODO << ". iCalendar Task Component Save" << std::endl;
78         std::cout << TESTS_ICALLOADJOURNAL << ". iCalendar Journal Component Load" << std::endl;
79         std::cout << TESTS_ICALSAVEJOURNAL << ". iCalendar Journal Component Save" << std::endl;
80         std::cout << TESTS_ICALLOADFREEBUSY << ". iCalendar FreeBusy Component Load" << std::endl;
81         std::cout << TESTS_ICALSAVEFREEBUSY << ". iCalendar FreeBusy Component Save" << std::endl;
82         std::cout << TESTS_ICALLOADTIMEZONE << ". iCalendar Timezone Component Load" << std::endl;
83         std::cout << TESTS_ICALSAVETIMEZONE << ". iCalendar Timezone Component Save" << std::endl;
84         std::cout << TESTS_CALENDARDATASTORAGE << ". Calendar Data Storage" << std::endl;
85         std::cout << TESTS_CALDAV << ". CalDAV Object" << std::endl;
86         std::cout << TESTS_COMMONFUNCTIONS << ". Common Functions" << std::endl;
87         std::cout << TESTS_EXTRA << ". Extra Functions Menu" << std::endl;
88         std::cout << TESTS_QUIT << ". Quit" << std::endl;
89         std::cout << std::endl;
91 }
93 void printextramenu(){
95         std::cout << "Extra Functions Menu" << std::endl << std::endl;
96         std::cout << "Select an option:" << std::endl << std::endl;     
97         std::cout << EXTRA_POPULATECALDAV << ". Populate CalDAV calendar" << std::endl;
98         std::cout << EXTRA_RETURN << ". Return to previous menu" << std::endl;
99         std::cout << std::endl;
100         
103 void runextramenu(){
104         
105         bool exitEnabled = false;
106         std::string stringOption = "";
107         int testResult = 0;
109         while(exitEnabled == false){
110         
111                 printextramenu();
113                 // Get user input.
115                 std::cout << "Select Option: "; 
116                 std::cin >> stringOption;
117                 
118                 int intOption = -1;
119                 
120                 // Check if input is a number.
121                 
122                 try{
123                         intOption = stoi(stringOption);
124                 }
125                 
126                 // Return to the top of the while statement if input
127                 // really isn't a number.
128                 
129                 catch(std::invalid_argument e){
130                         printn("Error: Selected option is not a number.");
131                         continue;
132                 }
133                 
134                 // Find which option has been selected from the
135                 // input.
136                 
137                 switch(intOption){
138                 
139                         case EXTRA_POPULATECALDAV:
140                                 printn("Populating CalDAV calendar...");
141                                 populatecaldav();
142                                 break;
143                         case EXTRA_RETURN:
144                                 return;
145                                 break;
146                         default:
147                                 printn("Invalid menu number given."); 
148                                 break;
149                 
150                 }
151         
152         }
153         
156 int main(int argc, char* argv[]){
158         // Initialise the several libraries that have
159         // been included.
160         
161         ::testing::InitGoogleTest(&argc, argv);
162         curl_global_init(CURL_GLOBAL_ALL);
163         
164         printn("Xestia Calendar Unit Testing Application");
165         printn("(c)2016 Xestia Software Development");
166         printn("Note: Unit testing is currently in development");
167         printn("");
169         bool exitEnabled = false;
170         std::string stringOption = "";
171         int testResult = 0;
173         while(exitEnabled == false){
174         
175                 printmenu();
177                 // Get user input.
179                 std::cout << "Select Option: "; 
180                 std::cin >> stringOption;
181                 
182                 int intOption = -1;
183                 
184                 // Check if input is a number.
185                 
186                 try{
187                         intOption = stoi(stringOption);
188                 }
189                 
190                 // Return to the top of the while statement if input
191                 // really isn't a number.
192                 
193                 catch(std::invalid_argument e){
194                         printn("Error: Selected option is not a number.");
195                         continue;
196                 }
197                 
198                 // Find which option has been selected from the
199                 // input.
200                 
201                 switch(intOption){
202                 
203                         case TESTS_ICALLOADEVENT:
204                                 printn("Running iCalendar Event Component tests...");
205                                 ::testing::GTEST_FLAG(filter) = "iCalendarEvent*";
206                                 testResult = RUN_ALL_TESTS();
207                                 break;
208                         case TESTS_ICALSAVEEVENT:
209                                 printn("Running iCalendar Event Component Save tests...");
210                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveEvent*";
211                                 testResult = RUN_ALL_TESTS();
212                                 break;
213                         case TESTS_ICALLOADTODO:
214                                 printn("Running iCalendar Task Component tests...");
215                                 ::testing::GTEST_FLAG(filter) = "iCalendarTask*";
216                                 testResult = RUN_ALL_TESTS();
217                                 break;
218                         case TESTS_ICALSAVETODO:
219                                 printn("Running iCalendar Task Component Save tests...");
220                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveTask*";
221                                 testResult = RUN_ALL_TESTS();
222                                 break;
223                         case TESTS_ICALLOADJOURNAL:
224                                 printn("Running iCalendar Journal Component tests...");
225                                 ::testing::GTEST_FLAG(filter) = "iCalendarJournal*";
226                                 testResult = RUN_ALL_TESTS();
227                                 break;
228                         case TESTS_ICALSAVEJOURNAL:
229                                 printn("Running iCalendar Journal Component Save tests...");
230                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveJournal*";
231                                 testResult = RUN_ALL_TESTS();
232                                 break;
233                         case TESTS_ICALLOADFREEBUSY:
234                                 printn("Running iCalendar Free Busy Component tests...");
235                                 ::testing::GTEST_FLAG(filter) = "iCalendarFreeBusy*";
236                                 testResult = RUN_ALL_TESTS();
237                                 break;
238                         case TESTS_ICALSAVEFREEBUSY:
239                                 printn("Running iCalendar Free Busy Component Save tests...");
240                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveFreeBusy*";
241                                 testResult = RUN_ALL_TESTS();
242                                 break;
243                         case TESTS_ICALLOADTIMEZONE:
244                                 printn("Running iCalendar Timezone Component tests...");
245                                 ::testing::GTEST_FLAG(filter) = "iCalendarTimezone*";
246                                 testResult = RUN_ALL_TESTS();
247                                 break;
248                         case TESTS_ICALSAVETIMEZONE:
249                                 printn("Running iCalendar Timezone Component Save tests...");
250                                 ::testing::GTEST_FLAG(filter) = "iCalendarSaveTimezone*";
251                                 testResult = RUN_ALL_TESTS();
252                                 break;
253                         case TESTS_CALENDARDATASTORAGE:
254                                 printn("Running Calendar Data Storage tests...");
255                                 ::testing::GTEST_FLAG(filter) = "CalendarDataStorage*";
256                                 testResult = RUN_ALL_TESTS();
257                                 break;
258                         case TESTS_CALDAV:
259                                 printn("Running CalDAV tests...");
260                                 ::testing::GTEST_FLAG(filter) = "CalDAV*";
261                                 testResult = RUN_ALL_TESTS();
262                                 break;
263                         case TESTS_COMMONFUNCTIONS:
264                                 printn("Running Commmon Functions tests...");
265                                 ::testing::GTEST_FLAG(filter) = "CommonFunctions*";
266                                 testResult = RUN_ALL_TESTS();
267                                 break;
268                         case TESTS_EXTRA:
269                                 runextramenu();
270                                 break;
271                         case TESTS_QUIT:
272                                 return 0;
273                                 break;
274                         default:
275                                 printn("Invalid menu number given."); 
276                                 break;
277                 
278                 }
279         
280         }
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