📄 strings-reps-test.c
字号:
"(got %" APR_SIZE_T_FMT ", " "expected %" APR_SIZE_T_FMT ")", size, expected_len); if (memcmp(expected_text, text->data, expected_len)) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "record read returned unexpected data"); return SVN_NO_ERROR;}struct string_args{ svn_fs_t *fs; const char *key; const char *text; apr_size_t len;};static svn_error_t *txn_body_verify_string(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; return verify_expected_record(b->fs, b->key, b->text, b->len, trail);}static svn_error_t *txn_body_string_append(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; return svn_fs_bdb__string_append(b->fs, &(b->key), b->len, b->text, trail, trail->pool);}static svn_error_t *txn_body_string_clear(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; return svn_fs_bdb__string_clear(b->fs, b->key, trail, trail->pool);}static svn_error_t *txn_body_string_delete(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; return svn_fs_bdb__string_delete(b->fs, b->key, trail, trail->pool);}static svn_error_t *txn_body_string_size(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; svn_filesize_t string_size; SVN_ERR(svn_fs_bdb__string_size(&string_size, b->fs, b->key, trail, trail->pool)); if (string_size > SVN_MAX_OBJECT_SIZE) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "txn_body_string_size: string size is too large " "(got %" SVN_FILESIZE_T_FMT ", limit is %" APR_SIZE_T_FMT ")", string_size, SVN_MAX_OBJECT_SIZE); b->len = (apr_size_t) string_size; return SVN_NO_ERROR;}static svn_error_t *txn_body_string_append_fail(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; SVN_ERR(svn_fs_bdb__string_append(b->fs, &(b->key), b->len, b->text, trail, trail->pool)); return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "la dee dah, la dee day...");}static svn_error_t *txn_body_string_copy(void *baton, trail_t *trail){ struct string_args *b = (struct string_args *) baton; return svn_fs_bdb__string_copy(b->fs, &(b->key), b->key, trail, trail->pool);}static const char *bigstring1 =" Alice opened the door and found that it led into a small\n""passage, not much larger than a rat-hole: she knelt down and\n""looked along the passage into the loveliest garden you ever saw.\n""How she longed to get out of that dark hall, and wander about\n""among those beds of bright flowers and those cool fountains, but\n""she could not even get her head though the doorway; 'and even if\n""my head would go through,' thought poor Alice, 'it would be of\n""very little use without my shoulders. Oh, how I wish\n""I could shut up like a telescope! I think I could, if I only\n""know how to begin.' For, you see, so many out-of-the-way things\n""had happened lately, that Alice had begun to think that very few\n""things indeed were really impossible.";static const char *bigstring2 =" There seemed to be no use in waiting by the little door, so she\n""went back to the table, half hoping she might find another key on\n""it, or at any rate a book of rules for shutting people up like\n""telescopes: this time she found a little bottle on it, ('which\n""certainly was not here before,' said Alice,) and round the neck\n""of the bottle was a paper label, with the words 'DRINK ME'\n""beautifully printed on it in large letters.";static const char *bigstring3 =" It was all very well to say 'Drink me,' but the wise little\n""Alice was not going to do THAT in a hurry. 'No, I'll look\n""first,' she said, 'and see whether it's marked \"poison\" or not';\n""for she had read several nice little histories about children who\n""had got burnt, and eaten up by wild beasts and other unpleasant\n""things, all because they WOULD not remember the simple rules\n""their friends had taught them: such as, that a red-hot poker\n""will burn you if you hold it too long; and that if you cut your\n""finger VERY deeply with a knife, it usually bleeds; and she had\n""never forgotten that, if you drink much from a bottle marked\n""'poison,' it is almost certain to disagree with you, sooner or\n""later.";static svn_error_t *test_strings(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ struct string_args args; svn_fs_t *fs; svn_stringbuf_t *string; *msg = "test many strings table functions together"; if (msg_only) return SVN_NO_ERROR; /* Create a new fs and repos */ SVN_ERR(svn_test__create_fs (&fs, "test-repo-test-strings", "bdb", pool)); /* The plan (after each step below, verify the size and contents of the string): 1. Write a new string (string1). 2. Append string2 to string. 3. Clear string. 4. Append string3 to string. 5. Delete string (verify by size requested failure). 6. Write a new string (string1), appending string2, string3, and string4. */ /* 1. Write a new string (string1). */ args.fs = fs; args.key = NULL; args.text = bigstring1; args.len = strlen(bigstring1); SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); /* Make sure a key was returned. */ if (! args.key) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "write of new string failed to return new key"); /* Verify record's size and contents. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); /* Append a second string to our first one. */ args.text = bigstring2; args.len = strlen(bigstring2); SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); /* Verify record's size and contents. */ string = svn_stringbuf_create(bigstring1, pool); svn_stringbuf_appendcstr(string, bigstring2); args.text = string->data; args.len = string->len; SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); /* Clear the record */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_clear, &args, pool)); /* Verify record's size and contents. */ args.text = ""; args.len = 0; SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); /* Append a third string to our first one. */ args.text = bigstring3; args.len = strlen(bigstring3); SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); /* Verify record's size and contents. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); /* Delete our record...she's served us well. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_delete, &args, pool)); /* Now, we expect a size request on this record to fail with SVN_ERR_FS_NO_SUCH_STRING. */ { svn_error_t *err = svn_fs_base__retry_txn(args.fs, txn_body_string_size, &args, pool); if (! err) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "query unexpectedly successful"); if (err->apr_err != SVN_ERR_FS_NO_SUCH_STRING) return svn_error_create(SVN_ERR_FS_GENERAL, err, "query failed with unexpected error"); svn_error_clear(err); } return SVN_NO_ERROR;}static svn_error_t *write_null_string(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ struct string_args args; svn_fs_t *fs; *msg = "write a null string"; if (msg_only) return SVN_NO_ERROR; /* Create a new fs and repos */ SVN_ERR(svn_test__create_fs (&fs, "test-repo-test-strings", "bdb", pool)); args.fs = fs; args.key = NULL; args.text = NULL; args.len = 0; SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); return SVN_NO_ERROR;}static svn_error_t *abort_string(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ struct string_args args, args2; svn_fs_t *fs; *msg = "write a string, then abort during an overwrite"; if (msg_only) return SVN_NO_ERROR; /* Create a new fs and repos */ SVN_ERR(svn_test__create_fs (&fs, "test-repo-abort-string", "bdb", pool)); /* The plan: 1. Write a new string (string1). 2. Overwrite string1 with string2, but then ABORT the transaction. 3. Read string to make sure it is still string1. */ /* 1. Write a new string (string1). */ args.fs = fs; args.key = NULL; args.text = bigstring1; args.len = strlen(bigstring1); SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); /* Make sure a key was returned. */ if (! args.key) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "write of new string failed to return new key"); /* Verify record's size and contents. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); /* Append a second string to our first one. */ args2.fs = fs; args2.key = args.key; args2.text = bigstring2; args2.len = strlen(bigstring2); { svn_error_t *err; /* This function is *supposed* to fail with SVN_ERR_TEST_FAILED */ err = svn_fs_base__retry_txn(args.fs, txn_body_string_append_fail, &args2, pool); if ((! err) || (err->apr_err != SVN_ERR_TEST_FAILED)) return svn_error_create(SVN_ERR_TEST_FAILED, err, "failed to intentionally abort a trail"); svn_error_clear(err); } /* Verify that record's size and contents are still that of string1 */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); return SVN_NO_ERROR;}static svn_error_t *copy_string(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ struct string_args args; svn_fs_t *fs; const char *old_key; *msg = "create and copy a string"; if (msg_only) return SVN_NO_ERROR; /* Create a new fs and repos */ SVN_ERR(svn_test__create_fs (&fs, "test-repo-copy-string", "bdb", pool)); /* Write a new string (string1). */ args.fs = fs; args.key = NULL; args.text = bigstring1; args.len = strlen(bigstring1); SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_append, &args, pool)); /* Make sure a key was returned. */ if (! (old_key = args.key)) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "write of new string failed to return new key"); /* Now copy that string into a new location. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_string_copy, &args, pool)); /* Make sure a different key was returned. */ if ((! args.key) || (! strcmp(old_key, args.key))) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "copy of string failed to return new key"); /* Verify record's size and contents. */ SVN_ERR(svn_fs_base__retry_txn(args.fs, txn_body_verify_string, &args, pool)); return SVN_NO_ERROR;}/* The test table. */struct svn_test_descriptor_t test_funcs[] = { SVN_TEST_NULL, SVN_TEST_PASS(write_new_rep), SVN_TEST_PASS(write_rep), SVN_TEST_PASS(read_rep), SVN_TEST_PASS(delete_rep), SVN_TEST_PASS(test_strings), SVN_TEST_PASS(write_null_string), SVN_TEST_PASS(abort_string), SVN_TEST_PASS(copy_string), SVN_TEST_NULL };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -