1 // xestiacalendar_test.cpp - Xestia Calendar Unit Testing Suite.
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar 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.
11 // Xestia Calendar 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.
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>
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_icaltimezonesave.h"
37 #include "xestiacalendar_calendardatastorage.h"
38 #include "xestiacalendar_caldav.h"
41 TESTS_ICALLOADEVENT = 1,
45 TESTS_ICALLOADJOURNAL,
46 TESTS_ICALSAVEJOURNAL,
47 TESTS_ICALLOADFREEBUSY,
48 TESTS_ICALSAVEFREEBUSY,
49 TESTS_ICALLOADTIMEZONE,
50 TESTS_ICALSAVETIMEZONE,
51 TESTS_CALENDARDATASTORAGE,
53 TESTS_COMMONFUNCTIONS,
59 EXTRA_POPULATECALDAV = 1,
63 void printn(std::string text){
64 // printn: Print a line and end with a newline (\n).
66 std::cout << text << std::endl;
71 // printmenu: Print the menu.
73 std::cout << "Select an option:" << std::endl << std::endl;
74 std::cout << TESTS_ICALLOADEVENT << ". iCalendar Event Component Load" << std::endl;
75 std::cout << TESTS_ICALSAVEEVENT << ". iCalendar Event Component Save" << std::endl;
76 std::cout << TESTS_ICALLOADTODO << ". iCalendar Task Component Load" << std::endl;
77 std::cout << TESTS_ICALSAVETODO << ". iCalendar Task Component Save" << std::endl;
78 std::cout << TESTS_ICALLOADJOURNAL << ". iCalendar Journal Component Load" << std::endl;
79 std::cout << TESTS_ICALSAVEJOURNAL << ". iCalendar Journal Component Save" << std::endl;
80 std::cout << TESTS_ICALLOADFREEBUSY << ". iCalendar FreeBusy Component Load" << std::endl;
81 std::cout << TESTS_ICALSAVEFREEBUSY << ". iCalendar FreeBusy Component Save" << std::endl;
82 std::cout << TESTS_ICALLOADTIMEZONE << ". iCalendar Timezone Component Load" << std::endl;
83 std::cout << TESTS_ICALSAVETIMEZONE << ". iCalendar Timezone Component Save" << std::endl;
84 std::cout << TESTS_CALENDARDATASTORAGE << ". Calendar Data Storage" << std::endl;
85 std::cout << TESTS_CALDAV << ". CalDAV Object" << std::endl;
86 std::cout << TESTS_COMMONFUNCTIONS << ". Common Functions" << std::endl;
87 std::cout << TESTS_EXTRA << ". Extra Functions Menu" << std::endl;
88 std::cout << TESTS_QUIT << ". Quit" << std::endl;
89 std::cout << std::endl;
93 void printextramenu(){
95 std::cout << "Extra Functions Menu" << std::endl << std::endl;
96 std::cout << "Select an option:" << std::endl << std::endl;
97 std::cout << EXTRA_POPULATECALDAV << ". Populate CalDAV calendar" << std::endl;
98 std::cout << EXTRA_RETURN << ". Return to previous menu" << std::endl;
99 std::cout << std::endl;
105 bool exitEnabled = false;
106 std::string stringOption = "";
109 while(exitEnabled == false){
115 std::cout << "Select Option: ";
116 std::cin >> stringOption;
120 // Check if input is a number.
123 intOption = stoi(stringOption);
126 // Return to the top of the while statement if input
127 // really isn't a number.
129 catch(std::invalid_argument e){
130 printn("Error: Selected option is not a number.");
134 // Find which option has been selected from the
139 case EXTRA_POPULATECALDAV:
140 printn("Populating CalDAV calendar...");
147 printn("Invalid menu number given.");
156 int main(int argc, char* argv[]){
158 // Initialise the several libraries that have
161 ::testing::InitGoogleTest(&argc, argv);
162 curl_global_init(CURL_GLOBAL_ALL);
164 printn("Xestia Calendar Unit Testing Application");
165 printn("(c)2016 Xestia Software Development");
166 printn("Note: Unit testing is currently in development");
169 bool exitEnabled = false;
170 std::string stringOption = "";
173 while(exitEnabled == false){
179 std::cout << "Select Option: ";
180 std::cin >> stringOption;
184 // Check if input is a number.
187 intOption = stoi(stringOption);
190 // Return to the top of the while statement if input
191 // really isn't a number.
193 catch(std::invalid_argument e){
194 printn("Error: Selected option is not a number.");
198 // Find which option has been selected from the
203 case TESTS_ICALLOADEVENT:
204 printn("Running iCalendar Event Component tests...");
205 ::testing::GTEST_FLAG(filter) = "iCalendarEvent*";
206 testResult = RUN_ALL_TESTS();
208 case TESTS_ICALSAVEEVENT:
209 printn("Running iCalendar Event Component Save tests...");
210 ::testing::GTEST_FLAG(filter) = "iCalendarSaveEvent*";
211 testResult = RUN_ALL_TESTS();
213 case TESTS_ICALLOADTODO:
214 printn("Running iCalendar Task Component tests...");
215 ::testing::GTEST_FLAG(filter) = "iCalendarTask*";
216 testResult = RUN_ALL_TESTS();
218 case TESTS_ICALSAVETODO:
219 printn("Running iCalendar Task Component Save tests...");
220 ::testing::GTEST_FLAG(filter) = "iCalendarSaveTask*";
221 testResult = RUN_ALL_TESTS();
223 case TESTS_ICALLOADJOURNAL:
224 printn("Running iCalendar Journal Component tests...");
225 ::testing::GTEST_FLAG(filter) = "iCalendarJournal*";
226 testResult = RUN_ALL_TESTS();
228 case TESTS_ICALSAVEJOURNAL:
229 printn("Running iCalendar Journal Component Save tests...");
230 ::testing::GTEST_FLAG(filter) = "iCalendarSaveJournal*";
231 testResult = RUN_ALL_TESTS();
233 case TESTS_ICALLOADFREEBUSY:
234 printn("Running iCalendar Free Busy Component tests...");
235 ::testing::GTEST_FLAG(filter) = "iCalendarFreeBusy*";
236 testResult = RUN_ALL_TESTS();
238 case TESTS_ICALSAVEFREEBUSY:
239 printn("Running iCalendar Free Busy Component Save tests...");
240 ::testing::GTEST_FLAG(filter) = "iCalendarSaveFreeBusy*";
241 testResult = RUN_ALL_TESTS();
243 case TESTS_ICALLOADTIMEZONE:
244 printn("Running iCalendar Timezone Component tests...");
245 ::testing::GTEST_FLAG(filter) = "iCalendarTimezone*";
246 testResult = RUN_ALL_TESTS();
248 case TESTS_ICALSAVETIMEZONE:
249 printn("Running iCalendar Timezone Component Save tests...");
250 ::testing::GTEST_FLAG(filter) = "iCalendarSaveTimezone*";
251 testResult = RUN_ALL_TESTS();
253 case TESTS_CALENDARDATASTORAGE:
254 printn("Running Calendar Data Storage tests...");
255 ::testing::GTEST_FLAG(filter) = "CalendarDataStorage*";
256 testResult = RUN_ALL_TESTS();
259 printn("Running CalDAV tests...");
260 ::testing::GTEST_FLAG(filter) = "CalDAV*";
261 testResult = RUN_ALL_TESTS();
263 case TESTS_COMMONFUNCTIONS:
264 printn("Running Commmon Functions tests...");
265 ::testing::GTEST_FLAG(filter) = "CommonFunctions*";
266 testResult = RUN_ALL_TESTS();
275 printn("Invalid menu number given.");