/* * GetUniqueFMID * * This function is a copy of original openchangedb_get_new_folderID from libproxy/openchangedb.C * * I extract this function because : * - Function can be implemented directly in the backend * - */ enum MAPISTATUS GetUniqueFMID(struct EasyLinuxContext *elContext, uint64_t *FMID) { int ret; struct ldb_result *res; struct ldb_message *msg; const char * const attrs[] = { "*", NULL }; /* Get the current GlobalCount */ ret = ldb_search(elContext->LdbTable, elContext->mem_ctx, &res, ldb_get_root_basedn(elContext->LdbTable), LDB_SCOPE_SUBTREE, attrs, "(objectClass=server)"); if( ret != LDB_SUCCESS || !res->count ) return MAPI_E_NOT_FOUND; *FMID = ldb_msg_find_attr_as_uint64(res->msgs[0], "GlobalCount", 0); /* Update GlobalCount value */ msg = ldb_msg_new(elContext->mem_ctx); msg->dn = ldb_dn_copy(msg, ldb_msg_find_attr_as_dn(elContext->LdbTable, elContext->mem_ctx, res->msgs[0], "distinguishedName")); ldb_msg_add_fmt(msg, "GlobalCount", "%llu", (long long unsigned int) ((*FMID) + 1)); msg->elements[0].flags = LDB_FLAG_MOD_REPLACE; ret = ldb_modify(elContext->LdbTable, msg); if( ret != LDB_SUCCESS || !res->count ) return MAPI_E_NOT_FOUND; *FMID = (exchange_globcnt(*FMID) << 16) | 0x0001; return MAPI_E_SUCCESS; }
} END_TEST START_TEST (test_get_new_changeNumber) { uint64_t cn = 0, new_cn; int i; for (i = 0; i < 5; i++) { retval = openchangedb_get_new_changeNumber(g_oc_ctx, USER1, &cn); CHECK_SUCCESS; new_cn = ((exchange_globcnt(NEXT_CHANGE_NUMBER+i) << 16) | 0x0001); ck_assert(cn == new_cn); } } END_TEST
} END_TEST START_TEST (test_get_new_changeNumbers) { uint64_t cn; int i; struct UI8Array_r *cns; retval = openchangedb_get_new_changeNumbers(g_oc_ctx, g_mem_ctx, USER1, 10, &cns); CHECK_SUCCESS; ck_assert_int_eq(10, cns->cValues); for (i = 0; i < 10; i++) { cn = ((exchange_globcnt(NEXT_CHANGE_NUMBER+5+i) << 16) | 0x0001); ck_assert(cns->lpui8[i] == cn); } } END_TEST