Extend stream unit testing by test code for svn_stream_skip. * subversion/tests/libsvn_subr/stream-test.c (test_stream_seek_file, test_stream_seek_stringbuf, test_stream_seek_translated): replicate seek&read code to test skip() git-svn-id: https://svn.apache.org/repos/asf/subversion/branches/integrate-stream-api-extensions@1072516 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/subversion/tests/libsvn_subr/stream-test.c b/subversion/tests/libsvn_subr/stream-test.c index 66e911c..5a48175 100644 --- a/subversion/tests/libsvn_subr/stream-test.c +++ b/subversion/tests/libsvn_subr/stream-test.c
@@ -259,6 +259,7 @@ apr_status_t status; static const char *NL = APR_EOL_STR; svn_stream_mark_t *mark; + apr_size_t count; status = apr_file_open(&f, fname, (APR_READ | APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_DELONCLOSE), APR_OS_DEFAULT, pool); @@ -301,6 +302,19 @@ SVN_ERR(svn_stream_readline(stream, &line, NL, &eof, pool)); SVN_TEST_ASSERT(eof); + /* Go back to the begin of last line and try to skip it + * NOT including the EOL. */ + SVN_ERR(svn_stream_seek(stream, mark)); + count = strlen(file_data[1]); + SVN_ERR(svn_stream_skip(stream, &count)); + SVN_TEST_ASSERT(count == strlen(file_data[1])); + /* The remaining line should be empty */ + SVN_ERR(svn_stream_readline(stream, &line, NL, &eof, pool)); + SVN_TEST_ASSERT(! eof && strcmp(line->data, "") == 0); + /* The next read should return EOF. */ + SVN_ERR(svn_stream_readline(stream, &line, NL, &eof, pool)); + SVN_TEST_ASSERT(eof); + SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; @@ -332,6 +346,18 @@ buf[3] = '\0'; SVN_TEST_STRING_ASSERT(buf, "Two"); + /* Go back to the begin of last word and try to skip some of it */ + SVN_ERR(svn_stream_seek(stream, mark)); + len = 2; + SVN_ERR(svn_stream_skip(stream, &len)); + SVN_TEST_ASSERT(len == 2); + /* The remaining line should be empty */ + len = 3; + SVN_ERR(svn_stream_read(stream, buf, &len)); + buf[len] = '\0'; + SVN_TEST_ASSERT(len == 1); + SVN_TEST_STRING_ASSERT(buf, "o"); + SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR; @@ -370,6 +396,16 @@ buf[4] = '\0'; SVN_TEST_STRING_ASSERT(buf, " was"); + SVN_ERR(svn_stream_seek(translated_stream, mark)); + len = 2; + SVN_ERR(svn_stream_skip(translated_stream, &len)); + SVN_TEST_ASSERT(len == 2); + len = 2; + SVN_ERR(svn_stream_read(translated_stream, buf, &len)); + SVN_TEST_ASSERT(len == 2); + buf[len] = '\0'; + SVN_TEST_STRING_ASSERT(buf, "as"); + /* Seek from inside of keyword to inside of keyword. */ SVN_ERR(svn_stream_mark(translated_stream, &mark, pool)); len = 9; @@ -384,6 +420,16 @@ buf[9] = '\0'; SVN_TEST_STRING_ASSERT(buf, " expanded"); + SVN_ERR(svn_stream_seek(translated_stream, mark)); + len = 6; + SVN_ERR(svn_stream_skip(translated_stream, &len)); + SVN_TEST_ASSERT(len == 6); + len = 3; + SVN_ERR(svn_stream_read(translated_stream, buf, &len)); + SVN_TEST_ASSERT(len == 3); + buf[len] = '\0'; + SVN_TEST_STRING_ASSERT(buf, "ded"); + /* Seek from inside of keyword to outside of keyword. */ SVN_ERR(svn_stream_mark(translated_stream, &mark, pool)); len = 4; @@ -398,6 +444,16 @@ buf[4] = '\0'; SVN_TEST_STRING_ASSERT(buf, " $Tw"); + SVN_ERR(svn_stream_seek(translated_stream, mark)); + len = 2; + SVN_ERR(svn_stream_skip(translated_stream, &len)); + SVN_TEST_ASSERT(len == 2); + len = 2; + SVN_ERR(svn_stream_read(translated_stream, buf, &len)); + SVN_TEST_ASSERT(len == 2); + buf[len] = '\0'; + SVN_TEST_STRING_ASSERT(buf, "Tw"); + /* Seek from outside of keyword to outside of keyword. */ SVN_ERR(svn_stream_mark(translated_stream, &mark, pool)); len = 1; @@ -412,6 +468,16 @@ buf[1] = '\0'; SVN_TEST_STRING_ASSERT(buf, "o"); + SVN_ERR(svn_stream_seek(translated_stream, mark)); + len = 2; + SVN_ERR(svn_stream_skip(translated_stream, &len)); + SVN_TEST_ASSERT(len == 1); + len = 1; + SVN_ERR(svn_stream_read(translated_stream, buf, &len)); + SVN_TEST_ASSERT(len == 0); + buf[len] = '\0'; + SVN_TEST_STRING_ASSERT(buf, ""); + SVN_ERR(svn_stream_close(stream)); return SVN_NO_ERROR;