|
@@ -345,76 +345,6 @@ test_buffers(void)
|
|
|
buf_free(buf);
|
|
|
buf = NULL;
|
|
|
|
|
|
-#if 0
|
|
|
- {
|
|
|
- int s;
|
|
|
- int eof;
|
|
|
- int i;
|
|
|
- buf_t *buf2;
|
|
|
- /****
|
|
|
- * read_to_buf
|
|
|
- ****/
|
|
|
- s = open(get_fname("data"), O_WRONLY|O_CREAT|O_TRUNC, 0600);
|
|
|
- write(s, str, 256);
|
|
|
- close(s);
|
|
|
-
|
|
|
- s = open(get_fname("data"), O_RDONLY, 0);
|
|
|
- eof = 0;
|
|
|
- errno = 0; /* XXXX */
|
|
|
- i = read_to_buf(s, 10, buf, &eof);
|
|
|
- printf("%s\n", strerror(errno));
|
|
|
- test_eq(i, 10);
|
|
|
- test_eq(eof, 0);
|
|
|
- //test_eq(buf_capacity(buf), 4096);
|
|
|
- test_eq(buf_datalen(buf), 10);
|
|
|
-
|
|
|
- test_memeq(str, (char*)_buf_peek_raw_buffer(buf), 10);
|
|
|
-
|
|
|
- /* Test reading 0 bytes. */
|
|
|
- i = read_to_buf(s, 0, buf, &eof);
|
|
|
- //test_eq(buf_capacity(buf), 512*1024);
|
|
|
- test_eq(buf_datalen(buf), 10);
|
|
|
- test_eq(eof, 0);
|
|
|
- test_eq(i, 0);
|
|
|
-
|
|
|
- /* Now test when buffer is filled exactly. */
|
|
|
- buf2 = buf_new_with_capacity(6);
|
|
|
- i = read_to_buf(s, 6, buf2, &eof);
|
|
|
- //test_eq(buf_capacity(buf2), 6);
|
|
|
- test_eq(buf_datalen(buf2), 6);
|
|
|
- test_eq(eof, 0);
|
|
|
- test_eq(i, 6);
|
|
|
- test_memeq(str+10, (char*)_buf_peek_raw_buffer(buf2), 6);
|
|
|
- buf_free(buf2);
|
|
|
- buf2 = NULL;
|
|
|
-
|
|
|
- /* Now test when buffer is filled with more data to read. */
|
|
|
- buf2 = buf_new_with_capacity(32);
|
|
|
- i = read_to_buf(s, 128, buf2, &eof);
|
|
|
- //test_eq(buf_capacity(buf2), 128);
|
|
|
- test_eq(buf_datalen(buf2), 32);
|
|
|
- test_eq(eof, 0);
|
|
|
- test_eq(i, 32);
|
|
|
- buf_free(buf2);
|
|
|
- buf2 = NULL;
|
|
|
-
|
|
|
- /* Now read to eof. */
|
|
|
- test_assert(buf_capacity(buf) > 256);
|
|
|
- i = read_to_buf(s, 1024, buf, &eof);
|
|
|
- test_eq(i, (256-32-10-6));
|
|
|
- test_eq(buf_capacity(buf), MAX_BUF_SIZE);
|
|
|
- test_eq(buf_datalen(buf), 256-6-32);
|
|
|
- test_memeq(str, (char*)_buf_peek_raw_buffer(buf), 10); /* XXX Check rest. */
|
|
|
- test_eq(eof, 0);
|
|
|
-
|
|
|
- i = read_to_buf(s, 1024, buf, &eof);
|
|
|
- test_eq(i, 0);
|
|
|
- test_eq(buf_capacity(buf), MAX_BUF_SIZE);
|
|
|
- test_eq(buf_datalen(buf), 256-6-32);
|
|
|
- test_eq(eof, 1);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
done:
|
|
|
if (buf)
|
|
|
buf_free(buf);
|