} END_TEST START_TEST (test_is_schema_created) { enum mapistore_error retval; ck_assert(is_schema_created(conn) == false); ck_assert(is_database_empty(conn) == true); retval = create_schema(conn, NAMEDPROPS_MYSQL_SCHEMA_PATH); ck_assert_int_eq(retval, MAPISTORE_SUCCESS); ck_assert(is_schema_created(conn) == true); ck_assert(is_database_empty(conn) == true); } END_TEST
/** \details Initialize mapistore named properties MySQL backend \param mem_ctx pointer to the memory context \param lp_ctx pointer to the loadparm context \param nprops_ctx pointer on pointer to the namedprops context to return \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE error */ enum mapistore_error mapistore_namedprops_mysql_init(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct namedprops_context **nprops_ctx) { enum mapistore_error retval; struct namedprops_context *nprops = NULL; struct namedprops_mysql_params parms; MYSQL *conn = NULL; /* Sanity checks */ MAPISTORE_RETVAL_IF(!lp_ctx, MAPISTORE_ERR_INVALID_PARAMETER, NULL); MAPISTORE_RETVAL_IF(!nprops_ctx, MAPISTORE_ERR_INVALID_PARAMETER, NULL); /* Retrieve smb.conf arguments */ retval = mapistore_namedprops_mysql_parameters(lp_ctx, &parms); if (retval != MAPISTORE_SUCCESS) { DEBUG(0, ("[%s:%d] ERROR: parsing MySQL named properties " "parametric option failed with %s\n", __FUNCTION__, __LINE__, mapistore_errstr(retval))); MAPISTORE_RETVAL_ERR(retval, NULL); } /* Establish MySQL connection */ if (parms.sock) { // FIXME DEBUG(0, ("Not implemented connect through unix socket to mysql")); } else { char *connection_string = connection_string_from_parameters(mem_ctx, &parms); MAPISTORE_RETVAL_IF(!connection_string, MAPISTORE_ERR_NOT_INITIALIZED, NULL); create_connection(connection_string, &conn); } MAPISTORE_RETVAL_IF(!conn, MAPISTORE_ERR_NOT_INITIALIZED, NULL); /* Initialize the database */ if (!is_schema_created(conn) || is_database_empty(conn)) { retval = initialize_database(conn, parms.data); MAPISTORE_RETVAL_IF(retval != MAPISTORE_SUCCESS, retval, NULL); } /* Create context */ nprops = talloc_zero(mem_ctx, struct namedprops_context); MAPISTORE_RETVAL_IF(!nprops, MAPISTORE_ERR_NO_MEMORY, NULL); nprops->backend_type = NAMEDPROPS_BACKEND_MYSQL; nprops->create_id = create_id; nprops->get_mapped_id = get_mapped_id; nprops->get_nameid = get_nameid; nprops->get_nameid_type = get_nameid_type; nprops->next_unused_id = next_unused_id; nprops->transaction_commit = transaction_commit; nprops->transaction_start = transaction_start; nprops->data = conn; talloc_set_destructor(nprops, mapistore_namedprops_mysql_destructor); *nprops_ctx = nprops; return MAPISTORE_SUCCESS; }
} END_TEST START_TEST (test_initialize_database) { enum mapistore_error retval; /* test sanity checks */ retval = initialize_database(NULL, NULL); ck_assert_int_eq(retval, MAPISTORE_ERR_DATABASE_INIT); ck_assert(is_database_empty(conn) == true); retval = initialize_database(conn, NAMEDPROPS_MYSQL_SCHEMA_PATH); ck_assert_int_eq(retval, MAPISTORE_SUCCESS); ck_assert(is_database_empty(conn) == false); } END_TEST