Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added option to populate a CalDAV calendar in the unit testing application
[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_icaltaskload.h"
29 #include "xestiacalendar_icaljournalload.h"
30 #include "xestiacalendar_icalfreebusyload.h"
31 #include "xestiacalendar_icaltimezoneload.h"
32 #include "xestiacalendar_caldav.h"
34 enum MenuOpts {
35         TESTS_ICALLOADEVENT = 1,
36         TESTS_ICALLOADTODO,
37         TESTS_ICALLOADJOURNAL,
38         TESTS_ICALLOADFREEBUSY,
39         TESTS_ICALLOADTIMEZONE,
40         TESTS_CALDAV,
41         TESTS_COMMONFUNCTIONS,
42         TESTS_EXTRA,
43         TESTS_QUIT
44 };
46 enum ExtraMenuOpts{
47         EXTRA_POPULATECALDAV = 1,
48         EXTRA_RETURN
49 };
51 void printn(std::string text){
52 // printn: Print a line and end with a newline (\n).
54         std::cout << text << std::endl;
56 }
58 void printmenu(){
59 // printmenu: Print the menu.
61         std::cout << "Select an option:" << std::endl << std::endl;
62         std::cout << TESTS_ICALLOADEVENT << ". iCalendar Event Component Load" << std::endl;
63         std::cout << TESTS_ICALLOADTODO << ". iCalendar Task Component Load" << std::endl;
64         std::cout << TESTS_ICALLOADJOURNAL << ". iCalendar Journal Component Load" << std::endl;
65         std::cout << TESTS_ICALLOADFREEBUSY << ". iCalendar FreeBusy Component Load" << std::endl;
66         std::cout << TESTS_ICALLOADTIMEZONE << ". iCalendar Timezone Component Load" << std::endl;
67         std::cout << TESTS_CALDAV << ". CalDAV Object" << std::endl;
68         std::cout << TESTS_COMMONFUNCTIONS << ". Common Functions" << std::endl;
69         std::cout << TESTS_EXTRA << ". Extra Functions Menu" << std::endl;
70         std::cout << TESTS_QUIT << ". Quit" << std::endl;
71         std::cout << std::endl;
73 }
75 void printextramenu(){
77         std::cout << "Extra Functions Menu" << std::endl << std::endl;
78         std::cout << "Select an option:" << std::endl << std::endl;     
79         std::cout << EXTRA_POPULATECALDAV << ". Populate CalDAV calendar" << std::endl;
80         std::cout << EXTRA_RETURN << ". Return to previous menu" << std::endl;
81         std::cout << std::endl;
82         
83 }
85 void runextramenu(){
86         
87         bool ExitEnabled = false;
88         std::string StringOption = "";
89         int TestResult = 0;
91         while(ExitEnabled == false){
92         
93                 printextramenu();
95                 // Get user input.
97                 std::cout << "Select Option: "; 
98                 std::cin >> StringOption;
99                 
100                 int IntOption = -1;
101                 
102                 // Check if input is a number.
103                 
104                 try{
105                         IntOption = stoi(StringOption);
106                 }
107                 
108                 // Return to the top of the while statement if input
109                 // really isn't a number.
110                 
111                 catch(std::invalid_argument e){
112                         printn("Error: Selected option is not a number.");
113                         continue;
114                 }
115                 
116                 // Find which option has been selected from the
117                 // input.
118                 
119                 switch(IntOption){
120                 
121                         case EXTRA_POPULATECALDAV:
122                                 printn("Populating CalDAV calendar...");
123                                 populatecaldav();
124                                 break;
125                         case EXTRA_RETURN:
126                                 return;
127                                 break;
128                         default:
129                                 printn("Invalid menu number given."); 
130                                 break;
131                 
132                 }
133         
134         }
135         
138 int main(int argc, char* argv[]){
140         // Initialise the several libraries that have
141         // been included.
142         
143         ::testing::InitGoogleTest(&argc, argv);
144         curl_global_init(CURL_GLOBAL_ALL);
145         
146         printn("Xestia Calendar Unit Testing Application");
147         printn("(c)2016 Xestia Software Development");
148         printn("Note: Unit testing is currently in development");
149         printn("");
151         bool ExitEnabled = false;
152         std::string StringOption = "";
153         int TestResult = 0;
155         while(ExitEnabled == false){
156         
157                 printmenu();
159                 // Get user input.
161                 std::cout << "Select Option: "; 
162                 std::cin >> StringOption;
163                 
164                 int IntOption = -1;
165                 
166                 // Check if input is a number.
167                 
168                 try{
169                         IntOption = stoi(StringOption);
170                 }
171                 
172                 // Return to the top of the while statement if input
173                 // really isn't a number.
174                 
175                 catch(std::invalid_argument e){
176                         printn("Error: Selected option is not a number.");
177                         continue;
178                 }
179                 
180                 // Find which option has been selected from the
181                 // input.
182                 
183                 switch(IntOption){
184                 
185                         case TESTS_ICALLOADEVENT:
186                                 printn("Running iCalendar Event Component tests...");
187                                 ::testing::GTEST_FLAG(filter) = "iCalendarEvent*";
188                                 TestResult = RUN_ALL_TESTS();
189                                 break;
190                         case TESTS_ICALLOADTODO:
191                                 printn("Running iCalendar Task Component tests...");
192                                 ::testing::GTEST_FLAG(filter) = "iCalendarTask*";
193                                 TestResult = RUN_ALL_TESTS();
194                                 break;
195                         case TESTS_ICALLOADJOURNAL:
196                                 printn("Running iCalendar Journal Component tests...");
197                                 ::testing::GTEST_FLAG(filter) = "iCalendarJournal*";
198                                 TestResult = RUN_ALL_TESTS();
199                                 break;
200                         case TESTS_ICALLOADFREEBUSY:
201                                 printn("Running iCalendar Free Busy Component tests...");
202                                 ::testing::GTEST_FLAG(filter) = "iCalendarFreeBusy*";
203                                 TestResult = RUN_ALL_TESTS();
204                                 break;
205                         case TESTS_ICALLOADTIMEZONE:
206                                 printn("Running iCalendar Free Busy Component tests...");
207                                 ::testing::GTEST_FLAG(filter) = "iCalendarTimezone*";
208                                 TestResult = RUN_ALL_TESTS();
209                                 break;
210                         case TESTS_CALDAV:
211                                 printn("Running CalDAV tests...");
212                                 ::testing::GTEST_FLAG(filter) = "CalDAV*";
213                                 TestResult = RUN_ALL_TESTS();
214                                 break;
215                         case TESTS_COMMONFUNCTIONS:
216                                 printn("Running Commmon Functions tests...");
217                                 ::testing::GTEST_FLAG(filter) = "CommonFunctions*";
218                                 TestResult = RUN_ALL_TESTS();
219                                 break;
220                         case TESTS_EXTRA:
221                                 runextramenu();
222                                 break;
223                         case TESTS_QUIT:
224                                 return 0;
225                                 break;
226                         default:
227                                 printn("Invalid menu number given."); 
228                                 break;
229                 
230                 }
231         
232         }
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