📄 fs-test.c
字号:
/* Step 1. Find it by name in the hash of all rev. props returned to us by svn_fs_revision_proplist. If it can't be found, return an error. */ prop_value = apr_hash_get(proplist, final_props[i][0], APR_HASH_KEY_STRING); if (! prop_value) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "unable to find expected revision property"); /* Step 2. Make sure the value associated with it is the same as what was expected, else return an error. */ if (strcmp(final_props[i][0], SVN_PROP_REVISION_DATE)) if (strcmp(prop_value->data, final_props[i][1])) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "revision property had an unexpected value"); } } return SVN_NO_ERROR;}static svn_error_t *node_props(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; apr_hash_t *proplist; svn_string_t *value; int i; svn_string_t s1; const char *initial_props[4][2] = { { "Best Rock Artist", "Creed" }, { "Best Rap Artist", "Eminem" }, { "Best Country Artist", "(null)" }, { "Best Sound Designer", "Pluessman" } }; const char *final_props[4][2] = { { "Best Rock Artist", "P.O.D." }, { "Best Rap Artist", "Busta Rhymes" }, { "Best Sound Designer", "Pluessman" }, { "Biggest Cakewalk Fanatic", "Pluessman" } }; *msg = "set and get some node properties"; if (msg_only) return SVN_NO_ERROR; /* Open the fs and transaction */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-node-props", opts->fs_type, pool)); SVN_ERR(svn_fs_begin_txn(&txn, fs, 0, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); /* Make a node to put some properties into */ SVN_ERR(svn_fs_make_file(txn_root, "music.txt", pool)); /* Set some properties on the nodes. */ for (i = 0; i < 4; i++) { SET_STR(&s1, initial_props[i][1]); SVN_ERR(svn_fs_change_node_prop (txn_root, "music.txt", initial_props[i][0], &s1, pool)); } /* Change some of the above properties. */ SET_STR(&s1, "P.O.D."); SVN_ERR(svn_fs_change_node_prop(txn_root, "music.txt", "Best Rock Artist", &s1, pool)); SET_STR(&s1, "Busta Rhymes"); SVN_ERR(svn_fs_change_node_prop(txn_root, "music.txt", "Best Rap Artist", &s1, pool)); /* Remove a property altogether */ SVN_ERR(svn_fs_change_node_prop(txn_root, "music.txt", "Best Country Artist", NULL, pool)); /* Copy a property's value into a new property. */ SVN_ERR(svn_fs_node_prop(&value, txn_root, "music.txt", "Best Sound Designer", pool)); s1.data = value->data; s1.len = value->len; SVN_ERR(svn_fs_change_node_prop(txn_root, "music.txt", "Biggest Cakewalk Fanatic", &s1, pool)); /* Obtain a list of all current properties, and make sure it matches the expected values. */ SVN_ERR(svn_fs_node_proplist(&proplist, txn_root, "music.txt", pool)); { svn_string_t *prop_value; if (apr_hash_count(proplist) != 4 ) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "unexpected number of node properties were found"); /* Loop through our list of expected node property name/value pairs. */ for (i = 0; i < 4; i++) { /* For each expected property: */ /* Step 1. Find it by name in the hash of all node props returned to us by svn_fs_node_proplist. If it can't be found, return an error. */ prop_value = apr_hash_get(proplist, final_props[i][0], APR_HASH_KEY_STRING); if (! prop_value) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "unable to find expected node property"); /* Step 2. Make sure the value associated with it is the same as what was expected, else return an error. */ if (strcmp(prop_value->data, final_props[i][1])) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "node property had an unexpected value"); } } return SVN_NO_ERROR;}/* Set *PRESENT to true if entry NAME is present in directory PATH under ROOT, else set *PRESENT to false. */static svn_error_t *check_entry(svn_fs_root_t *root, const char *path, const char *name, svn_boolean_t *present, apr_pool_t *pool){ apr_hash_t *entries; svn_fs_dirent_t *ent; SVN_ERR(svn_fs_dir_entries(&entries, root, path, pool)); ent = apr_hash_get(entries, name, APR_HASH_KEY_STRING); if (ent) *present = TRUE; else *present = FALSE; return SVN_NO_ERROR;}/* Return an error if entry NAME is absent in directory PATH under ROOT. */static svn_error_t *check_entry_present(svn_fs_root_t *root, const char *path, const char *name, apr_pool_t *pool){ svn_boolean_t present; SVN_ERR(check_entry(root, path, name, &present, pool)); if (! present) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "entry \"%s\" absent when it should be present", name); return SVN_NO_ERROR;}/* Return an error if entry NAME is present in directory PATH under ROOT. */static svn_error_t *check_entry_absent(svn_fs_root_t *root, const char *path, const char *name, apr_pool_t *pool){ svn_boolean_t present; SVN_ERR(check_entry(root, path, name, &present, pool)); if (present) return svn_error_createf (SVN_ERR_FS_GENERAL, NULL, "entry \"%s\" present when it should be absent", name); return SVN_NO_ERROR;}/* Fetch the youngest revision from a repos. */static svn_error_t *fetch_youngest_rev(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; svn_revnum_t new_rev; svn_revnum_t youngest_rev, new_youngest_rev; *msg = "fetch the youngest revision from a filesystem"; if (msg_only) return SVN_NO_ERROR; SVN_ERR(svn_test__create_fs(&fs, "test-repo-youngest-rev", opts->fs_type, pool)); /* Get youngest revision of brand spankin' new filesystem. */ SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, pool)); /* Prepare a txn to receive the greek tree. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, 0, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); /* Create the greek tree. */ SVN_ERR(svn_test__create_greek_tree(txn_root, pool)); /* Commit it. */ SVN_ERR(test_commit_txn(&new_rev, txn, NULL, pool)); /* Get the new youngest revision. */ SVN_ERR(svn_fs_youngest_rev(&new_youngest_rev, fs, pool)); if (youngest_rev == new_rev) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "commit didn't bump up revision number"); if (new_youngest_rev != new_rev) return svn_error_create(SVN_ERR_FS_GENERAL, NULL, "couldn't fetch youngest revision"); return SVN_NO_ERROR;}/* Test committing against an empty repository. todo: also test committing against youngest? */static svn_error_t *basic_commit(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root, *revision_root; svn_revnum_t before_rev, after_rev; const char *conflict; *msg = "basic commit"; if (msg_only) return SVN_NO_ERROR; /* Prepare a filesystem. */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-basic-commit", opts->fs_type, pool)); /* Save the current youngest revision. */ SVN_ERR(svn_fs_youngest_rev(&before_rev, fs, pool)); /* Prepare a txn to receive the greek tree. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, 0, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); /* Paranoidly check that the current youngest rev is unchanged. */ SVN_ERR(svn_fs_youngest_rev(&after_rev, fs, pool)); if (after_rev != before_rev) return svn_error_create (SVN_ERR_FS_GENERAL, NULL, "youngest revision changed unexpectedly"); /* Create the greek tree. */ SVN_ERR(svn_test__create_greek_tree(txn_root, pool)); /* Commit it. */ SVN_ERR(svn_fs_commit_txn(&conflict, &after_rev, txn, pool)); /* Make sure it's a different revision than before. */ if (after_rev == before_rev) return svn_error_create (SVN_ERR_FS_GENERAL, NULL, "youngest revision failed to change"); /* Get root of the revision */ SVN_ERR(svn_fs_revision_root(&revision_root, fs, after_rev, pool)); /* Check the tree. */ SVN_ERR(svn_test__check_greek_tree(revision_root, pool)); return SVN_NO_ERROR;}static svn_error_t *test_tree_node_validation(const char **msg, svn_boolean_t msg_only, svn_test_opts_t *opts, apr_pool_t *pool){ svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root, *revision_root; svn_revnum_t after_rev; const char *conflict; apr_pool_t *subpool; *msg = "testing tree validation helper"; if (msg_only) return SVN_NO_ERROR; /* Prepare a filesystem. */ SVN_ERR(svn_test__create_fs(&fs, "test-repo-validate-tree-entries", opts->fs_type, pool)); /* In a txn, create the greek tree. */ subpool = svn_pool_create(pool); { static svn_test__tree_entry_t expected_entries[] = { /* path, contents (0 = dir) */ { "iota", "This is the file 'iota'.\n" }, { "A", 0 }, { "A/mu", "This is the file 'mu'.\n" }, { "A/B", 0 }, { "A/B/lambda", "This is the file 'lambda'.\n" }, { "A/B/E", 0 }, { "A/B/E/alpha", "This is the file 'alpha'.\n" }, { "A/B/E/beta", "This is the file 'beta'.\n" }, { "A/B/F", 0 }, { "A/C", 0 }, { "A/D", 0 }, { "A/D/gamma", "This is the file 'gamma'.\n" }, { "A/D/G", 0 }, { "A/D/G/pi", "This is the file 'pi'.\n" }, { "A/D/G/rho", "This is the file 'rho'.\n" }, { "A/D/G/tau", "This is the file 'tau'.\n" }, { "A/D/H", 0 }, { "A/D/H/chi", "This is the file 'chi'.\n" }, { "A/D/H/psi", "This is the file 'psi'.\n" }, { "A/D/H/omega", "This is the file 'omega'.\n" } }; SVN_ERR(svn_fs_begin_txn(&txn, fs, 0, subpool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool)); SVN_ERR(svn_test__create_greek_tree(txn_root, subpool)); /* Carefully validate that tree in the transaction. */ SVN_ERR(svn_test__validate_tree(txn_root, expected_entries, 20, subpool)); /* Go ahead and commit the tree, and destroy the txn object. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -