You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@apache.org on 2003/07/10 21:57:58 UTC
cvs commit: apr/test testfile.c
trawick 2003/07/10 12:57:58
Modified: test testfile.c
Log:
add a test that concentrates on APR_TRUNCATE
Revision Changes Path
1.71 +40 -0 apr/test/testfile.c
Index: testfile.c
===================================================================
RCS file: /home/cvs/apr/test/testfile.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- testfile.c 28 May 2003 19:25:33 -0000 1.70
+++ testfile.c 10 Jul 2003 19:57:58 -0000 1.71
@@ -506,6 +506,45 @@
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 @@
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;
}