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