--- sio_test.c 2003/01/30 16:38:32 1.12
+++ sio_test.c 2003/02/03 17:19:11 1.13
@@ -204,7 +204,7 @@
});
if (rc != SIO_OK) return;
EVAL0("sio_configure_stage(sios_buffer)", {
- rc = sio_configure_stage(sio, sios_buffer, "outputsize", &buflen);
+ rc = sio_configure_stage(sio, sios_buffer, "outputsize", &bufsize);
});
if (rc != SIO_OK) return;
EVAL0("sio_configure_stage(sios_buffer, inputsize)", {
@@ -1052,6 +1052,176 @@
#if ENABLE_ZLIB
TS_TEST(test_sio_zlib)
{
+ sio_rc_t rc;
+ sio_t *sio;
+ sio_stage_t *sios_zlib, *sios_fd;
+ size_t bufsize = 1000; /* input/output buffer size */
+ int zoutlevel = 9; /* compress best on output */
+ int zinlevel = -1; /* decompress input */
+ size_t buflen = 81; /* fd input buffer size */
+ int fd;
+ int i,wcount = 100;
+ char S[] = "Hello world\n";
+ char buf[sizeof(S)];
+ size_t actual, len = strlen(S);
+ char tempfile[] = "./sio_test_tmpfile.XXXXXX";
+ int do_unlink = 0;
+
+ EVAL0("sio_create", {
+ rc = sio_create(&sio);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_create_stage(&sios_fd)", {
+ rc = sio_create_stage(sio, &sio_module_fd, &sios_fd);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_create_stage(&sios_zlib)", {
+ rc = sio_create_stage(sio, &sio_module_zlib, &sios_zlib);
+ });
+ if (rc != SIO_OK) return;
+
+ EVAL0("sio_configure_stage(sios_fd, buflen)", {
+ rc = sio_configure_stage(sio, sios_fd, "buflen", &buflen);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_configure_stage(sios_zlib)", {
+ rc = sio_configure_stage(sio, sios_zlib, "outputsize", &bufsize);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_configure_stage(sios_zlib, inputsize)", {
+ rc = sio_configure_stage(sio, sios_zlib, "inputsize", &bufsize);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_configure_stage(sios_zlib, outputlevel)", {
+ rc = sio_configure_stage(sio, sios_zlib, "outputlevel", &zoutlevel);
+ });
+ if (rc != SIO_OK) return;
+ EVAL0("sio_configure_stage(sios_zlib, inputlevel)", {
+ rc = sio_configure_stage(sio, sios_zlib, "inputlevel", &zinlevel);
+ });
+ if (rc != SIO_OK) return;
+
+ /*
+ * WRITE phase
+ */
+
+ mktemp(tempfile);
+ fd = open(tempfile, O_CREAT|O_EXCL|O_WRONLY, 0600);
+ if (fd < 0) {
+ ts_test_fail(TS_CTX, "cannot create temporary file \"%s\" (%s)\n",
+ tempfile, strerror(errno));
+ } else {
+ do_unlink = 1;
+ EVAL0("sio_configure_stage(sios_fd, fd)", {
+ rc = sio_configure_stage(sio, sios_fd, "fd", &fd);
+ });
+ if (rc != SIO_OK) goto badwrite;
+ EVAL0("sio_attach(sios_fd)", {
+ rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE);
+ });
+ if (rc != SIO_OK) goto badwrite;
+ EVAL0("sio_attach(sios_zlib)", {
+ rc = sio_attach(sio, sios_zlib, SIO_MODE_READWRITE);
+ });
+ if (rc != SIO_OK) goto badwrite2;
+
+ for (i=0; i<wcount; ++i) {
+ EVAL0("sio_write", {
+ rc = sio_write(sio, S, len, &actual);
+ });
+ if (rc != SIO_OK) break;
+ if (actual != len) {
+ ts_test_fail(TS_CTX, "sio_write result %d (expected %d)\n",
+ (int)actual, (int)len);
+ break;
+ }
+ }
+
+ EVAL0("sio_push", {
+ rc = sio_push(sio);
+ });
+
+ EVAL0("sio_detach(sios_zlib)", {
+ rc = sio_detach(sio, sios_zlib);
+ });
+
+ badwrite2:
+ EVAL0("sio_detach(sios_fd)", {
+ rc = sio_detach(sio, sios_fd);
+ });
+
+ badwrite:
+ close(fd);
+ }
+
+ fd = open(tempfile, O_RDONLY);
+ if (fd < 0) {
+ ts_test_fail(TS_CTX, "cannot read temporary file \"%s\" (%s)\n",
+ tempfile, strerror(errno));
+ } else {
+ EVAL0("sio_configure_stage(sios_fd, fd)", {
+ rc = sio_configure_stage(sio, sios_fd, "fd", &fd);
+ });
+ if (rc != SIO_OK) goto badread;
+
+ EVAL0("sio_attach(sios_fd)", {
+ rc = sio_attach(sio, sios_fd, SIO_MODE_READWRITE);
+ });
+ if (rc != SIO_OK) goto badread;
+ EVAL0("sio_attach(sios_zlib)", {
+ rc = sio_attach(sio, sios_zlib, SIO_MODE_READWRITE);
+ });
+ if (rc != SIO_OK) goto badread2;
+
+ for (i=0; i<wcount; ++i) {
+ EVAL0("sio_read", {
+ rc = sreadloop(sio, buf, len, &actual);
+ });
+ if (rc != SIO_OK) break;
+ if (actual != len) {
+ ts_test_fail(TS_CTX, "sio_read result %d (expected %d)\n",
+ (int)actual, (int)len);
+ break;
+ }
+ buf[actual] = '\0';
+ if (strcmp(buf, S)) {
+ ts_test_fail(TS_CTX, "sio_read data mismatch at loop %d\n",
+ i);
+ break;
+ }
+ }
+
+ EVAL0("sio_detach(sios_zlib)", {
+ rc = sio_detach(sio, sios_zlib);
+ });
+
+ badread2:
+ EVAL0("sio_detach(sios_fd)", {
+ rc = sio_detach(sio, sios_fd);
+ });
+
+ badread:
+ close(fd);
+ }
+
+ if (do_unlink && unlink(tempfile) < 0) {
+ ts_test_fail(TS_CTX, "cannot unlink temporary file \"%s\" (%s)\n",
+ tempfile, strerror(errno));
+ }
+
+ /*
+ * common cleanup
+ */
+
+ EVAL0("sio_destroy_stage", {
+ rc = sio_destroy_stage(sio, sios_zlib);
+ });
+ EVAL0("sio_destroy_stage(sios_fd)", {
+ rc = sio_destroy_stage(sio, sios_fd);
+ });
+ EVAL0("sio_destroy", {
+ rc = sio_destroy(sio);
+ });
}
#endif
|