Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added menu option for Contact Conversion tests to the unit test application.
[xestiaab/.git] / source / tests / xestiaab_test.cpp
1 // xestiaab_test.cpp - Xestia Address Book Unit Testing Suite.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
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 Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <gtest/gtest.h>
20 #include <iostream>
21 #include <string>
22 #include "xestiaab_carddav.h"
23 #include "xestiaab_contactload.h"
24 #include "xestiaab_contactsave.h"
25 #include "xestiaab_convert.h"
26 #include "xestiaab_vcard.h"
28 enum MenuOpts {
29         TESTS_CARDDAV = 1, 
30         TESTS_CONTACTLOAD,
31         TESTS_CONTACTSAVE, 
32         TESTS_VCARD,
33         TESTS_CONVERT,
34         TESTS_ALL,
35         TESTS_QUIT
36 };
38 void printn(std::string text){
39 // printn: Print a line and end with a newline (\n).
41         std::cout << text << std::endl;
43 }
45 void printmenu(){
46 // printmenu: Print the menu.
48         std::cout << "Select an option:" << std::endl << std::endl;
49         std::cout << TESTS_CARDDAV << ". CardDAV Object" << std::endl;
50         std::cout << TESTS_CONTACTLOAD << ". Contact Loading" << std::endl;
51         std::cout << TESTS_CONTACTSAVE << ". Contact Saving" << std::endl;
52         std::cout << TESTS_VCARD << ". vCard Object" << std::endl;
53         std::cout << TESTS_CONVERT << ". Contact Conversion" << std::endl;
54         std::cout << TESTS_ALL << ". All Tests" << std::endl;
55         std::cout << TESTS_QUIT << ". Quit" << std::endl;
56         std::cout << std::endl;
58 }
60 int main(int argc, char* argv[]){
62         ::testing::InitGoogleTest(&argc, argv);
64         printn("Xestia Address Book Unit Testing Application");
65         printn("(c)2015 Xestia Software Development");
66         printn("Note: Unit testing is currently in development");
67         printn("");
69         bool ExitEnabled = false;
70         std::string StringOption = "";
71         int TestResult = 0;
73         while(ExitEnabled == false){
74         
75                 printmenu();
77                 // Get user input.
79                 std::cout << "Select Option: "; 
80                 std::cin >> StringOption;
81                 
82                 int IntOption = -1;
83                 
84                 // Check if input is a number.
85                 
86                 try{
87                         IntOption = stoi(StringOption);
88                 }
89                 
90                 // Return to the top of the while statement if input
91                 // really isn't a number.
92                 
93                 catch(std::invalid_argument e){
94                         printn("Error: Selected option is not a number.");
95                         continue;
96                 }
97                 
98                 // Find which option has been selected from the
99                 // input.
100                 
101                 switch(IntOption){
102                 
103                         case TESTS_CARDDAV:
104                                 printn("Running CardDAV tests...");
105                                 ::testing::GTEST_FLAG(filter) = "CardDAV*";
106                                 TestResult = RUN_ALL_TESTS();
107                                 break;
108                         case TESTS_CONTACTLOAD:
109                                 printn("Running Contact Loading tests...");
110                                 ::testing::GTEST_FLAG(filter) = "ContactLoad*";
111                                 TestResult = RUN_ALL_TESTS();
112                                 break;
113                         case TESTS_CONTACTSAVE:
114                                 printn("Running Contact Saving tests...");
115                                 ::testing::GTEST_FLAG(filter) = "ContactSave*";
116                                 TestResult = RUN_ALL_TESTS();
117                                 break;
118                         case TESTS_CONVERT:
119                                 printn("Running Contact Conversion tests...");
120                                 ::testing::GTEST_FLAG(filter) = "ConvertCmdLine*";
121                                 TestResult = RUN_ALL_TESTS();
122                                 break;
123                         case TESTS_VCARD:
124                                 printn("Running vCard tests...");
125                                 ::testing::GTEST_FLAG(filter) = "vCard*";
126                                 TestResult = RUN_ALL_TESTS();
127                                 break;
128                         case TESTS_ALL:
129                                 printn("Running all tests...");
130                                 ::testing::GTEST_FLAG(filter) = "*";
131                                 TestResult = RUN_ALL_TESTS();
132                                 break;
133                         case TESTS_QUIT:
134                                 return 0;
135                                 break;
136                         default:
137                                 printn("Invalid menu number given."); 
138                                 break;
139                 
140                 }
141         
142         }
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