Merge trunk changes (from r2196 up to 2259) into branch
[jelmer/openchange.git] / utils / mapitest / mapitest.h
1 /*
2    Stand-alone MAPI testsuite
3
4    OpenChange Project
5
6    Copyright (C) Julien Kerihuel 2008
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 #ifndef __MAPITEST_H__
23 #define __MAPITEST_H__
24
25 #include "libmapi/libmapi.h"
26
27 #include <errno.h>
28 #include <err.h>
29
30 /* forward declaration */
31 struct mapitest;
32 struct mapitest_suite;
33
34
35 /**
36         \file mapitest.h
37         Data structures for %mapitest
38  */
39
40 /**
41   Flags for changing test applicability
42   
43   If you add values here, you also need to add a matching description to
44   applicabilityFlagsDescription and suitable logic to
45   mapitest_suite_test_is_applicable().
46 */
47 enum TestApplicabilityFlags {
48         ApplicableToAllVersions = 0,    /*!< This test is always applicable */
49         NotInExchange2010 = 0x1,        /*!< This test is not applicable to Exchange 2010 */
50         NotInExchange2010SP0 = 0x2,     /*!< This test is not applicable to Exchange 2010
51                                              Service Pack 0, but is applicable to later versions */
52         ExpectedFail = 0x8000,          /*!< This test is expected to fail */
53         LastTestApplicabilityFlag = 0xFFFF
54 };
55
56 /**
57   List of possible test results
58 */
59 enum TestResult {
60         Pass,                   /*!< The test was expected to pass, and it did */
61         Fail,                   /*!< The test was expected to pass, but it failed */
62         UnexpectedPass,         /*!< The test was expected to fail, but it passed instead */
63         ExpectedFailure         /*!< The test was expected to fail, and it did */
64 };
65
66 #include "utils/mapitest/proto.h"
67
68 /**
69         A list of %mapitest tests
70
71         %mapitest tests are grouped into test suites. This linked
72         list data structure represents the various tests as a
73         list of tests (i.e. the linked list is a suite of tests).
74
75         The function that executes the test is pointed to by the
76         fn element (i.e. fn is a function pointer).
77 */
78 struct mapitest_test {
79         struct mapitest_test            *prev;          /*!< The previous test in the list */
80         struct mapitest_test            *next;          /*!< The next test in the list */
81         char                            *name;          /*!< The name of this test */
82         char                            *description;   /*!< The description of this test */
83         void                            *fn;            /*!< pointer to the test function */
84         enum TestApplicabilityFlags     flags;          /*!< any applicability for this test */
85 };
86
87 /**
88         List of test names
89
90         This linked list data structure has a list of names of tests. It is
91         used with mapitest_stat to record the failed tests.
92 */
93 struct mapitest_unit {
94         struct mapitest_unit    *prev;          /*!< The previous test in the list */
95         struct mapitest_unit    *next;          /*!< The next test in the list */
96         char                    *name;          /*!< The name of the test */
97         char                    *reason;        /*!< Why this test was skipped or failed (if applicable) */
98 };
99
100 /**
101         %mapitest statistics
102
103         During a %mapitest run, %mapitest collects statistics on each test suite.
104
105         This data structure records the results for one run of a test suite.
106
107         There should be one entry in the failure_info list for each failure.
108 */
109 struct mapitest_stat {
110         uint32_t                success;        /*!< Number of tests in this suite that passed */
111         uint32_t                failure;        /*!< Number of tests in this suite that failed */
112         uint32_t                skipped;        /*!< Number of tests in this suite that were skipped */
113         uint32_t                x_fail;         /*!< Number of tests in this suite that were expected failures */
114         struct mapitest_unit    *failure_info;  /*!< List of names of the tests that failed */
115         struct mapitest_unit    *skip_info;     /*!< List of names of the tests that were skipped, and why */
116         bool                    enabled;        /*!< Whether this statistics structure is valid */
117 };
118
119 /**
120         A list of test suites
121
122         %mapitest executes a set of tests. Those tests are grouped into
123         suites of related tests (e.g. all tests that do not require a 
124         server are in one suite, the tests for NSPI are in another suite,
125         and so on). This linked list data structure represents the various
126         test suites to be executed.
127 */
128 struct mapitest_suite {
129         struct mapitest_suite   *prev;        /*!< Pointer to the previous test suite */
130         struct mapitest_suite   *next;        /*!< Pointer to the next test suite */
131         char                    *name;        /*!< The name of the test suite */
132         char                    *description; /*!< Description of the test suite */
133         bool                    online;       /*!< Whether this suite requires a server */
134         struct mapitest_test    *tests;       /*!< The tests in this suite */
135         struct mapitest_stat    *stat;        /*!< Results of running this test */
136 };
137
138 /**
139         The context structure for a %mapitest run
140 */
141 struct mapitest {
142         TALLOC_CTX              *mem_ctx;       /*!< talloc memory context for memory allocations */
143         struct mapi_context     *mapi_ctx;      /*!< mapi context */
144         struct mapi_session     *session;
145         bool                    confidential;   /*!< true if confidential information should be omitted */
146         bool                    no_server;      /*!< true if only non-server tests should be run */
147         bool                    mapi_all;       /*!< true if all tests should be run */
148         bool                    online;         /*!< true if the server could be accessed */
149         bool                    color;          /*!< true if the output should be colored */
150         bool                    subunit_output; /*!< true if we should write output in subunit protocol format */
151         struct emsmdb_info      info;
152         struct mapi_profile     *profile;
153         struct mapitest_suite   *mapi_suite;    /*!< the various test suites */
154         struct mapitest_unit    *cmdline_calls;
155         struct mapitest_unit    *cmdline_suite;
156         const char              *org;
157         const char              *org_unit;
158         FILE                    *stream;
159         void                    *priv;
160 };
161
162 struct mapitest_module {
163         char                    *name;
164         
165 };
166
167 /**
168    Context for %mapitest test folder
169 */
170 struct mt_common_tf_ctx
171 {
172         mapi_object_t   obj_store;
173         mapi_object_t   obj_top_folder;
174         mapi_object_t   obj_test_folder;
175         mapi_object_t   obj_test_msg[10];
176 };
177
178
179 /*
180  *  Defines
181  */
182 #define MAPITEST_SUCCESS        0
183 #define MAPITEST_ERROR          -1
184
185 #define MT_STREAM_MAX_SIZE      0x3000
186
187 #define MT_YES                  "[yes]"
188 #define MT_NO                   "[no]"
189
190 #define MT_CONFIDENTIAL "[Confidential]"
191
192 #define MT_HDR_START            "#############################[mapitest report]#################################\n"
193 #define MT_HDR_END              "###############################################################################\n"
194 #define MT_HDR_FMT              "[*] %-25s: %-20s\n"
195 #define MT_HDR_FMT_DATE         "[*] %-25s: %-20s"
196 #define MT_HDR_FMT_SECTION      "[*] %-25s:\n"
197 #define MT_HDR_FMT_SUBSECTION   "%-21s: %-10s\n"
198 #define MT_HDR_FMT_VER_NORM     "%-21s: %02d.%02d.%04d.%04d\n"
199
200 #define MT_DIRNAME_TOP          "[MT] Top of Mailbox"
201 #define MT_DIRNAME_APPOINTMENT  "[MT] Calendar"
202 #define MT_DIRNAME_CONTACT      "[MT] Contact"
203 #define MT_DIRNAME_JOURNAL      "[MT] Journal"
204 #define MT_DIRNAME_POST         "[MT] Post"
205 #define MT_DIRNAME_NOTE         "[MT] Note"
206 #define MT_DIRNAME_STICKYNOTE   "[MT] Sticky Notes"
207 #define MT_DIRNAME_TASK         "[MT] Tasks"
208 #define MT_DIRNAME_TEST         "[MT] Test Folder1"
209
210 #define MT_MAIL_SUBJECT         "[MT] Sample E-MAIL"
211 #define MT_MAIL_ATTACH          "Attach1.txt"
212 #define MT_MAIL_ATTACH2         "Attach2.txt"
213
214 #define MODULE_TITLE            "[MODULE] %s\n"
215 #define MODULE_TITLE_DELIM      '#'
216 #define MODULE_TITLE_NEWLINE    2
217 #define MODULE_TITLE_LINELEN    80
218
219 #define MODULE_TEST_TITLE       "[TEST] %s\n"
220 #define MODULE_TEST_RESULT      "[RESULT] %s: %s\n"
221 #define MODULE_TEST_DELIM       '-'
222 #define MODULE_TEST_DELIM2      '='
223 #define MODULE_TEST_LINELEN     72
224 #define MODULE_TEST_NEWLINE     1
225 #define MODULE_TEST_SUCCESS     "[SUCCESS]"
226 #define MODULE_TEST_FAILURE     "[FAILURE]"
227
228 #define MT_ERROR        "[ERROR]: %s\n"
229
230 #define MT_STAT_FAILED_TITLE    "[STAT] FAILED TEST CASES\n"
231 #define MT_STAT_RESULT  "* %-35s: %s (%s)\n"
232 #define MT_STAT_SKIPPED_TITLE   "[STAT] SKIPPED TEST CASES\n"
233
234 #define MT_SUMMARY_TITLE "[STAT] TEST SUMMARY\n"
235
236 #define MT_WHITE           "\033[0;29m"
237 #define MT_RED             "\033[1;31m"
238 #define MT_GREEN           "\033[1;32m"
239
240 #define Exchange2010SP0Version  0x0E00
241
242 #endif /* !__MAPITEST_H__ */