diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-08-05 16:22:51 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-08-05 16:22:51 +0000 |
commit | cf46733632c7279a9fd0fe6ce26f9185a4ae82a9 (patch) | |
tree | da27775a2161723ef342e91af41a8b51fedef405 /subversion/tests/libsvn_wc/pristine-store-test.c | |
parent | bb0ef45f7c46b0ae221b26265ef98a768c33f820 (diff) | |
download | subversion-tarball-master.tar.gz |
subversion-1.9.7HEADsubversion-1.9.7master
Diffstat (limited to 'subversion/tests/libsvn_wc/pristine-store-test.c')
-rw-r--r-- | subversion/tests/libsvn_wc/pristine-store-test.c | 138 |
1 files changed, 65 insertions, 73 deletions
diff --git a/subversion/tests/libsvn_wc/pristine-store-test.c b/subversion/tests/libsvn_wc/pristine-store-test.c index 6df96fc..d9ed077 100644 --- a/subversion/tests/libsvn_wc/pristine-store-test.c +++ b/subversion/tests/libsvn_wc/pristine-store-test.c @@ -70,40 +70,6 @@ create_repos_and_wc(const char **wc_abspath, return SVN_NO_ERROR; } - -/* Write the string DATA into a new unique-named file in the directory - * DIR_ABSPATH. Set *FILE_ABSPATH to its absolute path and *CHECKSUM_SHA1 - * and *CHECKSUM_MD5 to its SHA-1 and MD-5 checksums. - * - * CHECKSUM_SHA1 and/or CHECKSUM_MD5 may be null if not required. */ -static svn_error_t * -write_and_checksum_temp_file(const char **file_abspath, - svn_checksum_t **sha1_checksum, - svn_checksum_t **md5_checksum, - const char *data, - const char *dir_abspath, - apr_pool_t *pool) -{ - apr_file_t *file; - - SVN_ERR(svn_io_open_unique_file3(&file, file_abspath, - dir_abspath, svn_io_file_del_none, - pool, pool)); - - SVN_ERR(svn_io_file_write_full(file, data, strlen(data), NULL, pool)); - SVN_ERR(svn_io_file_close(file, pool)); - - if (sha1_checksum) - SVN_ERR(svn_io_file_checksum2(sha1_checksum, *file_abspath, - svn_checksum_sha1, pool)); - if (md5_checksum) - SVN_ERR(svn_io_file_checksum2(md5_checksum, *file_abspath, - svn_checksum_md5, pool)); - - return SVN_NO_ERROR; -} - - /* Exercise the pristine text API with a simple write and read. */ static svn_error_t * pristine_write_read(const svn_test_opts_t *opts, @@ -112,7 +78,9 @@ pristine_write_read(const svn_test_opts_t *opts, svn_wc__db_t *db; const char *wc_abspath; - const char *pristine_tmp_abspath; + svn_wc__db_install_data_t *install_data; + svn_stream_t *pristine_stream; + apr_size_t sz; const char data[] = "Blah"; svn_string_t *data_string = svn_string_create(data, pool); @@ -123,15 +91,15 @@ pristine_write_read(const svn_test_opts_t *opts, /* Write DATA into a new temporary pristine file, set PRISTINE_TMP_ABSPATH * to its path and set DATA_SHA1 and DATA_MD5 to its checksums. */ - { - const char *pristine_tmp_dir; + SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream, + &install_data, + &data_sha1, &data_md5, + db, wc_abspath, + pool, pool)); - SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db, - wc_abspath, pool, pool)); - SVN_ERR(write_and_checksum_temp_file(&pristine_tmp_abspath, - &data_sha1, &data_md5, - data, pristine_tmp_dir, pool)); - } + sz = strlen(data); + SVN_ERR(svn_stream_write(pristine_stream, data, &sz)); + SVN_ERR(svn_stream_close(pristine_stream)); /* Ensure it's not already in the store. */ { @@ -143,7 +111,7 @@ pristine_write_read(const svn_test_opts_t *opts, } /* Install the new pristine file, referenced by its checksum. */ - SVN_ERR(svn_wc__db_pristine_install(db, pristine_tmp_abspath, + SVN_ERR(svn_wc__db_pristine_install(install_data, data_sha1, data_md5, pool)); /* Ensure it is now found in the store. */ @@ -209,8 +177,10 @@ pristine_delete_while_open(const svn_test_opts_t *opts, { svn_wc__db_t *db; const char *wc_abspath; - const char *pristine_tmp_dir; + svn_wc__db_install_data_t *install_data; + svn_stream_t *pristine_stream; svn_stream_t *contents; + apr_size_t sz; const char data[] = "Blah"; svn_checksum_t *data_sha1, *data_md5; @@ -218,17 +188,17 @@ pristine_delete_while_open(const svn_test_opts_t *opts, SVN_ERR(create_repos_and_wc(&wc_abspath, &db, "pristine_delete_while_open", opts, pool)); - SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db, - wc_abspath, pool, pool)); + SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream, + &install_data, + &data_sha1, &data_md5, + db, wc_abspath, + pool, pool)); - /* Install a pristine text. */ - { - const char *path; - - SVN_ERR(write_and_checksum_temp_file(&path, &data_sha1, &data_md5, - data, pristine_tmp_dir, pool)); - SVN_ERR(svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool)); - } + sz = strlen(data); + SVN_ERR(svn_stream_write(pristine_stream, data, &sz)); + SVN_ERR(svn_stream_close(pristine_stream)); + SVN_ERR(svn_wc__db_pristine_install(install_data, + data_sha1, data_md5, pool)); /* Open it for reading */ SVN_ERR(svn_wc__db_pristine_read(&contents, NULL, db, wc_abspath, data_sha1, @@ -242,7 +212,7 @@ pristine_delete_while_open(const svn_test_opts_t *opts, char buffer[4]; apr_size_t len = 4; - SVN_ERR(svn_stream_read(contents, buffer, &len)); + SVN_ERR(svn_stream_read_full(contents, buffer, &len)); SVN_TEST_ASSERT(len == 4); SVN_TEST_ASSERT(memcmp(buffer, data, len) == 0); } @@ -276,7 +246,6 @@ reject_mismatching_text(const svn_test_opts_t *opts, #ifdef SVN_DEBUG /* The pristine store only checks this in debug mode. */ svn_wc__db_t *db; const char *wc_abspath; - const char *pristine_tmp_dir; const char data[] = "Blah"; svn_checksum_t *data_sha1, *data_md5; @@ -286,28 +255,47 @@ reject_mismatching_text(const svn_test_opts_t *opts, SVN_ERR(create_repos_and_wc(&wc_abspath, &db, "reject_mismatching_text", opts, pool)); - SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db, - wc_abspath, pool, pool)); - /* Install a pristine text. */ { - const char *path; - - SVN_ERR(write_and_checksum_temp_file(&path, &data_sha1, &data_md5, - data, pristine_tmp_dir, pool)); - SVN_ERR(svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool)); + svn_wc__db_install_data_t *install_data; + svn_stream_t *pristine_stream; + apr_size_t sz; + + SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream, + &install_data, + &data_sha1, &data_md5, + db, wc_abspath, + pool, pool)); + + sz = strlen(data); + SVN_ERR(svn_stream_write(pristine_stream, data, &sz)); + SVN_ERR(svn_stream_close(pristine_stream)); + + SVN_ERR(svn_wc__db_pristine_install(install_data, + data_sha1, data_md5, + pool)); } /* Try to install the wrong pristine text against the same checksum. * Should fail. */ { - svn_error_t *err; - const char *path; - - SVN_ERR(write_and_checksum_temp_file(&path, NULL, NULL, - data2, pristine_tmp_dir, pool)); - err = svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool); - SVN_TEST_ASSERT_ERROR(err, SVN_ERR_WC_CORRUPT_TEXT_BASE); + svn_wc__db_install_data_t *install_data; + svn_stream_t *pristine_stream; + apr_size_t sz; + + SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream, + &install_data, + &data_sha1, &data_md5, + db, wc_abspath, + pool, pool)); + + sz = strlen(data2); + SVN_ERR(svn_stream_write(pristine_stream, data2, &sz)); + SVN_ERR(svn_stream_close(pristine_stream)); + + SVN_ERR(svn_wc__db_pristine_install(install_data, + data_sha1, data_md5, + pool)); } return SVN_NO_ERROR; @@ -319,7 +307,9 @@ reject_mismatching_text(const svn_test_opts_t *opts, } -struct svn_test_descriptor_t test_funcs[] = +static int max_threads = -1; + +static struct svn_test_descriptor_t test_funcs[] = { SVN_TEST_NULL, SVN_TEST_OPTS_PASS(pristine_write_read, @@ -330,3 +320,5 @@ struct svn_test_descriptor_t test_funcs[] = "reject_mismatching_text"), SVN_TEST_NULL }; + +SVN_TEST_MAIN |