From a1f1f0ce477a78f22ba6ce198c95d460ad1488cd Mon Sep 17 00:00:00 2001 From: Evgeny Kotkov Date: Wed, 12 Apr 2023 12:54:19 +0000 Subject: 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 --- test/testfile.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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; } -- cgit v1.2.1