summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kotkov <kotkov@apache.org>2023-04-12 12:54:19 +0000
committerEvgeny Kotkov <kotkov@apache.org>2023-04-12 12:54:19 +0000
commita1f1f0ce477a78f22ba6ce198c95d460ad1488cd (patch)
treeb2d92f638a3858c41553d1e30901353caf9ea362
parent9e0ea97b831fa473b2ce8d33cfb2a70bc818c39d (diff)
downloadapr-a1f1f0ce477a78f22ba6ce198c95d460ad1488cd.tar.gz
Add a regression test for the issue where appending to a buffered file
was causing the content to be written at offset 0, rather than appended (see r1909088). * test/testfile.c (test_append_buffered): New test. (testfile): Run the new test. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1909089 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--test/testfile.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/testfile.c b/test/testfile.c
index 7e1102415..5df4d7106 100644
--- a/test/testfile.c
+++ b/test/testfile.c
@@ -2198,6 +2198,50 @@ static void test_datasync_on_stream(abts_case *tc, void *data)
}
}
+static void test_append_buffered(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_file_t *f;
+ const char *fname = "data/testappend_buffered.dat";
+ apr_size_t bytes_written;
+ char buf[64];
+
+ apr_file_remove(fname, p);
+
+ /* Create file with contents. */
+ rv = apr_file_open(&f, fname, APR_FOPEN_WRITE | APR_FOPEN_CREATE,
+ APR_FPROT_OS_DEFAULT, p);
+ APR_ASSERT_SUCCESS(tc, "create file", rv);
+
+ rv = apr_file_write_full(f, "abc", 3, &bytes_written);
+ APR_ASSERT_SUCCESS(tc, "write to file", rv);
+ apr_file_close(f);
+
+ /* Re-open it with APR_FOPEN_APPEND and APR_FOPEN_BUFFERED. */
+ rv = apr_file_open(&f, fname,
+ APR_FOPEN_READ | APR_FOPEN_WRITE |
+ APR_FOPEN_APPEND | APR_FOPEN_BUFFERED,
+ APR_FPROT_OS_DEFAULT, p);
+ APR_ASSERT_SUCCESS(tc, "open file", rv);
+
+ /* Append to the file. */
+ rv = apr_file_write_full(f, "def", 3, &bytes_written);
+ APR_ASSERT_SUCCESS(tc, "write to file", rv);
+ apr_file_close(f);
+
+ rv = apr_file_open(&f, fname, APR_FOPEN_READ,
+ APR_FPROT_OS_DEFAULT, p);
+ APR_ASSERT_SUCCESS(tc, "open file", rv);
+
+ /* Test the file contents. */
+ rv = apr_file_gets(buf, sizeof(buf), f);
+ APR_ASSERT_SUCCESS(tc, "read from file", rv);
+ ABTS_STR_EQUAL(tc, "abcdef", buf);
+
+ apr_file_close(f);
+ apr_file_remove(fname, p);
+}
+
abts_suite *testfile(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -2262,6 +2306,7 @@ abts_suite *testfile(abts_suite *suite)
abts_run_test(suite, test_read_buffered_seek, NULL);
abts_run_test(suite, test_datasync_on_file, NULL);
abts_run_test(suite, test_datasync_on_stream, NULL);
+ abts_run_test(suite, test_append_buffered, NULL);
return suite;
}