332
332
stringbuf = svn_stringbuf_create("OneTwo", pool);
333
333
stream = svn_stream_from_stringbuf(stringbuf, pool);
335
SVN_ERR(svn_stream_read(stream, buf, &len));
335
SVN_ERR(svn_stream_read_full(stream, buf, &len));
337
337
SVN_TEST_STRING_ASSERT(buf, "One");
338
338
SVN_ERR(svn_stream_mark(stream, &mark, pool));
340
SVN_ERR(svn_stream_read(stream, buf, &len));
340
SVN_ERR(svn_stream_read_full(stream, buf, &len));
342
342
SVN_TEST_STRING_ASSERT(buf, "Two");
343
343
SVN_ERR(svn_stream_seek(stream, mark));
345
SVN_ERR(svn_stream_read(stream, buf, &len));
345
SVN_ERR(svn_stream_read_full(stream, buf, &len));
347
347
SVN_TEST_STRING_ASSERT(buf, "Two");
351
351
SVN_ERR(svn_stream_skip(stream, 2));
352
352
/* The remaining line should be empty */
354
SVN_ERR(svn_stream_read(stream, buf, &len));
354
SVN_ERR(svn_stream_read_full(stream, buf, &len));
356
356
SVN_TEST_ASSERT(len == 1);
357
357
SVN_TEST_STRING_ASSERT(buf, "o");
381
381
FALSE, keywords, TRUE, pool);
382
382
/* Seek from outside of keyword to inside of keyword. */
384
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
384
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
385
385
SVN_TEST_ASSERT(len == 25);
387
387
SVN_TEST_STRING_ASSERT(buf, "One$MyKeyword: my keyword");
389
389
SVN_ERR(svn_stream_reset(translated_stream));
390
390
SVN_ERR(svn_stream_seek(translated_stream, mark));
392
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
392
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
393
393
SVN_TEST_ASSERT(len == 4);
395
395
SVN_TEST_STRING_ASSERT(buf, " was");
397
397
SVN_ERR(svn_stream_seek(translated_stream, mark));
398
398
SVN_ERR(svn_stream_skip(translated_stream, 2));
400
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
400
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
401
401
SVN_TEST_ASSERT(len == 2);
403
403
SVN_TEST_STRING_ASSERT(buf, "as");
405
405
/* Seek from inside of keyword to inside of keyword. */
406
406
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
408
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
408
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
409
409
SVN_TEST_ASSERT(len == 9);
411
411
SVN_TEST_STRING_ASSERT(buf, " expanded");
412
412
SVN_ERR(svn_stream_seek(translated_stream, mark));
414
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
414
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
415
415
SVN_TEST_ASSERT(len == 9);
417
417
SVN_TEST_STRING_ASSERT(buf, " expanded");
419
419
SVN_ERR(svn_stream_seek(translated_stream, mark));
420
420
SVN_ERR(svn_stream_skip(translated_stream, 6));
422
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
422
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
423
423
SVN_TEST_ASSERT(len == 3);
425
425
SVN_TEST_STRING_ASSERT(buf, "ded");
427
427
/* Seek from inside of keyword to outside of keyword. */
428
428
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
430
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
430
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
431
431
SVN_TEST_ASSERT(len == 4);
433
433
SVN_TEST_STRING_ASSERT(buf, " $Tw");
434
434
SVN_ERR(svn_stream_seek(translated_stream, mark));
436
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
436
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
437
437
SVN_TEST_ASSERT(len == 4);
439
439
SVN_TEST_STRING_ASSERT(buf, " $Tw");
441
441
SVN_ERR(svn_stream_seek(translated_stream, mark));
442
442
SVN_ERR(svn_stream_skip(translated_stream, 2));
444
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
444
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
445
445
SVN_TEST_ASSERT(len == 2);
447
447
SVN_TEST_STRING_ASSERT(buf, "Tw");
449
449
/* Seek from outside of keyword to outside of keyword. */
450
450
SVN_ERR(svn_stream_mark(translated_stream, &mark, pool));
452
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
452
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
453
453
SVN_TEST_ASSERT(len == 1);
455
455
SVN_TEST_STRING_ASSERT(buf, "o");
456
456
SVN_ERR(svn_stream_seek(translated_stream, mark));
458
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
458
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
459
459
SVN_TEST_ASSERT(len == 1);
461
461
SVN_TEST_STRING_ASSERT(buf, "o");
463
463
SVN_ERR(svn_stream_seek(translated_stream, mark));
464
464
SVN_ERR(svn_stream_skip(translated_stream, 2));
466
SVN_ERR(svn_stream_read(translated_stream, buf, &len));
466
SVN_ERR(svn_stream_read_full(translated_stream, buf, &len));
467
467
SVN_TEST_ASSERT(len == 0);
469
469
SVN_TEST_STRING_ASSERT(buf, "");
525
525
stream = svn_stream_compressed(empty_file_stream, pool);
526
526
len = sizeof(buf);
527
SVN_ERR(svn_stream_read(stream, buf, &len));
527
SVN_ERR(svn_stream_read_full(stream, buf, &len));
529
529
return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
530
530
"Got unexpected result.");
727
727
return SVN_NO_ERROR;
731
test_stringbuf_from_stream(apr_pool_t *pool)
733
const char *test_cases[] =
737
"this string is longer than the default 64 minimum block size used"
738
"by the function under test",
742
const char **test_case;
743
for (test_case = test_cases; *test_case; ++test_case)
745
svn_stringbuf_t *result1, *result2, *result3, *result4;
746
svn_stringbuf_t *original = svn_stringbuf_create(*test_case, pool);
748
svn_stream_t *stream1 = svn_stream_from_stringbuf(original, pool);
749
svn_stream_t *stream2 = svn_stream_from_stringbuf(original, pool);
751
SVN_ERR(svn_stringbuf_from_stream(&result1, stream1, 0, pool));
752
SVN_ERR(svn_stringbuf_from_stream(&result2, stream1, 0, pool));
753
SVN_ERR(svn_stringbuf_from_stream(&result3, stream2, original->len,
755
SVN_ERR(svn_stringbuf_from_stream(&result4, stream2, original->len,
758
/* C-string contents must match */
759
SVN_TEST_STRING_ASSERT(result1->data, original->data);
760
SVN_TEST_STRING_ASSERT(result2->data, "");
761
SVN_TEST_STRING_ASSERT(result3->data, original->data);
762
SVN_TEST_STRING_ASSERT(result4->data, "");
764
/* assumed length must match */
765
SVN_TEST_ASSERT(result1->len == original->len);
766
SVN_TEST_ASSERT(result2->len == 0);
767
SVN_TEST_ASSERT(result3->len == original->len);
768
SVN_TEST_ASSERT(result4->len == 0);
775
empty_read_full_fn(void *baton, char *buffer, apr_size_t *len)
782
test_stream_compressed_read_full(apr_pool_t *pool)
784
svn_stream_t *stream, *empty_stream;
788
/* Reading an empty stream with read_full only support should not error. */
789
empty_stream = svn_stream_create(NULL, pool);
791
/* Create stream with only full read support. */
792
svn_stream_set_read2(empty_stream, NULL, empty_read_full_fn);
794
stream = svn_stream_compressed(empty_stream, pool);
796
SVN_ERR(svn_stream_read_full(stream, buf, &len));
798
return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
799
"Got unexpected result.");
801
SVN_ERR(svn_stream_close(stream));
730
806
/* The test table. */
732
struct svn_test_descriptor_t test_funcs[] =
808
static int max_threads = 1;
810
static struct svn_test_descriptor_t test_funcs[] =
735
813
SVN_TEST_PASS2(test_stream_from_string,
752
830
"test base64 encoding/decoding streams"),
753
831
SVN_TEST_PASS2(test_stream_base64_2,
754
832
"base64 decoding allocation problem"),
833
SVN_TEST_PASS2(test_stringbuf_from_stream,
834
"test svn_stringbuf_from_stream"),
835
SVN_TEST_PASS2(test_stream_compressed_read_full,
836
"test compression for streams without partial read"),