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