summaryrefslogtreecommitdiff
path: root/test/testfile.c
diff options
context:
space:
mode:
authortrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-07-10 19:57:58 +0000
committertrawick <trawick@13f79535-47bb-0310-9956-ffa450edef68>2003-07-10 19:57:58 +0000
commit524ac3812ba9cf75caa571628f7cc6d46a753821 (patch)
treef894eef94637f11043670630aa88c8c170219cd1 /test/testfile.c
parentcdb1cc0907900a44242b27d2b99474e0d0e1d8ba (diff)
downloadlibapr-524ac3812ba9cf75caa571628f7cc6d46a753821.tar.gz
add a test that concentrates on APR_TRUNCATE
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64567 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testfile.c')
-rw-r--r--test/testfile.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/testfile.c b/test/testfile.c
index 604ca605b..0bd4af9e0 100644
--- a/test/testfile.c
+++ b/test/testfile.c
@@ -506,6 +506,45 @@ static void test_mod_neg(CuTest *tc)
CuAssertIntEquals(tc, APR_SUCCESS, rv);
}
+static void test_truncate(CuTest *tc)
+{
+ 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);
+
+ rv = apr_file_open(&f, fname,
+ APR_CREATE | APR_WRITE, APR_UREAD | APR_UWRITE, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ s = "some data";
+ nbytes = strlen(s);
+ rv = apr_file_write(f, s, &nbytes);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, strlen(s), nbytes);
+
+ rv = apr_file_close(f);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_file_open(&f, fname,
+ APR_TRUNCATE | APR_WRITE, APR_UREAD | APR_UWRITE, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_file_close(f);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+
+ rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+ CuAssertIntEquals(tc, 0, finfo.size);
+
+ rv = apr_file_remove(fname, p);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
+}
+
CuSuite *testfile(void)
{
CuSuite *suite = CuSuiteNew("File I/O");
@@ -530,6 +569,7 @@ CuSuite *testfile(void)
SUITE_ADD_TEST(suite, test_gets);
SUITE_ADD_TEST(suite, test_bigread);
SUITE_ADD_TEST(suite, test_mod_neg);
+ SUITE_ADD_TEST(suite, test_truncate);
return suite;
}