edfd83b48402c41a1f9376cc08e2cc70d6defc91
[jelmer/openchange.git] / utils / mapitest / modules / module_mapidump.c
1 /*
2    Stand-alone MAPI testsuite
3
4    OpenChange Project - mapidump function tests
5
6    Copyright (C) Brad Hards 2009
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 "utils/mapitest/mapitest.h"
23 #include "utils/mapitest/proto.h"
24
25 /**
26    \file module_mapidump.c
27
28    \brief mapidump function tests
29
30    \note These tests do not show how to use libmapi properly, and should
31   not be used as a programming reference.
32 */
33
34 /**
35    \details Test dump using mapidump_SPropValue
36
37    This function:
38    -# Tests the mapidump_SPropValue() function 
39
40    \param mt pointer to the top-level mapitest structure
41
42    \return true on success, otherwise false
43    
44    \note This currently doesn't check the results are sane, so manual inspection is required
45 */ 
46 _PUBLIC_ bool mapitest_mapidump_spropvalue(struct mapitest *mt)
47 {
48         struct SPropValue propvalue;
49         struct FILETIME ft;
50         struct Binary_r bin;
51         struct StringArray_r mvstr;
52         uint32_t i;
53
54         propvalue.ulPropTag = PR_GENDER; /* enum MAPITAGS */
55         propvalue.dwAlignPad = 0;
56         propvalue.value.i = 3; /* union SPropValue_CTR */
57         mapidump_SPropValue(propvalue, "[sep]");
58
59         propvalue.ulPropTag = PR_SENSITIVITY; /* enum MAPITAGS */
60         propvalue.dwAlignPad = 0;
61         propvalue.value.l = 68000; /* union SPropValue_CTR */
62         mapidump_SPropValue(propvalue, "[sep]");
63
64         propvalue.ulPropTag = PR_REPLY_REQUESTED; /* enum MAPITAGS */
65         propvalue.dwAlignPad = 0;
66         propvalue.value.b = 1; /* union SPropValue_CTR */
67         mapidump_SPropValue(propvalue, "[sep]");
68
69         propvalue.ulPropTag = PidTagMemberId; /* enum MAPITAGS */
70         propvalue.dwAlignPad = 0;
71         propvalue.value.d = 0x3DEADBEEFCAFE124LL; /* union SPropValue_CTR */
72         mapidump_SPropValue(propvalue, "[sep]");
73
74         propvalue.ulPropTag = PR_SENDER_NAME; /* enum MAPITAGS */
75         propvalue.dwAlignPad = 0;
76         propvalue.value.lpszA = "Mr. The Sender"; /* union SPropValue_CTR */
77         mapidump_SPropValue(propvalue, "[sep]");
78
79         propvalue.ulPropTag = PR_REPORT_TAG; /* enum MAPITAGS */
80         propvalue.dwAlignPad = 0;
81         bin.cb = 12;
82         bin.lpb = talloc_array(mt->mem_ctx, uint8_t, bin.cb);
83         for (i = 0; i < bin.cb; ++i) {
84                 bin.lpb[i] = 0xF0 + i;
85         }
86         propvalue.value.bin = bin; /* union SPropValue_CTR */
87         mapidump_SPropValue(propvalue, "[sep]");
88
89         propvalue.ulPropTag = PidTagOriginalDeliveryTime ; /* enum MAPITAGS */
90         propvalue.dwAlignPad = 0;
91         ft.dwLowDateTime = 0x12345678;
92         ft.dwHighDateTime = 0x01CA6AE4;
93         propvalue.value.ft = ft; /* union SPropValue_CTR */
94         mapidump_SPropValue(propvalue, "[sep]");
95
96         propvalue.ulPropTag = PR_REPLY_TIME_ERROR; /* enum MAPITAGS */
97         propvalue.dwAlignPad = 0;
98         propvalue.value.err = MAPI_E_UNKNOWN_CPID; /* union SPropValue_CTR */
99         mapidump_SPropValue(propvalue, "[sep]");
100
101         propvalue.ulPropTag = PidTagScheduleInfoDelegateNames;
102         propvalue.dwAlignPad = 0;
103         mvstr.cValues = 3;
104         mvstr.lppszA = talloc_array(mt->mem_ctx, const char *, mvstr.cValues);
105         mvstr.lppszA[0] = talloc_strdup(mt->mem_ctx, "Foo");
106         mvstr.lppszA[1] = talloc_strdup(mt->mem_ctx, "A longer string");
107         mvstr.lppszA[2] = talloc_strdup(mt->mem_ctx, "All strung out on bugs");
108
109         propvalue.value.MVszA = mvstr;
110         mapidump_SPropValue(propvalue, "[sep]");
111
112 #if 0
113         /* Types TODO */
114         // int64_t dbl;/* [case(0x0005)] */
115         // const char *lpszW;/* [unique,charset(UTF16),case(0x001f)] */
116         // struct FlatUID_r *lpguid;/* [unique,case(0x0048)] */
117         // struct ShortArray_r MVi;/* [case(0x1002)] */
118         // struct LongArray_r MVl;/* [case(0x1003)] */
119         // struct BinaryArray_r MVbin;/* [case(0x1102)] */
120         // struct FlatUIDArray_r MVguid;/* [case(0x1048)] */
121         // struct StringArrayW_r MVszW;/* [case(0x101f)] */
122         // struct DateTimeArray_r MVft;/* [case(0x1040)] */
123         // uint32_t object;/* [case(0x000d)] */
124 #endif
125
126         propvalue.ulPropTag = 0xDDDD << 16 | PT_LONG; /* This isn't a real tag, just a test case */
127         propvalue.dwAlignPad = 0;
128         propvalue.value.l = 68020;
129         mapidump_SPropValue(propvalue, "[sep]");
130
131         return true;
132 }
133
134 /**
135    \details Test dump using mapidump_SPropTagArray
136
137    This function:
138    -# Tests the mapidump_SPropTagArray() function 
139
140    \param mt pointer to the top-level mapitest structure
141
142    \return true on success, otherwise false
143    
144    \note This currently doesn't check the results are sane, so manual inspection is required
145 */ 
146 _PUBLIC_ bool mapitest_mapidump_sproptagarray(struct mapitest *mt)
147 {
148         struct SPropTagArray *tagarray;
149
150         tagarray = set_SPropTagArray(mt->mem_ctx, 5, PR_SENDER_NAME,
151                                                      PR_BODY,
152                                                      PR_PERSONAL_HOME_PAGE,
153                                                      PR_OTHER_ADDRESS_CITY,
154                                                      (0xDDDD << 16 | PT_LONG));
155
156         mapidump_SPropTagArray(tagarray);
157
158         return true;
159 }
160
161 /**
162    \details Test dump using mapidump_SRowSet
163
164    This function:
165    -# Tests the mapidump_SRowSet() function 
166    -# Indirectly tests the mapidump_SRow() function
167
168    \param mt pointer to the top-level mapitest structure
169
170    \return true on success, otherwise false
171    
172    \note This currently doesn't check the results are sane, so manual inspection is required
173 */ 
174 _PUBLIC_ bool mapitest_mapidump_srowset(struct mapitest *mt)
175 {
176         struct SRowSet          srowset;
177
178         struct SPropValue       SPropValue;
179
180         srowset.cRows = 2;
181         srowset.aRow = talloc_array(mt->mem_ctx, struct SRow, srowset.cRows);
182
183         srowset.aRow[0].cValues = 0;
184         srowset.aRow[0].lpProps = talloc_zero(mt->mem_ctx, struct SPropValue);
185
186         SPropValue.ulPropTag = PR_OBJECT_TYPE;
187         SPropValue.value.l = MAPI_MAILUSER;
188         SRow_addprop(&(srowset.aRow[0]), SPropValue);
189
190         SPropValue.ulPropTag = PR_DISPLAY_TYPE;
191         SPropValue.value.l = 0;
192         SRow_addprop(&(srowset.aRow[0]), SPropValue);
193
194         SPropValue.ulPropTag = PR_GIVEN_NAME;
195         SPropValue.value.lpszA = "gname";
196         SRow_addprop(&(srowset.aRow[0]), SPropValue);
197
198         srowset.aRow[1].cValues = 0;
199         srowset.aRow[1].lpProps = talloc_zero(mt->mem_ctx, struct SPropValue);
200         SPropValue.ulPropTag = PR_GIVEN_NAME;
201         SPropValue.value.lpszA = "kname";
202         SRow_addprop(&(srowset.aRow[1]), SPropValue);
203
204         SPropValue.ulPropTag = PR_7BIT_DISPLAY_NAME;
205         SPropValue.value.lpszA = "lname";
206         SRow_addprop(&(srowset.aRow[1]), SPropValue);
207
208         mapidump_SRowSet(&srowset, "[sep]");
209
210         return true;
211 }
212
213 /**
214    \details Test dump using mapidump_pabentry
215
216    This function:
217    -# Tests the mapidump_PAB_entry() function 
218
219    \param mt pointer to the top-level mapitest structure
220
221    \return true on success, otherwise false
222    
223    \note This currently doesn't check the results are sane, so manual inspection is required
224 */ 
225 _PUBLIC_ bool mapitest_mapidump_pabentry(struct mapitest *mt)
226 {
227         struct SRow             pabentry;
228         struct SPropValue       SPropValue;
229
230         pabentry.cValues = 0;
231         pabentry.lpProps = talloc_zero(mt->mem_ctx, struct SPropValue);
232
233         SPropValue.ulPropTag = PR_ADDRTYPE_UNICODE;
234         SPropValue.value.lpszA = "dummy addrtype";
235         SRow_addprop(&(pabentry), SPropValue);
236
237         SPropValue.ulPropTag = PR_DISPLAY_NAME_UNICODE;
238         SPropValue.value.lpszA = "dummy display name";
239         SRow_addprop(&(pabentry), SPropValue);
240
241         SPropValue.ulPropTag = PR_EMAIL_ADDRESS_UNICODE;
242         SPropValue.value.lpszA = "dummy@example.com";
243         SRow_addprop(&(pabentry), SPropValue);
244
245         SPropValue.ulPropTag = PR_ACCOUNT_UNICODE;
246         SPropValue.value.lpszA = "dummy account";
247         SRow_addprop(&(pabentry), SPropValue);
248
249         mapidump_PAB_entry(&pabentry);
250
251         return true;
252 }
253
254 /**
255    \details Test dump using mapidump_note
256
257    This function:
258    -# Tests the mapidump_note() function on a plain text message
259    -# Tests the mapidump_note() function on a HTML message
260
261    \param mt pointer to the top-level mapitest structure
262
263    \return true on success, otherwise false
264    
265    \note This currently doesn't check the results are sane, so manual inspection is required
266 */ 
267 _PUBLIC_ bool mapitest_mapidump_note(struct mapitest *mt)
268 {
269         struct mapi_SPropValue_array    props;
270
271         props.cValues = 3;
272         props.lpProps = talloc_array(mt->mem_ctx, struct mapi_SPropValue, props.cValues);
273
274         props.lpProps[0].ulPropTag = PR_CONVERSATION_TOPIC;
275         props.lpProps[0].value.lpszA = "Topic of the Note";
276
277         props.lpProps[1].ulPropTag = PR_BODY;
278         props.lpProps[1].value.lpszA = "This is the body of the note. It has two sentences.";
279
280         props.lpProps[2].ulPropTag = PR_CLIENT_SUBMIT_TIME;
281         props.lpProps[2].value.ft.dwLowDateTime = 0x12345678;
282         props.lpProps[2].value.ft.dwHighDateTime = 0x01CA6BE4;
283
284         mapidump_note(&props, "[dummy ID]");
285
286         props.lpProps[1].ulPropTag = PR_BODY_HTML;
287         props.lpProps[1].value.lpszA = "<h1>Heading for the Note</h1>\n<p>This is the body of the note. It has two sentences.</p>";
288
289         mapidump_note(&props, "[dummy ID]");
290
291         
292         return true;
293 }
294
295 /**
296    \details Test dump using mapidump_task
297
298    This function:
299    -# Tests the mapidump_task() function
300    -# modifies the task to be completed
301    -# Tests the associated get_importance() function
302    -# Tests the associated get_task_status() function
303
304    \param mt pointer to the top-level mapitest structure
305
306    \return true on success, otherwise false
307    
308    \note This currently doesn't check the results are sane, so manual inspection is required
309 */ 
310 _PUBLIC_ bool mapitest_mapidump_task(struct mapitest *mt)
311 {
312         struct mapi_SPropValue_array    props;
313
314         props.cValues = 9;
315         props.lpProps = talloc_array(mt->mem_ctx, struct mapi_SPropValue, props.cValues);
316
317         props.lpProps[0].ulPropTag = PR_CONVERSATION_TOPIC;
318         props.lpProps[0].value.lpszA = "Topic of the Task";
319
320         props.lpProps[1].ulPropTag = PR_BODY;
321         props.lpProps[1].value.lpszA = "This is the body of the task. It has two sentences.";
322
323         props.lpProps[2].ulPropTag = PidLidTaskDueDate;
324         props.lpProps[2].value.ft.dwLowDateTime = 0x12345678;
325         props.lpProps[2].value.ft.dwHighDateTime = 0x01CA6CE4;
326
327         props.lpProps[3].ulPropTag = PidLidPrivate;
328         props.lpProps[3].value.b = 0;
329
330         props.lpProps[4].ulPropTag = PR_IMPORTANCE;
331         props.lpProps[4].value.l = IMPORTANCE_HIGH;
332
333         props.lpProps[5].ulPropTag = PidLidPercentComplete;
334         props.lpProps[5].value.dbl = 0.78;
335
336         props.lpProps[6].ulPropTag = PidLidTaskStartDate;
337         props.lpProps[6].value.ft.dwLowDateTime = 0x09876543;
338         props.lpProps[6].value.ft.dwHighDateTime = 0x01CA6AE4;
339
340         props.lpProps[7].ulPropTag = PidLidTaskStatus;
341         props.lpProps[7].value.l = olTaskWaiting;
342
343         props.lpProps[8].ulPropTag = PidLidContacts;
344         props.lpProps[8].value.MVszA.cValues = 2;
345         props.lpProps[8].value.MVszA.strings = talloc_array(mt->mem_ctx, struct mapi_LPSTR, 2);
346         props.lpProps[8].value.MVszA.strings[0].lppszA = "Contact One";
347         props.lpProps[8].value.MVszA.strings[1].lppszA = "Contact Two Jr.";
348
349         mapidump_task(&props, "[dummy ID]");
350
351         props.lpProps[7].ulPropTag = PidLidTaskStatus;
352         props.lpProps[7].value.l = olTaskComplete;
353
354         props.lpProps[3].ulPropTag = PidLidTaskDateCompleted;
355         props.lpProps[3].value.ft.dwLowDateTime = 0x22345678;
356         props.lpProps[3].value.ft.dwHighDateTime = 0x01CA6CB4;
357
358         mapidump_task(&props, "[dummy ID]");
359
360         if (strcmp("Low", get_importance(IMPORTANCE_LOW)) != 0) {
361                 mapitest_print(mt, "* %-40s: bad result IMPORTANCE_LOW\n", "mapidump_task");
362                 return false;
363         }
364         if (strcmp("Normal", get_importance(IMPORTANCE_NORMAL)) != 0) {
365                 mapitest_print(mt, "* %-40s: bad result IMPORTANCE_NORMAL\n", "mapidump_task");
366                 return false;
367         }
368         if (strcmp("High", get_importance(IMPORTANCE_HIGH)) != 0) {
369                 mapitest_print(mt, "* %-40s: bad result IMPORTANCE_HIGH\n", "mapidump_task");
370                 return false;
371         }
372         if (get_importance(IMPORTANCE_HIGH+1) != 0) {
373                 mapitest_print(mt, "* %-40s: bad result OUT_OF_RANGE\n", "mapidump_task");
374                 return false;
375         }
376
377         if (strcmp("Not Started", get_task_status(olTaskNotStarted)) != 0) {
378                 mapitest_print(mt, "* %-40s: bad result olTaskNotStarted\n", "mapidump_task");
379                 return false;
380         }
381         if (strcmp("In Progress", get_task_status(olTaskInProgress)) != 0) {
382                 mapitest_print(mt, "* %-40s: bad result olTaskInProgress\n", "mapidump_task");
383                 return false;
384         }
385         if (strcmp("Completed", get_task_status(olTaskComplete)) != 0) {
386                 mapitest_print(mt, "* %-40s: bad result olTaskCompleted\n", "mapidump_task");
387                 return false;
388         }
389         if (strcmp("Waiting on someone else", get_task_status(olTaskWaiting)) != 0) {
390                 mapitest_print(mt, "* %-40s: bad result olTaskWaiting\n", "mapidump_task");
391                 return false;
392         }
393         if (strcmp("Deferred", get_task_status(olTaskDeferred)) != 0) {
394                 mapitest_print(mt, "* %-40s: bad result olTaskDeferred\n", "mapidump_task");
395                 return false;
396         }
397         if (get_task_status(olTaskDeferred+1) != 0) {
398                 mapitest_print(mt, "* %-40s: bad result OUT_OF_RANGE\n", "mapidump_task");
399                 return false;
400         }
401         return true;
402 }
403
404 /**
405    \details Test dump using mapidump_contact
406
407    This function:
408    -# Tests the mapidump_contact() function
409
410    \param mt pointer to the top-level mapitest structure
411
412    \return true on success, otherwise false
413    
414    \note This currently doesn't check the results are sane, so manual inspection is required
415 */ 
416 _PUBLIC_ bool mapitest_mapidump_contact(struct mapitest *mt)
417 {
418         struct mapi_SPropValue_array    props;
419
420         props.cValues = 8;
421         props.lpProps = talloc_array(mt->mem_ctx, struct mapi_SPropValue, props.cValues);
422
423         props.lpProps[0].ulPropTag = PR_POSTAL_ADDRESS;
424         props.lpProps[0].value.lpszA = "P.O. Box 543, KTown";
425
426         props.lpProps[1].ulPropTag = PR_STREET_ADDRESS;
427         props.lpProps[1].value.lpszA = "1 My Street, KTown";
428
429         props.lpProps[2].ulPropTag = PR_COMPANY_NAME;
430         props.lpProps[2].value.lpszA = "Dummy Company Pty Ltd";
431
432         props.lpProps[3].ulPropTag = PR_TITLE;
433         props.lpProps[3].value.lpszA = "Ms.";
434
435         props.lpProps[4].ulPropTag = PR_COUNTRY;
436         props.lpProps[4].value.lpszA = "Australia";
437
438         props.lpProps[5].ulPropTag = PR_GIVEN_NAME;
439         props.lpProps[5].value.lpszA = "Konq.";
440
441         props.lpProps[6].ulPropTag = PR_SURNAME;
442         props.lpProps[6].value.lpszA = "Dragoon";
443
444         props.lpProps[7].ulPropTag = PR_DEPARTMENT_NAME;
445         props.lpProps[7].value.lpszA = "Research and Marketing";
446
447         mapidump_contact(&props, "[dummy ID]");
448
449         props.lpProps[1].ulPropTag = PR_CONVERSATION_TOPIC;
450         props.lpProps[1].value.lpszA = "Contact Topic";
451
452         mapidump_contact(&props, "[dummy ID]");
453
454         props.lpProps[0].ulPropTag = PidLidFileUnder;
455         props.lpProps[0].value.lpszA = "Card Label";
456
457         props.lpProps[4].ulPropTag = PR_DISPLAY_NAME;
458         props.lpProps[4].value.lpszA = "Konqi Dragon";
459
460         mapidump_contact(&props, "[dummy ID]");
461
462         return true;
463 }
464
465 /**
466    \details Test message dump using mapidump_appointment
467
468    This function:
469    -# Tests the mapidump_appointment() function
470
471    \param mt pointer to the top-level mapitest structure
472
473    \return true on success, otherwise false
474    
475    \note This currently doesn't check the results are sane, so manual inspection is required
476 */ 
477 _PUBLIC_ bool mapitest_mapidump_appointment(struct mapitest *mt)
478 {
479         struct mapi_SPropValue_array    props;
480
481         props.cValues = 8;
482         props.lpProps = talloc_array(mt->mem_ctx, struct mapi_SPropValue, props.cValues);
483
484         props.lpProps[0].ulPropTag = PidLidContacts;
485         props.lpProps[0].value.MVszA.cValues = 2;
486         props.lpProps[0].value.MVszA.strings = talloc_array(mt->mem_ctx, struct mapi_LPSTR, 2);
487         props.lpProps[0].value.MVszA.strings[0].lppszA = "Contact One";
488         props.lpProps[0].value.MVszA.strings[1].lppszA = "Contact Two Jr.";
489
490         props.lpProps[1].ulPropTag = PR_CONVERSATION_TOPIC;
491         props.lpProps[1].value.lpszA = "Dummy Appointment topic";
492
493         props.lpProps[2].ulPropTag = PidLidTimeZoneDescription;
494         props.lpProps[2].value.lpszA = "AEDT";
495
496         props.lpProps[3].ulPropTag = PidLidLocation;
497         props.lpProps[3].value.lpszA = "OpenChange Conference Room #3";
498
499         props.lpProps[4].ulPropTag = PidLidBusyStatus;
500         props.lpProps[4].value.l = olTaskNotStarted;
501
502         props.lpProps[5].ulPropTag = PidLidPrivate;
503         props.lpProps[5].ulPropTag = true;
504
505         props.lpProps[6].ulPropTag = PR_END_DATE;
506         props.lpProps[6].value.ft.dwLowDateTime = 0x12345678;
507         props.lpProps[6].value.ft.dwHighDateTime = 0x01CA6CE4;
508
509         props.lpProps[7].ulPropTag = PR_START_DATE;
510         props.lpProps[7].value.ft.dwLowDateTime = 0x09876543;
511         props.lpProps[7].value.ft.dwHighDateTime = 0x01CA6AE4;
512
513         mapidump_appointment(&props, "[dummy ID]");
514
515         return true;
516 }
517
518 /**
519    \details Test dump of an email message using mapidump_message
520
521    This function:
522    -# Builds an indicative email using mapi_SPropValues (sets no codepage)
523    -# Calls the mapidump_appointment() function
524
525    \param mt pointer to the top-level mapitest structure
526
527    \return true on success, otherwise false
528    
529    \note This currently doesn't check the results are sane, so manual inspection is required
530 */ 
531 _PUBLIC_ bool mapitest_mapidump_message(struct mapitest *mt)
532 {
533         struct mapi_SPropValue_array    props;
534
535         props.cValues = 9;
536         props.lpProps = talloc_array(mt->mem_ctx, struct mapi_SPropValue, props.cValues);
537
538         props.lpProps[0].ulPropTag = PR_INTERNET_MESSAGE_ID;
539         props.lpProps[0].value.lpszA = "dummy-3535395fds@example.com";
540         
541         props.lpProps[1].ulPropTag = PR_CONVERSATION_TOPIC;
542         props.lpProps[1].value.lpszA = "Dummy Email Subject";
543
544         props.lpProps[2].ulPropTag = PR_BODY;
545         props.lpProps[2].value.lpszA = "This is the body of the email. It has two sentences.\n";
546
547         props.lpProps[3].ulPropTag = PR_SENT_REPRESENTING_NAME;
548         props.lpProps[3].value.lpszA = "The Sender <sender@example.com>";
549
550         props.lpProps[4].ulPropTag = PR_DISPLAY_TO;
551         props.lpProps[4].value.lpszA = "The Recipient <to@example.com>";
552
553         props.lpProps[5].ulPropTag = PR_DISPLAY_CC;
554         props.lpProps[5].value.lpszA = "Other Recipient <cc@example.com>";
555
556         props.lpProps[6].ulPropTag = PR_DISPLAY_BCC;
557         props.lpProps[6].value.lpszA = "Ms. Anonymous <bcc@example.com>";
558
559         props.lpProps[7].ulPropTag = PidTagPriority;
560         props.lpProps[7].value.l = 0;
561
562         props.lpProps[8].ulPropTag = PR_HASATTACH;
563         props.lpProps[8].value.b = false;
564
565         mapidump_message(&props, "[dummy ID]", NULL);
566
567         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
568         props.lpProps[7].value.l = CP_USASCII;
569
570         mapidump_message(&props, "[dummy ID]", NULL);
571
572         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
573         props.lpProps[7].value.l = CP_UNICODE;
574
575         mapidump_message(&props, "[dummy ID]", NULL);
576
577         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
578         props.lpProps[7].value.l = CP_JAUTODETECT;
579
580         mapidump_message(&props, "[dummy ID]", NULL);
581
582         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
583         props.lpProps[7].value.l = CP_KAUTODETECT;
584
585         mapidump_message(&props, "[dummy ID]", NULL);
586
587         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
588         props.lpProps[7].value.l = CP_ISO2022JPESC;
589
590         mapidump_message(&props, "[dummy ID]", NULL);
591
592         props.lpProps[7].ulPropTag = PR_MESSAGE_CODEPAGE;
593         props.lpProps[7].value.l = CP_ISO2022JPSIO;
594
595         mapidump_message(&props, "[dummy ID]", NULL);
596
597         return true;
598 }
599
600 /**
601    \details Test dump of an new mail notification
602
603    This function:
604    -# Tests the mapidump_msgflags function with no bits set
605    -# Tests the mapidump_msgflags function with one bit set
606    -# Tests the mapidump_msgflags function with all bits set
607    -# Builds an indicative new mail notification
608    -# Calls the mapidump_newmail function to test dumping of that new mail notification
609   
610    \param mt pointer to the top-level mapitest structure
611
612    \return true on success, otherwise false
613    
614    \note This currently doesn't check the results are sane, so manual inspection is required
615 */ 
616 _PUBLIC_ bool mapitest_mapidump_newmail(struct mapitest *mt)
617 {
618         struct NewMailNotification notif;
619
620         mapidump_msgflags(0x0, "[sep]");
621
622         mapidump_msgflags(0x100, "[sep]");
623
624         mapidump_msgflags(0x1|0x2|0x4|0x8|0x10|0x20|0x40|0x80|0x100|0x200, "[sep]");
625
626         notif.FID = 0xFEDCBA9876543210LL;
627         notif.MID = 0xBADCAFEBEEF87625LL;
628         notif.MessageFlags = 0x20|0x2;
629         notif.UnicodeFlag = false;
630         notif.MessageClass.lpszA = "Dummy class";
631
632         mapidump_newmail(&notif, "[sep]");
633
634         return true;
635 }
636
637 /**
638    \details Test dump of a free/busy event
639
640    This function:
641    -# builds a freebusy binary event
642    -# tests dumping it using mapidump_freebusy_event()
643    -# modifies the event, and dumps it again
644    -# modifies the event, and dumps it again
645    -# tests dumping a date using mapidump_freebusy_date()
646    -# tests each months for mapidump_freebusy_month()
647    
648    \param mt pointer to the top-level mapitest structure
649
650    \return true on success, otherwise false
651    
652    \note This currently doesn't check the results are sane, so manual inspection is required
653 */ 
654 _PUBLIC_ bool mapitest_mapidump_freebusy(struct mapitest *mt)
655 {
656         struct Binary_r bin;
657         
658         bin.cb = 4;
659         bin.lpb = talloc_array(mt->mem_ctx, uint8_t, bin.cb);
660         /* this example from MS-OXOPFFB Section 4.4.3 */
661         bin.lpb[0] = 0x50;
662         bin.lpb[1] = 0x0A;
663         bin.lpb[2] = 0xC8;
664         bin.lpb[3] = 0x0A;
665         
666         mapidump_freebusy_event(&bin, 2009*16+11, 2008, "[sep]");
667
668         /* this example adapted from MS-OXOPFFB Section 4.4.3 */
669         bin.lpb[0] = 0x50;
670         bin.lpb[1] = 0x0A;
671         bin.lpb[2] = 0xCA;
672         bin.lpb[3] = 0x0A;
673         
674         mapidump_freebusy_event(&bin, 2009*16+11, 2009, "[sep]");
675
676         /* this example adapted from MS-OXOPFFB Section 4.4.3 */
677         bin.lpb[0] = 0x50;
678         bin.lpb[1] = 0x0A;
679         bin.lpb[2] = 0x80;
680         bin.lpb[3] = 0x0A;
681
682         mapidump_freebusy_event(&bin, 2009*16+11, 2009, "[sep]");
683
684         mapidump_freebusy_date(0x0CD18345, "[sep]");
685
686         if (strcmp("January", mapidump_freebusy_month(2009*16+1, 2009)) != 0) {
687                 mapitest_print(mt, "* %-40s: bad result January\n", "mapidump_freebusy");
688                 return false;
689         }
690         if (strcmp("February", mapidump_freebusy_month(2009*16+2, 2009)) != 0) {
691                 mapitest_print(mt, "* %-40s: bad result February\n", "mapidump_freebusy");
692                 return false;
693         }
694         if (strcmp("March", mapidump_freebusy_month(2009*16+3, 2009)) != 0) {
695                 mapitest_print(mt, "* %-40s: bad result March\n", "mapidump_freebusy");
696                 return false;
697         }
698         if (strcmp("April", mapidump_freebusy_month(2009*16+4, 2009)) != 0) {
699                 mapitest_print(mt, "* %-40s: bad result April\n", "mapidump_freebusy");
700                 return false;
701         }
702         if (strcmp("May", mapidump_freebusy_month(2009*16+5, 2009)) != 0) {
703                 mapitest_print(mt, "* %-40s: bad result May\n", "mapidump_freebusy");
704                 return false;
705         }
706         if (strcmp("June", mapidump_freebusy_month(2009*16+6, 2009)) != 0) {
707                 mapitest_print(mt, "* %-40s: bad result June\n", "mapidump_freebusy");
708                 return false;
709         }
710         if (strcmp("July", mapidump_freebusy_month(2009*16+7, 2009)) != 0) {
711                 mapitest_print(mt, "* %-40s: bad result July\n", "mapidump_freebusy");
712                 return false;
713         }
714         if (strcmp("August", mapidump_freebusy_month(2009*16+8, 2009)) != 0) {
715                 mapitest_print(mt, "* %-40s: bad result August\n", "mapidump_freebusy");
716                 return false;
717         }
718         if (strcmp("September", mapidump_freebusy_month(2009*16+9, 2009)) != 0) {
719                 mapitest_print(mt, "* %-40s: bad result September\n", "mapidump_freebusy");
720                 return false;
721         }
722         if (strcmp("October", mapidump_freebusy_month(2009*16+10, 2009)) != 0) {
723                 mapitest_print(mt, "* %-40s: bad result October\n", "mapidump_freebusy");
724                 return false;
725         }
726         if (strcmp("November", mapidump_freebusy_month(2009*16+11, 2009)) != 0) {
727                 mapitest_print(mt, "* %-40s: bad result November\n", "mapidump_freebusy");
728                 return false;
729         }
730         if (strcmp("December", mapidump_freebusy_month(2009*16+12, 2009)) != 0) {
731                 mapitest_print(mt, "* %-40s: bad result December\n", "mapidump_freebusy");
732                 return false;
733         }
734         if (mapidump_freebusy_month(2009*16+0, 2009) != 0) {
735                 mapitest_print(mt, "* %-40s: bad result underrange\n", "mapidump_freebusy");
736                 return false;
737         }
738         if (mapidump_freebusy_month(2009*16+13, 2009) != 0) {
739                 mapitest_print(mt, "* %-40s: bad result overrange\n", "mapidump_freebusy");
740                 return false;
741         }
742         return true;
743 }
744
745 /**
746    \details Test dump of a set of recipients
747
748    This function:
749    -# builds a recipient list
750    -# dumps out the recipient list using mapidump_Recipients()
751
752    \param mt pointer to the top-level mapitest structure
753
754    \return true on success, otherwise false
755    
756    \note This currently doesn't check the results are sane, so manual inspection is required
757 */ 
758 _PUBLIC_ bool mapitest_mapidump_recipients(struct mapitest *mt)
759 {
760         const char                      **userlist;
761         struct SRowSet                  resolved;
762         struct PropertyTagArray_r       flaglist;
763         struct SPropValue               SPropValue;
764
765         userlist = talloc_array(mt->mem_ctx, const char*, 3);
766         userlist[0] = "Mr. Unresolved";
767         userlist[1] = "Mr/Ms. Ambiguous";
768         userlist[2] = "Mrs. Resolved";
769
770         resolved.cRows = 1;
771         resolved.aRow = talloc_array(mt->mem_ctx, struct SRow, resolved.cRows);
772         resolved.aRow[0].cValues = 0;
773         resolved.aRow[0].lpProps = talloc_zero(mt->mem_ctx, struct SPropValue);
774         SPropValue.ulPropTag = PR_OBJECT_TYPE;
775         SPropValue.value.l = MAPI_MAILUSER;
776         SRow_addprop(&(resolved.aRow[0]), SPropValue);
777
778         SPropValue.ulPropTag = PR_GIVEN_NAME;
779         SPropValue.value.lpszA = "gname";
780         SRow_addprop(&(resolved.aRow[0]), SPropValue);
781
782         flaglist.cValues = 3;
783         flaglist.aulPropTag = talloc_zero_array(mt->mem_ctx, uint32_t, flaglist.cValues);
784         flaglist.aulPropTag[0] = MAPI_UNRESOLVED;
785         flaglist.aulPropTag[1] = MAPI_AMBIGUOUS;
786         flaglist.aulPropTag[2] = MAPI_RESOLVED;
787         
788         mapidump_Recipients(userlist, &resolved, &flaglist);
789
790         talloc_free(flaglist.aulPropTag);
791
792         return true;
793 }
794
795 /**
796    \details Test dump of a Folder deletion notification
797
798    This function:
799    -# Creates a FolderDeletedNotification structure
800    -# Dumps that structure out using mapidump_folderdeleted()
801    -# Tests mapidump_folderdeleted() with a null argument
802
803    \param mt pointer to the top-level mapitest structure
804
805    \return true on success, otherwise false
806    
807    \note This currently doesn't check the results are sane, so manual inspection is required
808 */ 
809 _PUBLIC_ bool mapitest_mapidump_folderdeleted(struct mapitest *mt)
810 {
811         struct FolderDeletedNotification folderdeletednotification;
812
813         folderdeletednotification.ParentFID = 0x9876CAFE432LL;
814         folderdeletednotification.FID = 0x1234ABCDLL;
815         mapidump_folderdeleted(&folderdeletednotification, "[sep]");
816         
817         mapidump_folderdeleted(0, "[sep]");
818
819         return true;
820 }
821
822 /**
823    \details Test dump of a folder move notification
824
825    This function:
826    -# Creates a FolderMoveCopyNotification structure
827    -# Dumps that structure out using mapidump_foldermoved()
828    -# Tests mapidump_foldermoved() with a null argument
829
830    \param mt pointer to the top-level mapitest structure
831
832    \return true on success, otherwise false
833    
834    \note This currently doesn't check the results are sane, so manual inspection is required
835 */ 
836 _PUBLIC_ bool mapitest_mapidump_foldermoved(struct mapitest *mt)
837 {
838         struct FolderMoveCopyNotification foldermovecopynotification;
839
840         foldermovecopynotification.ParentFID = 0x9876CAFE432LL;
841         foldermovecopynotification.FID = 0x1234ABCDLL;
842         foldermovecopynotification.OldParentFID = 0x9876CAFE43201DLL;
843         foldermovecopynotification.OldFID = 0x1234ABCD01DLL;
844         mapidump_foldermoved(&foldermovecopynotification, "[sep]");
845         
846         mapidump_foldermoved(0, "[sep]");
847
848         return true;
849 }
850
851 /**
852    \details Test dump of a folder copy notification
853
854    This function:
855    -# Creates a FolderMoveCopyNotification structure
856    -# Dumps that structure out using mapidump_foldercopy()
857    -# Tests mapidump_foldercopy() with a null argument
858
859    \param mt pointer to the top-level mapitest structure
860
861    \return true on success, otherwise false
862    
863    \note This currently doesn't check the results are sane, so manual inspection is required
864 */ 
865 _PUBLIC_ bool mapitest_mapidump_foldercopied(struct mapitest *mt)
866 {
867         struct FolderMoveCopyNotification foldermovecopynotification;
868
869         foldermovecopynotification.ParentFID = 0x9876CAFE432LL;
870         foldermovecopynotification.FID = 0x1234ABCDLL;
871         foldermovecopynotification.OldParentFID = 0x9876CAFE43201DLL;
872         foldermovecopynotification.OldFID = 0x1234ABCD01DLL;
873         mapidump_foldercopied(&foldermovecopynotification, "[sep]");
874         
875         mapidump_foldercopied(0, "[sep]");
876
877         return true;
878 }
879
880 /**
881    \details Test dump of a Folder creation notification
882
883    This function:
884    -# Creates a FolderCreatedNotification structure with a null tag set
885    -# Dumps that structure out using mapidump_foldercreated()
886    -# Adds a set of tags to the FolderCreatedNotification
887    -# Dumps the modified FolderCreatedNotification structure using mapidump_foldercreated()
888    -# Tests mapidump_foldercreated() with a null argument
889
890    \param mt pointer to the top-level mapitest structure
891
892    \return true on success, otherwise false
893    
894    \note This currently doesn't check the results are sane, so manual inspection is required
895 */ 
896 _PUBLIC_ bool mapitest_mapidump_foldercreated(struct mapitest *mt)
897 {
898         struct FolderCreatedNotification foldercreatednotification;
899
900         foldercreatednotification.ParentFID = 0x9876CAFE432LL;
901         foldercreatednotification.FID = 0x1234ABCDLL;
902         foldercreatednotification.NotificationTags.Tags = 0;
903         foldercreatednotification.TagCount = 0;
904         mapidump_foldercreated(&foldercreatednotification, "[sep]");
905
906         foldercreatednotification.TagCount = 3;
907         foldercreatednotification.NotificationTags.Tags = talloc_array(mt->mem_ctx, enum MAPITAGS,
908                                                            foldercreatednotification.TagCount);
909         foldercreatednotification.NotificationTags.Tags[0] = PidTagTemplateData;
910         foldercreatednotification.NotificationTags.Tags[1] = PR_URL_COMP_NAME;
911         foldercreatednotification.NotificationTags.Tags[2] = PidTagEndAttach;
912
913         mapidump_foldercreated(&foldercreatednotification, "[sep]");
914
915         mapidump_foldercreated(0, "[sep]");
916
917         return true;
918 }
919
920 /**
921    \details Test dump of a Message deletion notification
922
923    This function:
924    -# Creates a MessageDeletedNotification structure
925    -# Dumps that structure out using mapidump_messagedeleted()
926    -# Tests mapidump_messagedeleted() with a null argument
927
928    \param mt pointer to the top-level mapitest structure
929
930    \return true on success, otherwise false
931    
932    \note This currently doesn't check the results are sane, so manual inspection is required
933 */ 
934 _PUBLIC_ bool mapitest_mapidump_messagedeleted(struct mapitest *mt)
935 {
936         struct MessageDeletedNotification messagedeletednotification;
937
938         messagedeletednotification.FID = 0x1234ABCDLL;
939         messagedeletednotification.MID = 0x9876FEALL;
940         mapidump_messagedeleted(&messagedeletednotification, "[sep]");
941         
942         mapidump_messagedeleted(0, "[sep]");
943
944         return true;
945 }
946
947 /**
948    \details Test dump of a Message creation notification
949
950    This function:
951    -# Creates a MessageCreatedNotification structure
952    -# Dumps that structure out using mapidump_messagecreated()
953    -# Adds tags to the MessageCreatedNotification structure
954    -# Dumps the structure again.
955    -# Tests mapidump_messagecreated() with a null argument
956
957    \param mt pointer to the top-level mapitest structure
958
959    \return true on success, otherwise false
960    
961    \note This currently doesn't check the results are sane, so manual inspection is required
962 */ 
963 _PUBLIC_ bool mapitest_mapidump_messagecreated(struct mapitest *mt)
964 {
965         struct MessageCreatedNotification messagecreatednotification;
966
967         messagecreatednotification.FID = 0x1234ABCDLL;
968         messagecreatednotification.MID = 0x9876FEALL;
969         messagecreatednotification.NotificationTags.Tags = 0;
970         messagecreatednotification.TagCount = 0;
971         mapidump_messagecreated(&messagecreatednotification, "[sep]");
972
973         messagecreatednotification.TagCount = 3;
974         messagecreatednotification.NotificationTags.Tags = talloc_array(mt->mem_ctx, enum MAPITAGS,
975                                                        messagecreatednotification.TagCount);
976         messagecreatednotification.NotificationTags.Tags[0] = PR_DISPLAY_NAME;
977         messagecreatednotification.NotificationTags.Tags[1] = PR_DISPLAY_NAME_UNICODE;
978         messagecreatednotification.NotificationTags.Tags[2] = PR_COMPANY_NAME;
979
980         mapidump_messagecreated(0, "[sep]");
981
982         return true;
983 }
984
985 /**
986    \details Test dump of a Message moved notification
987
988    This function:
989    -# Creates a MessageMovedNotification structure
990    -# Dumps that structure out using mapidump_messagemoved()
991    -# Tests mapidump_messagemoved() with a null argument
992
993    \param mt pointer to the top-level mapitest structure
994
995    \return true on success, otherwise false
996    
997    \note This currently doesn't check the results are sane, so manual inspection is required
998 */ 
999 _PUBLIC_ bool mapitest_mapidump_messagemoved(struct mapitest *mt)
1000 {
1001         struct MessageMoveCopyNotification messagemovednotification;
1002
1003         messagemovednotification.FID = 0x1234ABCDLL;
1004         messagemovednotification.MID = 0x9876FEALL;
1005         messagemovednotification.OldFID = 0x1234ABCD01dLL;
1006         messagemovednotification.OldMID = 0x9876FEA01dLL;
1007         mapidump_messagemoved(&messagemovednotification, "[sep]");
1008         
1009         mapidump_messagemoved(0, "[sep]");
1010
1011         return true;
1012 }
1013
1014
1015 /**
1016    \details Test dump of a Message copied notification
1017
1018    This function:
1019    -# Creates a MessageCopiedNotification structure
1020    -# Dumps that structure out using mapidump_messagecopied()
1021    -# Tests mapidump_messagecopied() with a null argument
1022
1023    \param mt pointer to the top-level mapitest structure
1024
1025    \return true on success, otherwise false
1026    
1027    \note This currently doesn't check the results are sane, so manual inspection is required
1028 */ 
1029 _PUBLIC_ bool mapitest_mapidump_messagecopied(struct mapitest *mt)
1030 {
1031         struct MessageMoveCopyNotification messagecopiednotification;
1032
1033         messagecopiednotification.FID = 0x1234ABCDLL;
1034         messagecopiednotification.MID = 0x9876FEALL;
1035         messagecopiednotification.OldFID = 0x1234ABCD01dLL;
1036         messagecopiednotification.OldMID = 0x9876FEA01dLL;
1037         mapidump_messagecopied(&messagecopiednotification, "[sep]");
1038         
1039         mapidump_messagecopied(0, "[sep]");
1040
1041         return true;
1042 }
1043
1044 /**
1045    \details Test dump of a Message modification notification
1046
1047    This function:
1048    -# Creates a MessageModifiedNotification structure
1049    -# Dumps that structure out using mapidump_messagemodified()
1050    -# Adds tags to the MessageModifiedNotification structure
1051    -# Dumps the structure again.
1052    -# Tests mapidump_messagemodified() with a null argument
1053
1054    \param mt pointer to the top-level mapitest structure
1055
1056    \return true on success, otherwise false
1057    
1058    \note This currently doesn't check the results are sane, so manual inspection is required
1059 */ 
1060 _PUBLIC_ bool mapitest_mapidump_messagemodified(struct mapitest *mt)
1061 {
1062         struct MessageModifiedNotification messagemodifiednotification;
1063
1064         messagemodifiednotification.FID = 0x1234ABCDLL;
1065         messagemodifiednotification.MID = 0x9876FEALL;
1066         messagemodifiednotification.NotificationTags.Tags = 0;
1067         messagemodifiednotification.TagCount = 0;
1068         mapidump_messagemodified(&messagemodifiednotification, "[sep]");
1069
1070         messagemodifiednotification.TagCount = 3;
1071         messagemodifiednotification.NotificationTags.Tags = talloc_array(mt->mem_ctx, enum MAPITAGS,
1072                                                         messagemodifiednotification.TagCount);
1073         messagemodifiednotification.NotificationTags.Tags[0] = PR_DISPLAY_NAME;
1074         messagemodifiednotification.NotificationTags.Tags[1] = PR_DISPLAY_NAME_UNICODE;
1075         messagemodifiednotification.NotificationTags.Tags[2] = PR_COMPANY_NAME;
1076
1077         mapidump_messagemodified(0, "[sep]");
1078
1079         return true;
1080 }