/* Tests to parse non-valid git diffs. */ static svn_error_t * test_bad_git_diff_headers(apr_pool_t *pool) { svn_patch_file_t *patch_file; svn_patch_t *patch; svn_diff_hunk_t *hunk; SVN_ERR(create_patch_file(&patch_file, bad_git_diff_header, pool)); SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file, FALSE, /* reverse */ FALSE, /* ignore_whitespace */ pool, pool)); SVN_TEST_ASSERT(patch); SVN_TEST_STRING_ASSERT(patch->old_filename, "iota"); SVN_TEST_STRING_ASSERT(patch->new_filename, "iota.copied"); SVN_TEST_ASSERT(patch->operation == svn_diff_op_copied); SVN_TEST_ASSERT(patch->hunks->nelts == 1); hunk = APR_ARRAY_IDX(patch->hunks, 0, svn_diff_hunk_t *); SVN_ERR(check_content(hunk, TRUE, "This is the file 'iota'." NL, pool)); SVN_ERR(check_content(hunk, FALSE, "This is the file 'iota'." NL "some more bytes to 'iota'" NL, pool)); SVN_ERR(svn_diff_close_patch_file(patch_file, pool)); return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf_reader(apr_pool_t *pool) { svn_spillbuf_reader_t *sbr = svn_spillbuf__reader_create(4 /* blocksize */, 100 /* maxsize */, pool); apr_size_t amt; char buf[10]; SVN_ERR(svn_spillbuf__reader_write(sbr, "abcdef", 6, pool)); /* Get a buffer from the underlying reader, and grab a couple bytes. */ SVN_ERR(svn_spillbuf__reader_read(&amt, sbr, buf, 2, pool)); SVN_TEST_ASSERT(amt == 2 && memcmp(buf, "ab", 2) == 0); /* Trigger the internal "save" feature of the SBR. */ SVN_ERR(svn_spillbuf__reader_write(sbr, "ghijkl", 6, pool)); /* Read from the save buffer, and from the internal blocks. */ SVN_ERR(svn_spillbuf__reader_read(&amt, sbr, buf, 10, pool)); SVN_TEST_ASSERT(amt == 10 && memcmp(buf, "cdefghijkl", 10) == 0); /* Should be done. */ SVN_ERR(svn_spillbuf__reader_read(&amt, sbr, buf, 10, pool)); SVN_TEST_ASSERT(amt == 0); return SVN_NO_ERROR; }
static svn_error_t * test_svn_subst_translate_string2(apr_pool_t *pool) { static const struct translate_string2_data_t tests[] = { /* No reencoding, no translation of line endings */ { "abcdefz", "abcdefz", FALSE, FALSE }, /* No reencoding, translation of line endings */ { " \r\n\r\n \r\n \r\n", " \n\n \n \n", FALSE, TRUE }, /* Reencoding, no translation of line endings */ { "\xc7\xa9\xf4\xdf", "\xc3\x87\xc2\xa9\xc3\xb4\xc3\x9f", TRUE, FALSE }, /* Reencoding, translation of line endings */ { "\xc7\xa9\xf4\xdf\r\n", "\xc3\x87\xc2\xa9\xc3\xb4\xc3\x9f\n", TRUE, TRUE }, { NULL, NULL, FALSE, FALSE } }; const struct translate_string2_data_t *t; for (t = tests; t->source != NULL; t++) { svn_string_t *source_string = svn_string_create(t->source, pool); svn_string_t *new_value = NULL; svn_boolean_t translated_line_endings = ! t->translated_line_endings; svn_boolean_t translated_to_utf8; SVN_ERR(svn_subst_translate_string2(&new_value, NULL, &translated_line_endings, source_string, "ISO-8859-1", FALSE, pool, pool)); SVN_TEST_STRING_ASSERT(new_value->data, t->expected_str); SVN_TEST_ASSERT(translated_line_endings == t->translated_line_endings); new_value = NULL; translated_to_utf8 = ! t->translated_to_utf8; translated_line_endings = ! t->translated_line_endings; SVN_ERR(svn_subst_translate_string2(&new_value, &translated_to_utf8, &translated_line_endings, source_string, "ISO-8859-1", FALSE, pool, pool)); SVN_TEST_STRING_ASSERT(new_value->data, t->expected_str); SVN_TEST_ASSERT(translated_to_utf8 == t->translated_to_utf8); SVN_TEST_ASSERT(translated_line_endings == t->translated_line_endings); } /* Test that when REPAIR is FALSE, SVN_ERR_IO_INCONSISTENT_EOL is returned. */ { svn_string_t *source_string = svn_string_create(" \r \r\n \n ", pool); svn_string_t *new_value = NULL; svn_error_t *err = svn_subst_translate_string2(&new_value, NULL, NULL, source_string, "ISO-8859-1", FALSE, pool, pool); SVN_TEST_ASSERT_ERROR(err, SVN_ERR_IO_INCONSISTENT_EOL); } return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf__file_attrs(apr_pool_t *pool, svn_boolean_t spill_all, svn_spillbuf_t *buf) { apr_finfo_t finfo; SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool)); /* Check that the spillbuf size is what we expect it to be */ SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 18); /* Check file existence */ SVN_TEST_ASSERT(svn_spillbuf__get_filename(buf) != NULL); SVN_TEST_ASSERT(svn_spillbuf__get_file(buf) != NULL); /* The size of the file must match expectations */ SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_SIZE, svn_spillbuf__get_file(buf), pool)); if (spill_all) SVN_TEST_ASSERT(finfo.size == svn_spillbuf__get_size(buf)); else SVN_TEST_ASSERT(finfo.size == (svn_spillbuf__get_size(buf) - svn_spillbuf__get_memory_size(buf))); return SVN_NO_ERROR; }
static svn_error_t * short_string_table_body(svn_boolean_t do_load_store, apr_pool_t *pool) { apr_size_t indexes[STRING_COUNT] = { 0 }; string_table_builder_t *builder; string_table_t *table; int i; builder = svn_fs_x__string_table_builder_create(pool); for (i = 0; i < STRING_COUNT; ++i) indexes[i] = svn_fs_x__string_table_builder_add(builder, basic_strings[i], 0); table = svn_fs_x__string_table_create(builder, pool); if (do_load_store) SVN_ERR(store_and_load_table(&table, pool)); SVN_TEST_ASSERT(indexes[2] == indexes[6]); for (i = 0; i < STRING_COUNT; ++i) { apr_size_t len; const char *string = svn_fs_x__string_table_get(table, indexes[i], &len, pool); SVN_TEST_STRING_ASSERT(string, basic_strings[i]); SVN_TEST_ASSERT(len == strlen(string)); SVN_TEST_ASSERT(len == strlen(basic_strings[i])); } SVN_TEST_STRING_ASSERT(svn_fs_x__string_table_get(table, STRING_COUNT, NULL, pool), ""); return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf__basic(apr_pool_t *pool, apr_size_t len, svn_spillbuf_t *buf) { int i; const char *readptr; apr_size_t readlen; /* It starts empty. */ SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0); /* Place enough data into the buffer to cause a spill to disk. */ for (i = 20; i--; ) SVN_ERR(svn_spillbuf__write(buf, basic_data, len, pool)); /* And now has content. */ SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) > 0); /* Verify that we can read 20 copies of basic_data from the buffer. */ for (i = 20; i--; ) CHECK_READ(buf, (i + 1) * len, basic_data, pool); /* And after precisely 20 reads, it should be empty. */ SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, pool)); SVN_TEST_ASSERT(readptr == NULL); SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0); return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf_callback(apr_pool_t *pool) { svn_spillbuf_t *buf = svn_spillbuf__create( sizeof(basic_data) /* blocksize */, 10 * sizeof(basic_data) /* maxsize */, pool); int i; int counter; svn_boolean_t exhausted; /* Place enough data into the buffer to cause a spill to disk. */ for (i = 20; i--; ) SVN_ERR(svn_spillbuf__write(buf, basic_data, sizeof(basic_data), pool)); counter = 0; SVN_ERR(svn_spillbuf__process(&exhausted, buf, read_callback, &counter, pool)); SVN_TEST_ASSERT(!exhausted); SVN_ERR(svn_spillbuf__process(&exhausted, buf, read_callback, &counter, pool)); SVN_TEST_ASSERT(exhausted); return SVN_NO_ERROR; }
static svn_error_t * test_sparse(apr_pool_t *pool) { svn_bit_array__t *array = svn_bit_array__create(0, pool); apr_size_t i, k, min = 0x7ff00, max = 0x7ff00 + 1025, SCALE = 0x10000000; /* All values default to 0. */ for (i = 0; i < 15; ++i) for (k = i * SCALE + min; k < i * SCALE + max; ++k) SVN_TEST_ASSERT(svn_bit_array__get(array, k) == 0); /* Create a pattern, setting every other bit. Array will also auto-grow. */ for (i = 0; i < 15; ++i) for (k = i * SCALE + min; k < i * SCALE + max; ++k) if (k % 2) svn_bit_array__set(array, k, 1); /* Verify pattern */ for (i = 0; i < 15; ++i) for (k = i * SCALE + min; k < i * SCALE + max; ++k) { if (k % 2) SVN_TEST_ASSERT(svn_bit_array__get(array, k) == TRUE); else SVN_TEST_ASSERT(svn_bit_array__get(array, k) == FALSE); } return SVN_NO_ERROR; }
/* Check that reading a line from HUNK equals what's inside EXPECTED. * If ORIGINAL is TRUE, read the original hunk text; else, read the * modified hunk text. */ static svn_error_t * check_content(svn_diff_hunk_t *hunk, svn_boolean_t original, const char *expected, apr_pool_t *pool) { svn_stream_t *exp; svn_stringbuf_t *exp_buf; svn_stringbuf_t *hunk_buf; svn_boolean_t exp_eof; svn_boolean_t hunk_eof; exp = svn_stream_from_string(svn_string_create(expected, pool), pool); while (TRUE) { SVN_ERR(svn_stream_readline(exp, &exp_buf, NL, &exp_eof, pool)); if (original) SVN_ERR(svn_diff_hunk_readline_original_text(hunk, &hunk_buf, NULL, &hunk_eof, pool, pool)); else SVN_ERR(svn_diff_hunk_readline_modified_text(hunk, &hunk_buf, NULL, &hunk_eof, pool, pool)); SVN_TEST_ASSERT(exp_eof == hunk_eof); if (exp_eof) break; SVN_TEST_STRING_ASSERT(exp_buf->data, hunk_buf->data); } if (!hunk_eof) SVN_TEST_ASSERT(hunk_buf->len == 0); return SVN_NO_ERROR; }
static svn_error_t * test_read_only_mode(const svn_test_opts_t *opts, apr_pool_t *pool) { svn_config_t *cfg; svn_config_t *cfg2; const char *cfg_file; SVN_ERR(get_config_file_path(&cfg_file, opts, pool)); SVN_ERR(svn_config_read3(&cfg, cfg_file, TRUE, TRUE, FALSE, pool)); /* setting CFG to r/o mode shall toggle the r/o mode and expand values */ SVN_TEST_ASSERT(!svn_config__is_read_only(cfg)); SVN_TEST_ASSERT(!svn_config__is_expanded(cfg, "section1", "i")); svn_config__set_read_only(cfg, pool); SVN_TEST_ASSERT(svn_config__is_read_only(cfg)); SVN_TEST_ASSERT(svn_config__is_expanded(cfg, "section1", "i")); /* copies should be r/w with values */ SVN_ERR(svn_config_dup(&cfg2, cfg, pool)); SVN_TEST_ASSERT(!svn_config__is_read_only(cfg2)); return SVN_NO_ERROR; }
/* Create a packed filesystem in DIR. Set the shard size to SHARD_SIZE and create NUM_REVS number of revisions (in addition to r0). Use POOL for allocations. After this function successfully completes, the filesystem's youngest revision number will be the same as NUM_REVS. */ static svn_error_t * create_packed_filesystem(const char *dir, const svn_test_opts_t *opts, int num_revs, int shard_size, apr_pool_t *pool) { svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; const char *conflict; svn_revnum_t after_rev; apr_pool_t *subpool = svn_pool_create(pool); apr_pool_t *iterpool; int version; /* Create a filesystem, then close it */ SVN_ERR(svn_test__create_fs(&fs, dir, opts, subpool)); svn_pool_destroy(subpool); subpool = svn_pool_create(pool); /* Rewrite the format file */ SVN_ERR(svn_io_read_version_file(&version, svn_dirent_join(dir, "format", subpool), subpool)); SVN_ERR(write_format(dir, version, shard_size, subpool)); /* Reopen the filesystem */ SVN_ERR(svn_fs_open(&fs, dir, NULL, subpool)); /* Revision 1: the Greek tree */ 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)); SVN_ERR(svn_fs_commit_txn(&conflict, &after_rev, txn, subpool)); SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(after_rev)); /* Revisions 2 thru NUM_REVS-1: content tweaks to "iota". */ iterpool = svn_pool_create(subpool); while (after_rev < num_revs) { svn_pool_clear(iterpool); SVN_ERR(svn_fs_begin_txn(&txn, fs, after_rev, iterpool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, iterpool)); SVN_ERR(svn_test__set_file_contents(txn_root, "iota", get_rev_contents(after_rev + 1, iterpool), iterpool)); SVN_ERR(svn_fs_commit_txn(&conflict, &after_rev, txn, iterpool)); SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(after_rev)); } svn_pool_destroy(iterpool); svn_pool_destroy(subpool); /* Now pack the FS */ return svn_fs_pack(dir, NULL, NULL, NULL, NULL, pool); }
static svn_error_t * test_parse_property_and_text_diff(apr_pool_t *pool) { svn_patch_file_t *patch_file; svn_patch_t *patch; svn_prop_patch_t *prop_patch; svn_diff_hunk_t *hunk; apr_array_header_t *hunks; SVN_ERR(create_patch_file(&patch_file, property_and_text_unidiff, pool)); SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file, FALSE, /* reverse */ FALSE, /* ignore_whitespace */ pool, pool)); SVN_TEST_ASSERT(patch); SVN_TEST_STRING_ASSERT(patch->old_filename, "iota"); SVN_TEST_STRING_ASSERT(patch->new_filename, "iota"); SVN_TEST_ASSERT(patch->hunks->nelts == 1); SVN_TEST_ASSERT(apr_hash_count(patch->prop_patches) == 1); /* Check contents of text hunk */ hunk = APR_ARRAY_IDX(patch->hunks, 0, svn_diff_hunk_t *); SVN_ERR(check_content(hunk, TRUE, "This is the file 'iota'." NL, pool)); SVN_ERR(check_content(hunk, FALSE, "This is the file 'iota'." NL "some more bytes to 'iota'" NL, pool)); /* Check the added property */ prop_patch = apr_hash_get(patch->prop_patches, "prop_add", APR_HASH_KEY_STRING); SVN_TEST_ASSERT(prop_patch->operation == svn_diff_op_added); hunks = prop_patch->hunks; SVN_TEST_ASSERT(hunks->nelts == 1); hunk = APR_ARRAY_IDX(hunks, 0 , svn_diff_hunk_t *); SVN_ERR(check_content(hunk, TRUE, "", pool)); SVN_ERR(check_content(hunk, FALSE, "value" NL, pool)); SVN_ERR(svn_diff_close_patch_file(patch_file, pool)); return SVN_NO_ERROR; }
static svn_error_t * test_zero_defaults(apr_pool_t *pool) { svn_bit_array__t *array = svn_bit_array__create(0, pool); /* Test (default) allocation boundaries */ SVN_TEST_ASSERT(svn_bit_array__get(array, 0x7ffff) == 0); SVN_TEST_ASSERT(svn_bit_array__get(array, 0x80000) == 0); /* Test address boundaries */ SVN_TEST_ASSERT(svn_bit_array__get(array, 0) == 0); SVN_TEST_ASSERT(svn_bit_array__get(array, APR_SIZE_MAX) == 0); return SVN_NO_ERROR; }
static svn_error_t * test_repairing_svn_subst_translate_string2(apr_pool_t *pool) { { svn_string_t *source_string = svn_string_create(" \r \r\n \n ", pool); svn_string_t *new_value = NULL; SVN_ERR(svn_subst_translate_string2(&new_value, NULL, NULL, source_string, "ISO-8859-1", TRUE, pool, pool)); SVN_TEST_ASSERT(new_value != NULL); SVN_TEST_ASSERT(new_value->data != NULL); SVN_TEST_STRING_ASSERT(new_value->data, " \n \n \n "); } return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf_stream(apr_pool_t *pool) { svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, 100 /* maxsize */, pool); svn_stream_t *stream = svn_stream__from_spillbuf(buf, pool); char readbuf[256]; apr_size_t readlen; apr_size_t writelen; writelen = 6; SVN_ERR(svn_stream_write(stream, "abcdef", &writelen)); SVN_ERR(svn_stream_write(stream, "ghijkl", &writelen)); /* now: two blocks: 8 and 4 bytes */ readlen = 8; SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "abcdefgh", 8) == 0); /* now: one block: 4 bytes */ SVN_ERR(svn_stream_write(stream, "mnopqr", &writelen)); /* now: two blocks: 8 and 2 bytes */ SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "ijklmnop", 8) == 0); /* now: one block: 2 bytes */ SVN_ERR(svn_stream_write(stream, "stuvwx", &writelen)); SVN_ERR(svn_stream_write(stream, "ABCDEF", &writelen)); SVN_ERR(svn_stream_write(stream, "GHIJKL", &writelen)); /* now: two blocks: 8 and 6 bytes, and 6 bytes spilled to a file */ SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 8 && memcmp(readbuf, "qrstuvwx", 8) == 0); readlen = 6; SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 6 && memcmp(readbuf, "ABCDEF", 6) == 0); SVN_ERR(svn_stream_read_full(stream, readbuf, &readlen)); SVN_TEST_ASSERT(readlen == 6 && memcmp(readbuf, "GHIJKL", 6) == 0); return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf__interleaving(apr_pool_t *pool, svn_spillbuf_t* buf) { SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); /* now: two blocks: 8 and 4 bytes */ CHECK_READ(buf, 12, "abcdefgh", pool); /* now: one block: 4 bytes */ SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool)); /* now: two blocks: 8 and 2 bytes */ CHECK_READ(buf, 10, "ijklmnop", pool); /* now: one block: 2 bytes */ SVN_ERR(svn_spillbuf__write(buf, "stuvwx", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ABCDEF", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "GHIJKL", 6, pool)); /* now: two blocks: 8 and 6 bytes, and 6 bytes spilled to a file */ CHECK_READ(buf, 20, "qrstuvwx", pool); CHECK_READ(buf, 12, "ABCDEF", pool); CHECK_READ(buf, 6, "GHIJKL", pool); SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0); return SVN_NO_ERROR; }
static svn_error_t * read_callback(svn_boolean_t *stop, void *baton, const char *data, apr_size_t len, apr_pool_t *scratch_pool) { int *counter = baton; SVN_TEST_ASSERT(len == sizeof(basic_data)); SVN_TEST_ASSERT(memcmp(data, basic_data, len) == 0); *stop = (++*counter == 10); return SVN_NO_ERROR; }
/* Create a repository with a filesystem based on OPTS in a subdir NAME, * commit the standard Greek tree as revision 1, and set *REPOS_URL to * the URL we will use to access it. * * ### This always returns a file: URL. We should upgrade this to use the * test suite's specified URL scheme instead. */ static svn_error_t * create_greek_repos(const char **repos_url, const char *name, const svn_test_opts_t *opts, apr_pool_t *pool) { svn_repos_t *repos; svn_revnum_t committed_rev; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; /* Create a filesytem and repository. */ SVN_ERR(svn_test__create_repos(&repos, name, opts, pool)); /* Prepare and commit a txn containing the Greek tree. */ SVN_ERR(svn_fs_begin_txn2(&txn, svn_repos_fs(repos), 0 /* rev */, 0 /* flags */, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); SVN_ERR(svn_test__create_greek_tree(txn_root, pool)); SVN_ERR(svn_repos_fs_commit_txn(NULL, repos, &committed_rev, txn, pool)); SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(committed_rev)); SVN_ERR(svn_uri_get_file_url_from_dirent(repos_url, name, pool)); return SVN_NO_ERROR; }
static svn_error_t * commit_packed_fs(const svn_test_opts_t *opts, apr_pool_t *pool) { svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; const char *conflict; svn_revnum_t after_rev; /* Bail (with success) on known-untestable scenarios */ if ((strcmp(opts->fs_type, "fsfs") != 0) || (opts->server_minor_version && (opts->server_minor_version < 6))) return SVN_NO_ERROR; /* Create the packed FS and open it. */ SVN_ERR(create_packed_filesystem(REPO_NAME, opts, MAX_REV, 5, pool)); SVN_ERR(svn_fs_open(&fs, REPO_NAME, NULL, pool)); /* Now do a commit. */ SVN_ERR(svn_fs_begin_txn(&txn, fs, MAX_REV, pool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool)); SVN_ERR(svn_test__set_file_contents(txn_root, "iota", "How much better is it to get wisdom than gold! and to get " "understanding rather to be chosen than silver!", pool)); SVN_ERR(svn_fs_commit_txn(&conflict, &after_rev, txn, pool)); SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(after_rev)); return SVN_NO_ERROR; }
static svn_error_t * test_parse_unidiff_lacking_trailing_eol(apr_pool_t *pool) { svn_patch_file_t *patch_file; svn_boolean_t reverse; svn_boolean_t ignore_whitespace; int i; apr_pool_t *iterpool; reverse = FALSE; ignore_whitespace = FALSE; iterpool = svn_pool_create(pool); for (i = 0; i < 2; i++) { svn_patch_t *patch; svn_diff_hunk_t *hunk; svn_pool_clear(iterpool); SVN_ERR(create_patch_file(&patch_file, unidiff_lacking_trailing_eol, pool)); /* We have one patch with one hunk. Parse it. */ SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file, reverse, ignore_whitespace, iterpool, iterpool)); SVN_TEST_ASSERT(patch); SVN_TEST_STRING_ASSERT(patch->old_filename, "A/C/gamma"); SVN_TEST_STRING_ASSERT(patch->new_filename, "A/C/gamma"); SVN_TEST_ASSERT(patch->hunks->nelts == 1); hunk = APR_ARRAY_IDX(patch->hunks, 0, svn_diff_hunk_t *); SVN_ERR(check_content(hunk, ! reverse, "This is the file 'gamma'." NL, pool)); SVN_ERR(check_content(hunk, reverse, "This is the file 'gamma'." NL "some more bytes to 'gamma'", pool)); reverse = !reverse; SVN_ERR(svn_diff_close_patch_file(patch_file, pool)); } svn_pool_destroy(iterpool); return SVN_NO_ERROR; }
static svn_error_t * check_read(svn_spillbuf_t *buf, svn_filesize_t starting_size, const char *expected, apr_pool_t *scratch_pool) { apr_size_t expected_len = strlen(expected); const char *readptr; apr_size_t readlen; SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == starting_size); SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, scratch_pool)); SVN_TEST_ASSERT(readptr != NULL && readlen == expected_len && memcmp(readptr, expected, expected_len) == 0); return SVN_NO_ERROR; }
static svn_error_t * test_entries_alloc(apr_pool_t *pool) { svn_wc__db_t *db; const char *local_abspath; svn_wc_adm_access_t *adm_access; apr_hash_t *entries; const svn_wc_entry_t *entry; const char *local_relpath; #undef WC_NAME #define WC_NAME "test_entries_alloc" SVN_ERR(create_open(&db, &local_abspath, WC_NAME, pool)); SVN_ERR(svn_wc_adm_open3(&adm_access, NULL /* associated */, svn_dirent_join("fake-wc", WC_NAME, pool), FALSE /* write_lock */, 0 /* levels_to_lock */, NULL /* cancel_func */, NULL /* cancel_baton */, pool)); SVN_ERR(svn_wc_entries_read(&entries, adm_access, TRUE /* show_hidden */, pool)); /* The wcroot has 12 BASE children + 1 WORKING child + "this dir". */ SVN_TEST_ASSERT(apr_hash_count(entries) == 14); /* The "D" entry in the entries hash should be what we get from the svn_wc_entry() entrypoint. */ local_relpath = svn_dirent_join_many(pool, "fake-wc", WC_NAME, "D", NULL); SVN_ERR(svn_wc_entry(&entry, local_relpath, adm_access, TRUE, pool)); SVN_TEST_ASSERT(entry == apr_hash_get(entries, "D", APR_HASH_KEY_STRING)); /* This entry should be missing. */ SVN_ERR(svn_wc_entry(&entry, "missing", adm_access, TRUE, pool)); SVN_TEST_ASSERT(entry == NULL); return SVN_NO_ERROR; }
static svn_error_t * test_svn_subst_build_keywords3(apr_pool_t *pool) { /* Test expansion of custom keywords. */ struct keywords_tests_data { const char *keyword_name; const char *keywords_string; const char *expanded_keyword; const char *rev; const char *url; const char *repos_root_url; /* Can't test date since expanded value depends on local clock. */ const char *author; } tests[] = { {"FOO", "FOO=%P%_%a%_%b%_%%", "trunk/foo.txt stsp foo.txt %", "1234", "http://svn.example.com/repos/trunk/foo.txt", "http://svn.example.com/repos", "stsp"}, {"FOO", "FOO=author%_=%_%a", "author = stsp", "1234", "http://svn.example.com/repos/trunk/foo.txt", "http://svn.example.com/repos", "stsp"}, {"MyKeyword", "MyKeyword=%r%_%u%_%_%a", "4567 http://svn.example.com/svn/branches/myfile jrandom", "4567", "http://svn.example.com/svn/branches/myfile", "http://svn.example.com/svn", "jrandom"}, {"FreeBSD", "FreeBSD=%H", "head/README 222812 joel", /* date is not expanded in this test */ "222812", "http://svn.freebsd.org/base/head/README", "http://svn.freebsd.org/base", "joel"}, {"FreeBSD", "FreeBSD=%I", "README 222812 joel", /* date is not expanded in this test */ "222812", "http://svn.freebsd.org/base/head/README", "http://svn.freebsd.org/base", "joel"}, { NULL, NULL, NULL, NULL, NULL, NULL, NULL} }; const struct keywords_tests_data *t; for (t = tests; t->keyword_name != NULL; t++) { apr_hash_t *kw; svn_string_t *expanded_keyword; SVN_ERR(svn_subst_build_keywords3(&kw, t->keywords_string, t->rev, t->url, t->repos_root_url, 0 /* date */, t->author, pool)); expanded_keyword = svn_hash_gets(kw, t->keyword_name); SVN_TEST_ASSERT(expanded_keyword != NULL); SVN_TEST_STRING_ASSERT(expanded_keyword->data, t->expanded_keyword); } return SVN_NO_ERROR; }
static svn_error_t * test_stringbuf_from_stream(apr_pool_t *pool) { const char *test_cases[] = { "", "x", "this string is longer than the default 64 minimum block size used" "by the function under test", NULL }; const char **test_case; for (test_case = test_cases; *test_case; ++test_case) { svn_stringbuf_t *result1, *result2, *result3, *result4; svn_stringbuf_t *original = svn_stringbuf_create(*test_case, pool); svn_stream_t *stream1 = svn_stream_from_stringbuf(original, pool); svn_stream_t *stream2 = svn_stream_from_stringbuf(original, pool); SVN_ERR(svn_stringbuf_from_stream(&result1, stream1, 0, pool)); SVN_ERR(svn_stringbuf_from_stream(&result2, stream1, 0, pool)); SVN_ERR(svn_stringbuf_from_stream(&result3, stream2, original->len, pool)); SVN_ERR(svn_stringbuf_from_stream(&result4, stream2, original->len, pool)); /* C-string contents must match */ SVN_TEST_STRING_ASSERT(result1->data, original->data); SVN_TEST_STRING_ASSERT(result2->data, ""); SVN_TEST_STRING_ASSERT(result3->data, original->data); SVN_TEST_STRING_ASSERT(result4->data, ""); /* assumed length must match */ SVN_TEST_ASSERT(result1->len == original->len); SVN_TEST_ASSERT(result2->len == 0); SVN_TEST_ASSERT(result3->len == original->len); SVN_TEST_ASSERT(result4->len == 0); } return SVN_NO_ERROR; }
static svn_error_t * test_checksum_empty(apr_pool_t *pool) { svn_checksum_t *checksum; char data = '\0'; checksum = svn_checksum_empty_checksum(svn_checksum_md5, pool); SVN_TEST_ASSERT(svn_checksum_is_empty_checksum(checksum)); checksum = svn_checksum_empty_checksum(svn_checksum_sha1, pool); SVN_TEST_ASSERT(svn_checksum_is_empty_checksum(checksum)); SVN_ERR(svn_checksum(&checksum, svn_checksum_md5, &data, 0, pool)); SVN_TEST_ASSERT(svn_checksum_is_empty_checksum(checksum)); SVN_ERR(svn_checksum(&checksum, svn_checksum_sha1, &data, 0, pool)); SVN_TEST_ASSERT(svn_checksum_is_empty_checksum(checksum)); return SVN_NO_ERROR; }
static svn_error_t * many_strings_table_body(svn_boolean_t do_load_store, apr_pool_t *pool) { /* cause multiple sub-tables (6 to be exact) to be created */ enum { COUNT = 100 }; svn_stringbuf_t *strings[COUNT] = { 0 }; apr_size_t indexes[COUNT] = { 0 }; string_table_builder_t *builder; string_table_t *table; int i; builder = svn_fs_x__string_table_builder_create(pool); for (i = 0; i < COUNT; ++i) { strings[i] = generate_string(APR_UINT64_C(0x1234567876543210) * (i + 1), (i * i) % 23000, pool); indexes[i] = svn_fs_x__string_table_builder_add(builder, strings[i]->data, strings[i]->len); } table = svn_fs_x__string_table_create(builder, pool); if (do_load_store) SVN_ERR(store_and_load_table(&table, pool)); for (i = 0; i < COUNT; ++i) { apr_size_t len; const char *string = svn_fs_x__string_table_get(table, indexes[i], &len, pool); SVN_TEST_STRING_ASSERT(string, strings[i]->data); SVN_TEST_ASSERT(len == strlen(string)); SVN_TEST_ASSERT(len == strings[i]->len); } return SVN_NO_ERROR; }
static svn_error_t * recover_fully_packed(const svn_test_opts_t *opts, apr_pool_t *pool) { apr_pool_t *subpool; svn_fs_t *fs; svn_fs_txn_t *txn; svn_fs_root_t *txn_root; const char *conflict; svn_revnum_t after_rev; svn_error_t *err; /* Bail (with success) on known-untestable scenarios */ if ((strcmp(opts->fs_type, "fsfs") != 0) || (opts->server_minor_version && (opts->server_minor_version < 7))) return SVN_NO_ERROR; /* Create a packed FS for which every revision will live in a pack digest file, and then recover it. */ SVN_ERR(create_packed_filesystem(REPO_NAME, opts, MAX_REV, SHARD_SIZE, pool)); SVN_ERR(svn_fs_recover(REPO_NAME, NULL, NULL, pool)); /* Add another revision, re-pack, re-recover. */ subpool = svn_pool_create(pool); SVN_ERR(svn_fs_open(&fs, REPO_NAME, NULL, subpool)); SVN_ERR(svn_fs_begin_txn(&txn, fs, MAX_REV, subpool)); SVN_ERR(svn_fs_txn_root(&txn_root, txn, subpool)); SVN_ERR(svn_test__set_file_contents(txn_root, "A/mu", "new-mu", subpool)); SVN_ERR(svn_fs_commit_txn(&conflict, &after_rev, txn, subpool)); SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(after_rev)); svn_pool_destroy(subpool); SVN_ERR(svn_fs_pack(REPO_NAME, NULL, NULL, NULL, NULL, pool)); SVN_ERR(svn_fs_recover(REPO_NAME, NULL, NULL, pool)); /* Now, delete the youngest revprop file, and recover again. This time we want to see an error! */ SVN_ERR(svn_io_remove_file2( svn_dirent_join_many(pool, REPO_NAME, PATH_REVPROPS_DIR, apr_psprintf(pool, "%ld/%ld", after_rev / SHARD_SIZE, after_rev), NULL), FALSE, pool)); err = svn_fs_recover(REPO_NAME, NULL, NULL, pool); if (! err) return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "Expected SVN_ERR_FS_CORRUPT error; got none"); if (err->apr_err != SVN_ERR_FS_CORRUPT) return svn_error_create(SVN_ERR_TEST_FAILED, err, "Expected SVN_ERR_FS_CORRUPT error; got:"); svn_error_clear(err); return SVN_NO_ERROR; }
static svn_error_t * test_spillbuf_eof(apr_pool_t *pool) { svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */, 10 /* maxsize */, pool); SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); /* now: two blocks: 4 and 2 bytes, and 6 bytes in spill file. */ CHECK_READ(buf, 12, "abcd", pool); CHECK_READ(buf, 8, "ef", pool); CHECK_READ(buf, 6, "ghij", pool); CHECK_READ(buf, 2, "kl", pool); /* The spill file should have been emptied and forgotten. */ /* Assuming the spill file has been forgotten, this should result in precisely the same behavior. Specifically: the initial write should create two blocks, and the second write should be spilled. If there *was* a spill file, then this written data would go into the file. */ SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); CHECK_READ(buf, 12, "abcd", pool); CHECK_READ(buf, 8, "ef", pool); CHECK_READ(buf, 6, "ghij", pool); CHECK_READ(buf, 2, "kl", pool); /* The spill file should have been emptied and forgotten. */ /* Now, let's do a sequence where we arrange to hit EOF precisely on a block-sized read. Note: the second write must be more than 4 bytes, or it will not cause a spill. We use 8 to get the right boundary. */ SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijklmn", 8, pool)); CHECK_READ(buf, 14, "abcd", pool); CHECK_READ(buf, 10, "ef", pool); CHECK_READ(buf, 8, "ghij", pool); CHECK_READ(buf, 4, "klmn", pool); /* We discard the spill file when we know it has no data, rather than upon hitting EOF (upon a read attempt). Thus, the spill file should be gone. */ /* Verify the forgotten spill file. */ SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool)); SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool)); CHECK_READ(buf, 12, "abcd", pool); CHECK_READ(buf, 8, "ef", pool); CHECK_READ(buf, 6, "ghij", pool); /* Two unread bytes remaining in the spill file. */ SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 2); return SVN_NO_ERROR; }
/* The body of the svn_subst_translate_string2_null_encoding test. It should only be called by test_svn_subst_translate_string2_null_encoding(), as this code assumes that the process locale has been changed to a locale that uses either CP-1252 or ISO-8859-1 for the default narrow string encoding. */ static svn_error_t * test_svn_subst_translate_string2_null_encoding_helper(apr_pool_t *pool) { { svn_string_t *new_value = NULL; svn_boolean_t translated_to_utf8 = FALSE; svn_boolean_t translated_line_endings = TRUE; /* The 'AE' ligature, which is 0xc6 in both ISO-8859-1 and Windows-1252 */ svn_string_t *source_string = svn_string_create("\xc6", pool); SVN_ERR(svn_subst_translate_string2(&new_value, &translated_to_utf8, &translated_line_endings, source_string, NULL, FALSE, pool, pool)); SVN_TEST_STRING_ASSERT(new_value->data, "\xc3\x86"); SVN_TEST_ASSERT(translated_to_utf8); SVN_TEST_ASSERT(!translated_line_endings); } return SVN_NO_ERROR; }
static svn_error_t * test_pseudo_md5(apr_pool_t *pool) { apr_uint32_t input[16] = { 0 }; apr_uint32_t digest_15[4] = { 0 }; apr_uint32_t digest_31[4] = { 0 }; apr_uint32_t digest_63[4] = { 0 }; svn_checksum_t *checksum; /* input is all 0s but the hash shall be different (due to different input sizes)*/ svn__pseudo_md5_15(digest_15, input); svn__pseudo_md5_31(digest_31, input); svn__pseudo_md5_63(digest_63, input); SVN_TEST_ASSERT(memcmp(digest_15, digest_31, sizeof(digest_15))); SVN_TEST_ASSERT(memcmp(digest_15, digest_63, sizeof(digest_15))); SVN_TEST_ASSERT(memcmp(digest_31, digest_63, sizeof(digest_15))); /* the checksums shall also be different from "proper" MD5 */ SVN_ERR(svn_checksum(&checksum, svn_checksum_md5, input, 15, pool)); SVN_TEST_ASSERT(memcmp(digest_15, checksum->digest, sizeof(digest_15))); SVN_ERR(svn_checksum(&checksum, svn_checksum_md5, input, 31, pool)); SVN_TEST_ASSERT(memcmp(digest_31, checksum->digest, sizeof(digest_15))); SVN_ERR(svn_checksum(&checksum, svn_checksum_md5, input, 63, pool)); SVN_TEST_ASSERT(memcmp(digest_63, checksum->digest, sizeof(digest_15))); return SVN_NO_ERROR; }