Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the tests...
[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_vcard.h"
27 enum MenuOpts {
28         TESTS_CARDDAV = 1, 
29         TESTS_CONTACTLOAD,
30         TESTS_CONTACTSAVE, 
31         TESTS_VCARD,
32         TESTS_ALL,
33         TESTS_QUIT
34 };
36 void printn(std::string text){
37 // printn: Print a line and end with a newline (\n).
39         std::cout << text << std::endl;
41 }
43 void printmenu(){
44 // printmenu: Print the menu.
46         std::cout << "Select an option:" << std::endl << std::endl;
47         std::cout << TESTS_CARDDAV << ". CardDAV Object" << std::endl;
48         std::cout << TESTS_CONTACTLOAD << ". Contact Loading" << std::endl;
49         std::cout << TESTS_CONTACTSAVE << ". Contact Saving" << std::endl;
50         std::cout << TESTS_VCARD << ". vCard Object" << std::endl;
51         std::cout << TESTS_ALL << ". All Tests" << std::endl;
52         std::cout << TESTS_QUIT << ". Quit" << std::endl;
53         std::cout << std::endl;
55 }
57 int main(int argc, char* argv[]){
59         ::testing::InitGoogleTest(&argc, argv);
61         printn("Xestia Address Book Unit Testing Application");
62         printn("(c)2015 Xestia Software Development");
63         printn("Note: Unit testing is currently in development");
64         printn("");
66         bool ExitEnabled = false;
67         std::string StringOption = "";
68         int TestResult = 0;
70         while(ExitEnabled == false){
71         
72                 printmenu();
74                 // Get user input.
76                 std::cout << "Select Option: "; 
77                 std::cin >> StringOption;
78                 
79                 int IntOption = -1;
80                 
81                 // Check if input is a number.
82                 
83                 try{
84                         IntOption = stoi(StringOption);
85                 }
86                 
87                 // Return to the top of the while statement if input
88                 // really isn't a number.
89                 
90                 catch(std::invalid_argument e){
91                         printn("Error: Selected option is not a number.");
92                         continue;
93                 }
94                 
95                 // Find which option has been selected from the
96                 // input.
97                 
98                 switch(IntOption){
99                 
100                         case TESTS_CARDDAV:
101                                 printn("Running CardDAV tests...");
102                                 ::testing::GTEST_FLAG(filter) = "CardDAV*";
103                                 TestResult = RUN_ALL_TESTS();
104                                 break;
105                         case TESTS_CONTACTLOAD:
106                                 printn("Running Contact Loading tests...");
107                                 ::testing::GTEST_FLAG(filter) = "ContactLoad*";
108                                 TestResult = RUN_ALL_TESTS();
109                                 break;
110                         case TESTS_CONTACTSAVE:
111                                 printn("Running Contact Saving tests...");
112                                 ::testing::GTEST_FLAG(filter) = "ContactSave*";
113                                 TestResult = RUN_ALL_TESTS();
114                                 break;
115                         case TESTS_VCARD:
116                                 printn("Running vCard tests...");
117                                 ::testing::GTEST_FLAG(filter) = "vCard*";
118                                 TestResult = RUN_ALL_TESTS();
119                                 break;
120                         case TESTS_ALL:
121                                 printn("Running all tests...");
122                                 ::testing::GTEST_FLAG(filter) = "*";
123                                 TestResult = RUN_ALL_TESTS();
124                                 break;
125                         case TESTS_QUIT:
126                                 return 0;
127                                 break;
128                         default:
129                                 printn("Invalid menu number given."); 
130                                 break;
131                 
132                 }
133         
134         }
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