server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / libmapi++ / tests / profile_test.cpp
1 /*
2    libmapi C++ Wrapper
3
4    Test application for profile database and profile classes
5
6    Copyright (C) Brad Hards <bradh@openchange.org> 2010.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <exception>
23 #include <vector>
24 #include <string>
25
26 #include <libmapi++/libmapi++.h>
27 #define PROFILEDB_NAME_TEMPLATE "/tmp/mapidbXXXXXX"
28 int main ()
29 {
30         try {
31                 libmapipp::profile_database db;
32
33                 std::cout << "default profile name: " << db.get_default_profile_name() << std::endl;
34
35                 {
36                         char *tmpname = (char*) calloc(sizeof(PROFILEDB_NAME_TEMPLATE) + 1, sizeof(char));
37                         strncpy(tmpname, PROFILEDB_NAME_TEMPLATE, sizeof(PROFILEDB_NAME_TEMPLATE));
38                         int ret = mkstemp(tmpname);
39                         if (ret < 0) {
40                                 std::cout << "failed to create temporary file: " << strerror(errno) << std::endl;
41                         }
42                         if (libmapipp::profile_database::create_profile_store(tmpname)) {
43                                 std::cout << "success creating a temporary profile store" << std::endl;
44                         } else {
45                                 std::cout << "failed to create a temporary profile store" << std::endl;
46                         }
47                         unlink(tmpname);
48                 }
49                 
50                 {
51                         char *tmpname2 = (char*) calloc(sizeof(PROFILEDB_NAME_TEMPLATE) + 1, sizeof(char));
52                         strncpy(tmpname2, PROFILEDB_NAME_TEMPLATE, sizeof(PROFILEDB_NAME_TEMPLATE));
53                         int ret = mkstemp(tmpname2);
54                         if (ret < 0) {
55                                 std::cout << "failed to create temporary file: " << strerror(errno) << std::endl;
56                         }
57                         if (libmapipp::profile_database::create_profile_store(std::string(tmpname2))) {
58                                 std::cout << "success creating a temporary profile store with std::string" << std::endl;
59                         } else {
60                                 std::cout << "failed to create a temporary profile store with std::string" << std::endl;
61                         }
62                         unlink(tmpname2);
63                 }
64
65                 std::cout << "finished profile and profile database tests" << std::endl;
66         }
67         catch (libmapipp::mapi_exception e) // Catch any mapi exceptions
68         {
69                 std::cout << "MAPI Exception @ main: " <<  e.what() << std::endl;
70         }
71         catch (std::runtime_error e) // Catch runtime exceptions
72         {
73                 std::cout << "std::runtime_error exception @ main: " << e.what() << std::endl;
74
75         }
76
77         return 0;
78 }