You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2004/11/17 13:00:10 UTC
svn commit: rev 76115 - in apr/apr/trunk: file_io/unix test
Author: jorton
Date: Wed Nov 17 04:00:08 2004
New Revision: 76115
Modified:
apr/apr/trunk/file_io/unix/readwrite.c
apr/apr/trunk/test/testfile.c
Log:
* file_io/unix/readwrite.c (apr_file_puts): Use apr_file_write_full.
* test/testfile.c (test_puts, file_contents_equal): Test
apr_file_puts.
Modified: apr/apr/trunk/file_io/unix/readwrite.c
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Wed Nov 17 04:00:08 2004
@@ -268,9 +268,7 @@
APR_DECLARE(apr_status_t) apr_file_puts(const char *str, apr_file_t *thefile)
{
- apr_size_t nbytes = strlen(str);
-
- return apr_file_write(thefile, str, &nbytes);
+ return apr_file_write_full(thefile, str, strlen(str), NULL);
}
APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile)
Modified: apr/apr/trunk/test/testfile.c
==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Wed Nov 17 04:00:08 2004
@@ -505,6 +505,52 @@
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
+/* Test that the contents of file FNAME are equal to data EXPECT of
+ * length EXPECTLEN. */
+static void file_contents_equal(abts_case *tc,
+ const char *fname,
+ const void *expect,
+ apr_size_t expectlen)
+{
+ void *actual = apr_palloc(p, expectlen);
+ apr_file_t *f;
+
+ APR_ASSERT_SUCCESS(tc, "open file",
+ apr_file_open(&f, fname, APR_READ|APR_BUFFERED,
+ 0, p));
+ APR_ASSERT_SUCCESS(tc, "read from file",
+ apr_file_read_full(f, actual, expectlen, NULL));
+
+ ABTS_ASSERT(tc, "matched expected file contents",
+ memcmp(expect, actual, expectlen) == 0);
+
+ APR_ASSERT_SUCCESS(tc, "close file", apr_file_close(f));
+}
+
+#define LINE1 "this is a line of text\n"
+#define LINE2 "this is a second line of text\n"
+
+static void test_puts(abts_case *tc, void *data)
+{
+ apr_file_t *f;
+ const char *fname = "data/testputs.txt";
+
+ APR_ASSERT_SUCCESS(tc, "open file for writing",
+ apr_file_open(&f, fname,
+ APR_WRITE|APR_CREATE|APR_TRUNCATE,
+ APR_OS_DEFAULT, p));
+
+ APR_ASSERT_SUCCESS(tc, "write line to file",
+ apr_file_puts(LINE1, f));
+ APR_ASSERT_SUCCESS(tc, "write second line to file",
+ apr_file_puts(LINE2, f));
+
+ APR_ASSERT_SUCCESS(tc, "close for writing",
+ apr_file_close(f));
+
+ file_contents_equal(tc, fname, LINE1 LINE2, strlen(LINE1 LINE2));
+}
+
static void test_truncate(abts_case *tc, void *data)
{
apr_status_t rv;
@@ -567,6 +613,7 @@
abts_run_test(suite, test_getc, NULL);
abts_run_test(suite, test_ungetc, NULL);
abts_run_test(suite, test_gets, NULL);
+ abts_run_test(suite, test_puts, NULL);
abts_run_test(suite, test_bigread, NULL);
abts_run_test(suite, test_mod_neg, NULL);
abts_run_test(suite, test_truncate, NULL);