You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2015/12/10 21:41:12 UTC

svn commit: r1719203 - /subversion/trunk/subversion/tests/libsvn_subr/io-test.c

Author: ivan
Date: Thu Dec 10 20:41:12 2015
New Revision: 1719203

URL: http://svn.apache.org/viewvc?rev=1719203&view=rev
Log:
Add test for svn_io_file_readline().

* subversion/tests/libsvn_subr/io-test.c
  (test_file_readline): New test for svn_io_file_readline().
  (test_funcs): Add test_file_readline to the list.

Modified:
    subversion/trunk/subversion/tests/libsvn_subr/io-test.c

Modified: subversion/trunk/subversion/tests/libsvn_subr/io-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/io-test.c?rev=1719203&r1=1719202&r2=1719203&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/io-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/io-test.c Thu Dec 10 20:41:12 2015
@@ -592,6 +592,93 @@ test_read_length_line(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_file_readline(apr_pool_t *pool)
+{
+  const char *tmp_dir;
+  const char *tmp_file;
+  svn_stringbuf_t *buf;
+  apr_file_t *f;
+  svn_error_t *err;
+  const char *eol;
+  svn_boolean_t eof;
+  apr_off_t pos;
+
+  SVN_ERR(svn_test_make_sandbox_dir(&tmp_dir, "test_file_readline",
+                                    pool));
+
+  tmp_file = svn_dirent_join(tmp_dir, "foo", pool);
+
+  SVN_ERR(svn_io_file_create(tmp_file, "CR\rLF\nCRLF\r\nno-eol", pool));
+
+  SVN_ERR(svn_io_file_open(&f, tmp_file, APR_READ | APR_BUFFERED,
+                           APR_OS_DEFAULT, pool));
+  err = svn_io_file_readline(f, &buf, &eol, &eof, APR_SIZE_MAX, pool, pool);
+  SVN_ERR(err);
+  SVN_TEST_STRING_ASSERT(buf->data, "CR");
+  SVN_TEST_STRING_ASSERT(eol, "\r");
+  SVN_TEST_ASSERT(!eof);
+
+  /* Check that APR file reports correct offset. See r1719196 why it's
+     important. */
+  pos = 0;
+  SVN_ERR(svn_io_file_seek(f, APR_CUR, &pos, pool));
+  SVN_TEST_INT_ASSERT(pos, 3);
+
+  err = svn_io_file_readline(f, &buf, &eol, &eof, APR_SIZE_MAX, pool, pool);
+  SVN_ERR(err);
+  SVN_TEST_STRING_ASSERT(buf->data, "LF");
+  SVN_TEST_STRING_ASSERT(eol, "\n");
+  SVN_TEST_ASSERT(!eof);
+
+  /* Check that APR file reports correct offset. See r1719196 why it's
+     important. */
+  pos = 0;
+  SVN_ERR(svn_io_file_seek(f, APR_CUR, &pos, pool));
+  SVN_TEST_INT_ASSERT(pos, 6);
+
+  err = svn_io_file_readline(f, &buf, &eol, &eof, APR_SIZE_MAX, pool, pool);
+  SVN_ERR(err);
+  SVN_TEST_STRING_ASSERT(buf->data, "CRLF");
+  SVN_TEST_STRING_ASSERT(eol, "\r\n");
+  SVN_TEST_ASSERT(!eof);
+
+  /* Check that APR file reports correct offset. See r1719196 why it's
+     important. */
+  pos = 0;
+  SVN_ERR(svn_io_file_seek(f, APR_CUR, &pos, pool));
+  SVN_TEST_INT_ASSERT(pos, 12);
+
+  err = svn_io_file_readline(f, &buf, &eol, &eof, APR_SIZE_MAX, pool, pool);
+  SVN_ERR(err);
+  SVN_TEST_STRING_ASSERT(buf->data, "no-eol");
+  SVN_TEST_STRING_ASSERT(eol, NULL);
+  SVN_TEST_ASSERT(eof);
+
+  /* Check that APR file reports correct offset. See r1719196 why it's
+     important. */
+  pos = 0;
+  SVN_ERR(svn_io_file_seek(f, APR_CUR, &pos, pool));
+  SVN_TEST_INT_ASSERT(pos, 18);
+
+  /* Further reads still returns EOF. */
+  err = svn_io_file_readline(f, &buf, &eol, &eof, APR_SIZE_MAX, pool, pool);
+  SVN_ERR(err);
+  SVN_TEST_STRING_ASSERT(buf->data, "");
+  SVN_TEST_STRING_ASSERT(eol, NULL);
+  SVN_TEST_ASSERT(eof);
+
+  /* Check that APR file reports correct offset. See r1719196 why it's
+     important. */
+  pos = 0;
+  SVN_ERR(svn_io_file_seek(f, APR_CUR, &pos, pool));
+  SVN_TEST_INT_ASSERT(pos, 18);
+
+  SVN_ERR(svn_io_file_close(f, pool));
+
+  return SVN_NO_ERROR;
+}
+
 /* Move the read pointer in FILE to absolute position OFFSET and align
  * the read buffer to multiples of BLOCK_SIZE.  BUFFERED is set only if
  * FILE actually uses a read buffer.  Use POOL for allocations.
@@ -990,6 +1077,8 @@ static struct svn_test_descriptor_t test
                    "test svn_io_file_rename2"),
     SVN_TEST_PASS2(test_read_length_line,
                    "test svn_io_read_length_line()"),
+    SVN_TEST_PASS2(test_file_readline,
+                   "test svn_io_file_readline()"),
     SVN_TEST_NULL
   };