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