You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2010/12/10 17:52:09 UTC
svn commit: r1044432 - /apr/apr/trunk/test/testfile.c
Author: mturk
Date: Fri Dec 10 16:52:09 2010
New Revision: 1044432
URL: http://svn.apache.org/viewvc?rev=1044432&view=rev
Log:
Add apr_file_trunc test case. It currently fails for APR_FOPEN_BUFFERED because write buffer is flushed after ftruncate call
Modified:
apr/apr/trunk/test/testfile.c
Modified: apr/apr/trunk/test/testfile.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testfile.c?rev=1044432&r1=1044431&r2=1044432&view=diff
==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Fri Dec 10 16:52:09 2010
@@ -810,6 +810,62 @@ static void test_truncate(abts_case *tc,
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
+static void test_file_trunc(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_file_t *f;
+ const char *fname = "data/testtruncate.dat";
+ const char *s;
+ apr_size_t nbytes;
+ apr_finfo_t finfo;
+
+ apr_file_remove(fname, p);
+
+ /* Test unbuffered */
+ rv = apr_file_open(&f, fname,
+ APR_FOPEN_CREATE | APR_FOPEN_READ |
+ APR_FOPEN_WRITE,
+ APR_UREAD | APR_UWRITE, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ s = "some data";
+ nbytes = strlen(s);
+ rv = apr_file_write(f, s, &nbytes);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
+ rv = apr_file_trunc(f, 4);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_file_close(f);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);
+
+ rv = apr_file_remove(fname, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ /* Test buffered */
+ rv = apr_file_open(&f, fname,
+ APR_FOPEN_CREATE | APR_FOPEN_READ |
+ APR_FOPEN_WRITE | APR_FOPEN_BUFFERED,
+ APR_UREAD | APR_UWRITE, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ nbytes = strlen(s);
+ rv = apr_file_write(f, s, &nbytes);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
+ rv = apr_file_trunc(f, 4);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_file_close(f);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);
+
+ rv = apr_file_remove(fname, p);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+}
+
static void test_bigfprintf(abts_case *tc, void *data)
{
apr_file_t *f;
@@ -1003,6 +1059,7 @@ abts_suite *testfile(abts_suite *suite)
abts_run_test(suite, test_bigread, NULL);
abts_run_test(suite, test_mod_neg, NULL);
abts_run_test(suite, test_truncate, NULL);
+ abts_run_test(suite, test_file_trunc, NULL);
abts_run_test(suite, test_bigfprintf, NULL);
abts_run_test(suite, test_fail_write_flush, NULL);
abts_run_test(suite, test_fail_read_flush, NULL);