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