⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strings-reps-test.c

📁 subversion-1.4.3-1.tar.gz 配置svn的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* strings-reps-test.c --- test `strings' and `representations' interfaces * * ==================================================================== * Copyright (c) 2000-2004 CollabNet.  All rights reserved. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution.  The terms * are also available at http://subversion.tigris.org/license-1.html. * If newer versions of this license are posted there, you may use a * newer version instead, at your option. * * This software consists of voluntary contributions made by many * individuals.  For exact contribution history, see the revision * history and logs, available at http://subversion.tigris.org/. * ==================================================================== */#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <stdio.h>#include <apr.h>#include "svn_error.h"#include "../svn_test.h"#include "../svn_test_fs.h"#include "../../libsvn_fs_base/util/skel.h"#include "../../libsvn_fs_base/util/fs_skels.h"#include "../../libsvn_fs_base/bdb/strings-table.h"#include "../../libsvn_fs_base/bdb/reps-table.h"/*-----------------------------------------------------------------*//* Helper functions and batons for reps-table testing. */struct rep_args{  const char *key;  svn_fs_t *fs;  skel_t *skel;};static svn_error_t *txn_body_write_new_rep(void *baton, trail_t *trail){  struct rep_args *b = (struct rep_args *) baton;  representation_t *rep;  SVN_ERR(svn_fs_base__parse_representation_skel(&rep, b->skel,                                                 trail->pool));  return svn_fs_bdb__write_new_rep(&(b->key), b->fs, rep, trail, trail->pool);}static svn_error_t *txn_body_write_rep(void *baton, trail_t *trail){  struct rep_args *b = (struct rep_args *) baton;  representation_t *rep;  SVN_ERR(svn_fs_base__parse_representation_skel(&rep, b->skel,                                                 trail->pool));  return svn_fs_bdb__write_rep(b->fs, b->key, rep, trail, trail->pool);}static svn_error_t *txn_body_read_rep(void *baton, trail_t *trail){  struct rep_args *b = (struct rep_args *) baton;  representation_t *rep;  SVN_ERR(svn_fs_bdb__read_rep(&rep, b->fs, b->key, trail, trail->pool));  return svn_fs_base__unparse_representation_skel(&(b->skel), rep,                                                  trail->pool);}static svn_error_t *txn_body_delete_rep(void *baton, trail_t *trail){  struct rep_args *b = (struct rep_args *) baton;  return svn_fs_bdb__delete_rep(b->fs, b->key, trail, trail->pool);}/* Representation Table Test functions. */static svn_error_t *write_new_rep(const char **msg,               svn_boolean_t msg_only,              svn_test_opts_t *opts,              apr_pool_t *pool){  struct rep_args args;  const char *rep = "((fulltext 0 ) a83t2Z0q)";  svn_fs_t *fs;  *msg = "write a new rep, get a new key back";  if (msg_only)    return SVN_NO_ERROR;  /* Create a new fs and repos */  SVN_ERR(svn_test__create_fs          (&fs, "test-repo-write-new-rep",           "bdb", pool));  /* Set up transaction baton */  args.fs = fs;  args.skel = svn_fs_base__parse_skel(rep, strlen(rep), pool);  args.key = NULL;  /* Write new rep to reps table. */  SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_write_new_rep, &args,                                 pool));  if (args.key == NULL)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error writing new representation");  return SVN_NO_ERROR;}static svn_error_t *write_rep(const char **msg,           svn_boolean_t msg_only,          svn_test_opts_t *opts,          apr_pool_t *pool){  struct rep_args new_args;  struct rep_args args;  const char *new_rep = "((fulltext 0 ) a83t2Z0q)";  const char *rep = "((fulltext 0 ) kfogel31337)";  svn_fs_t *fs;  *msg = "write a new rep, then overwrite it";  if (msg_only)    return SVN_NO_ERROR;  /* Create a new fs and repos */  SVN_ERR(svn_test__create_fs          (&fs, "test-repo-write-rep",           "bdb", pool));  /* Set up transaction baton */  new_args.fs = fs;  new_args.skel = svn_fs_base__parse_skel(new_rep, strlen(new_rep), pool);  new_args.key = NULL;  /* Write new rep to reps table. */  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_write_new_rep, &new_args, pool));  /* Make sure we got a valid key. */  if (new_args.key == NULL)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error writing new representation");  /* Set up transaction baton for re-writing reps. */  args.fs = new_args.fs;  args.skel = svn_fs_base__parse_skel(rep, strlen(rep), pool);  args.key = new_args.key;  /* Overwrite first rep in reps table. */  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_write_rep, &args, pool));  return SVN_NO_ERROR;}static svn_error_t *read_rep(const char **msg,          svn_boolean_t msg_only,         svn_test_opts_t *opts,         apr_pool_t *pool){  struct rep_args new_args;  struct rep_args args;  struct rep_args read_args;  svn_stringbuf_t *skel_data;  svn_fs_t *fs;  const char *rep = "((fulltext 0 ) kfogel31337)";  const char *new_rep_before = "((fulltext 0 ) a83t2Z0)";  /* This test also tests the introduction of checksums into skels that     didn't have them. */  /* Get writeable strings. */  char *rep_after = apr_pstrdup    (pool, "((fulltext 0  (md5 16 XXXXXXXXXXXXXXXX)) kfogel31337");  char *new_rep_after = apr_pstrdup    (pool, "((fulltext 0  (md5 16 XXXXXXXXXXXXXXXX)) a83t2Z0");  int rep_after_len = strlen(rep_after);  int new_rep_after_len = strlen(new_rep_after);  /* Replace the fake fake checksums with the real fake checksums.     And someday, when checksums are actually calculated, we can     replace the real fake checksums with real real checksums. */  {    char *p;    for (p = rep_after; *p; p++)      if (*p == 'X')        *p = '\0';        for (p = new_rep_after; *p; p++)      if (*p == 'X')        *p = '\0';  }  *msg = "write and overwrite a new rep; confirm with reads";  if (msg_only)    return SVN_NO_ERROR;  /* Create a new fs and repos */  SVN_ERR(svn_test__create_fs          (&fs, "test-repo-read-rep",           "bdb", pool));  /* Set up transaction baton */  new_args.fs = fs;  new_args.skel = svn_fs_base__parse_skel(new_rep_before,                                          strlen(new_rep_before), pool);  new_args.key = NULL;  /* Write new rep to reps table. */  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_write_new_rep, &new_args, pool));  /* Make sure we got a valid key. */  if (new_args.key == NULL)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error writing new representation");  /* Read the new rep back from the reps table. */  read_args.fs = new_args.fs;  read_args.skel = NULL;  read_args.key = new_args.key;  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_read_rep, &read_args, pool));  /* Make sure the skel matches. */  if (! read_args.skel)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error reading new representation");    skel_data = svn_fs_base__unparse_skel(read_args.skel, pool);  if (memcmp(skel_data->data, new_rep_after, new_rep_after_len) != 0)    return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,                             "representation corrupted (first check)");    /* Set up transaction baton for re-writing reps. */  args.fs = new_args.fs;  args.skel = svn_fs_base__parse_skel(rep, strlen(rep), pool);  args.key = new_args.key;  /* Overwrite first rep in reps table. */  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_write_rep, &args, pool));  /* Read the new rep back from the reps table (using the same FS and     key as the first read...let's make sure this thing didn't get     written to the wrong place). */  read_args.skel = NULL;  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_read_rep, &read_args, pool));  /* Make sure the skel matches. */  if (! read_args.skel)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error reading new representation");    skel_data = svn_fs_base__unparse_skel(read_args.skel, pool);  if (memcmp(skel_data->data, rep_after, rep_after_len) != 0)    return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,                             "representation corrupted (second check)");  return SVN_NO_ERROR;}static svn_error_t *delete_rep(const char **msg,            svn_boolean_t msg_only,           svn_test_opts_t *opts,           apr_pool_t *pool){  struct rep_args new_args;  struct rep_args delete_args;  struct rep_args read_args;  const char *new_rep = "((fulltext 0 ) a83t2Z0q)";  svn_fs_t *fs;  svn_error_t *err;  *msg = "write, then delete, a new rep; confirm deletion";  if (msg_only)    return SVN_NO_ERROR;  /* Create a new fs and repos */  SVN_ERR(svn_test__create_fs          (&fs, "test-repo-delete-rep",           "bdb", pool));  /* Set up transaction baton */  new_args.fs = fs;  new_args.skel = svn_fs_base__parse_skel(new_rep, strlen(new_rep), pool);  new_args.key = NULL;  /* Write new rep to reps table. */  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_write_new_rep, &new_args, pool));  /* Make sure we got a valid key. */  if (new_args.key == NULL)    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error writing new representation");  /* Delete the rep we just wrote. */  delete_args.fs = new_args.fs;  delete_args.key = new_args.key;  SVN_ERR(svn_fs_base__retry_txn(new_args.fs,                                  txn_body_delete_rep, &delete_args, pool));  /* Try to read the new rep back from the reps table. */  read_args.fs = new_args.fs;  read_args.skel = NULL;  read_args.key = new_args.key;  err = svn_fs_base__retry_txn(new_args.fs,                                txn_body_read_rep, &read_args, pool);  /* We better have an error... */  if ((! err) && (read_args.skel))    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,                            "error deleting representation");  svn_error_clear(err);  return SVN_NO_ERROR;}/* ------------------------------------------------------------------- *//* Helper functions and batons for strings-table testing. */static svn_error_t *verify_expected_record(svn_fs_t *fs,                        const char *key,                        const char *expected_text,                       apr_size_t expected_len,                       trail_t *trail){  apr_size_t size;  char buf[100];  svn_stringbuf_t *text;  svn_filesize_t offset = 0;  svn_filesize_t string_size;  /* Check the string size. */  SVN_ERR(svn_fs_bdb__string_size(&string_size, fs, key,                                   trail, trail->pool));  if (string_size > SVN_MAX_OBJECT_SIZE)    return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,                             "record size is too large "                             "(got %" SVN_FILESIZE_T_FMT ", "                             "limit is %" APR_SIZE_T_FMT ")",                             string_size, SVN_MAX_OBJECT_SIZE);  size = (apr_size_t) string_size;  if (size != expected_len)    return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,                             "record has unexpected size "                             "(got %" APR_SIZE_T_FMT ", "                             "expected %" APR_SIZE_T_FMT ")",                             size, expected_len);  /* Read the string back in 100-byte chunks. */  text = svn_stringbuf_create("", trail->pool);  while (1)    {      size = sizeof(buf);      SVN_ERR(svn_fs_bdb__string_read(fs, key, buf, offset, &size,                                       trail, trail->pool));      if (size == 0)        break;      svn_stringbuf_appendbytes(text, buf, size);      offset += size;    }  /* Check the size and contents of the read data. */  if (text->len != expected_len)    return svn_error_createf(SVN_ERR_FS_GENERAL, NULL,                             "record read returned unexpected size "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -