diff options
author | Ivan Zhakov <ivan@apache.org> | 2022-06-20 21:57:13 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2022-06-20 21:57:13 +0000 |
commit | 49c44db709237e40a01b2f572bba420265c8db72 (patch) | |
tree | cbe15eb7e6ad8440d4c92d37e26253b6cd6403e7 /test | |
parent | abdf8ec5aa6d483cac6460a47f8f7458b05ad513 (diff) | |
download | apr-49c44db709237e40a01b2f572bba420265c8db72.tar.gz |
On 1.8.x branch: Merge r1770471, r1770489 from trunk:
r1770471: Add test for apr_file_open(APR_FOPEN_APPEND).
r1770489: Follow-up to r1770471: resolve two compiler warnings in
testfile.c.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1902120 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/testfile.c | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/test/testfile.c b/test/testfile.c index 25bfef5bf..3f4c6e03e 100644 --- a/test/testfile.c +++ b/test/testfile.c @@ -1254,6 +1254,74 @@ static void test_datasync_on_stream(abts_case *tc, void *data) ABTS_TRUE(tc, rv == APR_SUCCESS || APR_STATUS_IS_EINVAL(rv)); } +static void test_append(abts_case *tc, void *data) +{ + apr_file_t *f1; + apr_file_t *f2; + const char *fname = "data/testappend.dat"; + apr_int32_t flags = APR_FOPEN_CREATE | APR_FOPEN_READ | APR_FOPEN_WRITE | APR_FOPEN_APPEND; + char buf[128]; + apr_off_t offset; + + apr_file_remove(fname, p); + + /* Open test file with APR_FOPEN_APPEND, but without APR_FOPEN_XTHREAD. */ + APR_ASSERT_SUCCESS(tc, "open test file", + apr_file_open(&f1, fname, flags, APR_FPROT_OS_DEFAULT, p)); + + /* Open test file with APR_FOPEN_APPEND and APR_FOPEN_XTHREAD. */ + APR_ASSERT_SUCCESS(tc, "open test file", + apr_file_open(&f2, fname, flags | APR_FOPEN_XTHREAD, APR_FPROT_OS_DEFAULT, p)); + + APR_ASSERT_SUCCESS(tc, "write should succeed", + apr_file_puts("w1", f1)); + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f1, APR_CUR, &offset)); + ABTS_INT_EQUAL(tc, 2, (int) offset); + + APR_ASSERT_SUCCESS(tc, "write should succeed", + apr_file_puts("w2", f2)); + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f2, APR_CUR, &offset)); + ABTS_INT_EQUAL(tc, 4, (int) offset); + + APR_ASSERT_SUCCESS(tc, "write should succeed", + apr_file_puts("w3", f1)); + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f1, APR_CUR, &offset)); + ABTS_INT_EQUAL(tc, 6, (int) offset); + + APR_ASSERT_SUCCESS(tc, "write should succeed", + apr_file_puts("w4", f2)); + + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f2, APR_CUR, &offset)); + ABTS_INT_EQUAL(tc, 8, (int) offset); + + /* Check file content file using F1. */ + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f1, APR_SET, &offset)); + memset(buf, 0, sizeof(buf)); + apr_file_read_full(f1, buf, sizeof(buf), NULL); + ABTS_STR_EQUAL(tc, "w1w2w3w4", buf); + + /* Check file content file using F2. */ + offset = 0; + APR_ASSERT_SUCCESS(tc, "seek should succeed", + apr_file_seek(f2, APR_SET, &offset)); + memset(buf, 0, sizeof(buf)); + apr_file_read_full(f2, buf, sizeof(buf), NULL); + ABTS_STR_EQUAL(tc, "w1w2w3w4", buf); + + apr_file_close(f1); + apr_file_close(f2); +} + abts_suite *testfile(abts_suite *suite) { suite = ADD_SUITE(suite) @@ -1298,8 +1366,7 @@ abts_suite *testfile(abts_suite *suite) abts_run_test(suite, test_fail_read_flush, NULL); abts_run_test(suite, test_buffer_set_get, NULL); abts_run_test(suite, test_xthread, 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, NULL); return suite; } |