2 OpenChange MAPI torture suite implementation.
4 Tables related operations torture
6 Copyright (C) Julien Kerihuel 2008.
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.
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.
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/>.
22 #include <libmapi/libmapi.h>
23 #include <gen_ndr/ndr_exchange.h>
25 #include <credentials.h>
26 #include <torture/mapi_torture.h>
28 #include <torture/torture_proto.h>
29 #include <samba/popt.h>
31 bool torture_rpc_mapi_sorttable(struct torture_context *torture)
33 enum MAPISTATUS retval;
35 mapi_object_t obj_store;
36 mapi_object_t obj_folder;
37 mapi_object_t obj_ctable;
39 struct SPropTagArray *SPropTagArray;
40 struct SRowSet SRowSet;
41 struct SSortOrderSet criteria;
42 struct mapi_session *session;
46 /* init torture test */
47 mem_ctx = talloc_named(NULL, 0, "torture_rpc_mapi_sorttable");
48 if ((session = torture_init_mapi(mem_ctx, torture->lp_ctx)) == NULL) return false;
50 /* Open Message Store*/
51 mapi_object_init(&obj_store);
52 retval = OpenMsgStore(session, &obj_store);
53 mapi_errstr("OpenMsgStore", GetLastError());
54 if (retval != MAPI_E_SUCCESS) return false;
56 /* Retrieve Inbox folder ID */
57 retval = GetDefaultFolder(&obj_store, &id_folder, olFolderInbox);
58 mapi_errstr("GetDefaultFolder", GetLastError());
59 if (retval != MAPI_E_SUCCESS) return false;
61 /* Open Inbox Folder */
62 mapi_object_init(&obj_folder);
63 retval = OpenFolder(&obj_store, id_folder, &obj_folder);
64 mapi_errstr("OpenFolder", GetLastError());
65 if (retval != MAPI_E_SUCCESS) return false;
67 /* Retrieve the Contents Table */
68 mapi_object_init(&obj_ctable);
69 retval = GetContentsTable(&obj_folder, &obj_ctable, 0, &count);
70 mapi_errstr("GetContentsTable", GetLastError());
71 if (retval != MAPI_E_SUCCESS) return false;
73 /* Customize the contents table view */
74 SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_SUBJECT, PR_LAST_MODIFICATION_TIME);
75 retval = SetColumns(&obj_ctable, SPropTagArray);
76 MAPIFreeBuffer(SPropTagArray);
77 mapi_errstr("SetColumns", GetLastError());
78 if (retval != MAPI_E_SUCCESS) return false;
80 /* Browse and print table content */
81 printf("\nBefore SortTable ASCENDING:\n");
82 while (((retval = QueryRows(&obj_ctable, count, TBL_ADVANCE, &SRowSet)) != MAPI_E_NOT_FOUND) &&
84 count -= SRowSet.cRows;
86 for (i = 0; i < SRowSet.cRows; i++) {
87 printf("\t[%d] %s\n", i, SRowSet.aRow[i].lpProps[0].value.lpszA);
92 memset(&criteria, 0x0, sizeof (struct SSortOrderSet));
94 criteria.aSort = talloc_array(mem_ctx, struct SSortOrder, criteria.cSorts);
95 criteria.aSort[0].ulPropTag = PR_LAST_MODIFICATION_TIME;
96 criteria.aSort[0].ulOrder = TABLE_SORT_ASCEND;
97 retval = SortTable(&obj_ctable, &criteria);
98 mapi_errstr("SortTable", GetLastError());
100 /* SeekRow at beginning */
101 retval = SeekRow(&obj_ctable, BOOKMARK_BEGINNING, 0, &count);
102 mapi_errstr("SeekRow", GetLastError());
104 /* Browse and print table content */
105 printf("\nAfter SortTable ASCENDING:\n");
106 while (((retval = QueryRows(&obj_ctable, count, TBL_ADVANCE, &SRowSet)) != MAPI_E_NOT_FOUND) &&
108 count -= SRowSet.cRows;
110 for (i = 0; i < SRowSet.cRows; i++) {
111 printf("\t[%d] %s\n", i, SRowSet.aRow[i].lpProps[0].value.lpszA);
116 mapi_object_release(&obj_ctable);
117 mapi_object_release(&obj_folder);
118 mapi_object_release(&obj_store);