summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-06-05 16:50:52 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-06-05 16:50:52 (GMT)
commitdc3657b1b7d4d243084c3d11d2ddf5ff47135ebc (patch)
tree5ba1a872ee13097c5b0ffc00a36071620475e015
parentc4e779ece448364066a7669b7040a9bdbcc632a9 (diff)
downloadtcl-dc3657b1b7d4d243084c3d11d2ddf5ff47135ebc.zip
tcl-dc3657b1b7d4d243084c3d11d2ddf5ff47135ebc.tar.gz
tcl-dc3657b1b7d4d243084c3d11d2ddf5ff47135ebc.tar.bz2
more test tinkering
-rw-r--r--generic/tclZlib.c32
-rw-r--r--tests/zlib.test9
2 files changed, 25 insertions, 16 deletions
diff --git a/generic/tclZlib.c b/generic/tclZlib.c
index 537fa68..333c2fa 100644
--- a/generic/tclZlib.c
+++ b/generic/tclZlib.c
@@ -146,7 +146,8 @@ static Tcl_DriverWatchProc ZlibTransformWatch;
static Tcl_ObjCmdProc ZlibCmd;
static Tcl_ObjCmdProc ZlibStreamCmd;
-static void ConvertError(Tcl_Interp *interp, int code);
+static void ConvertError(Tcl_Interp *interp, int code,
+ uLong adler);
static void ExtractHeader(gz_header *headerPtr, Tcl_Obj *dictObj);
static int GenerateHeader(Tcl_Interp *interp, Tcl_Obj *dictObj,
GzipHeader *headerPtr, int *extraSizePtr);
@@ -210,7 +211,8 @@ static void
ConvertError(
Tcl_Interp *interp, /* Interpreter to store the error in. May be
* NULL, in which case nothing happens. */
- int code) /* The zlib error code. */
+ int code, /* The zlib error code. */
+ uLong adler) /* The checksum expected (for Z_NEED_DICT) */
{
if (interp == NULL) {
return;
@@ -228,7 +230,11 @@ ConvertError(
case Z_MEM_ERROR: codeStr = "MEM"; break;
case Z_BUF_ERROR: codeStr = "BUF"; break;
case Z_VERSION_ERROR: codeStr = "VERSION"; break;
- case Z_NEED_DICT: codeStr = "NEED_DICT"; break;
+ case Z_NEED_DICT:
+ codeStr = "NEED_DICT";
+ codeStr2 = codeStrBuf;
+ sprintf(codeStrBuf, "%lu", adler);
+ break;
default:
codeStr = "unknown";
codeStr2 = codeStrBuf;
@@ -640,7 +646,7 @@ Tcl_ZlibStreamInit(
}
if (e != Z_OK) {
- ConvertError(interp, e);
+ ConvertError(interp, e, zshPtr->stream.adler);
goto error;
}
@@ -886,7 +892,7 @@ Tcl_ZlibStreamReset(
}
if (e != Z_OK) {
- ConvertError(zshPtr->interp, e);
+ ConvertError(zshPtr->interp, e, zshPtr->stream.adler);
/* TODO:cleanup */
return TCL_ERROR;
}
@@ -1047,7 +1053,7 @@ Tcl_ZlibStreamPut(
e = SetDeflateDictionary(&zshPtr->stream, zshPtr->compDictObj);
if (e != Z_OK) {
if (zshPtr->interp) {
- ConvertError(zshPtr->interp, e);
+ ConvertError(zshPtr->interp, e, zshPtr->stream.adler);
}
return TCL_ERROR;
}
@@ -1093,7 +1099,7 @@ Tcl_ZlibStreamPut(
}
if (e != Z_OK && !(flush==Z_FINISH && e==Z_STREAM_END)) {
if (zshPtr->interp) {
- ConvertError(zshPtr->interp, e);
+ ConvertError(zshPtr->interp, e, zshPtr->stream.adler);
}
return TCL_ERROR;
}
@@ -1296,7 +1302,7 @@ Tcl_ZlibStreamGet(
}
if (!(e==Z_OK || e==Z_STREAM_END || e==Z_BUF_ERROR)) {
Tcl_SetByteArrayLength(data, existing);
- ConvertError(zshPtr->interp, e);
+ ConvertError(zshPtr->interp, e, zshPtr->stream.adler);
return TCL_ERROR;
}
if (e == Z_STREAM_END) {
@@ -1512,7 +1518,7 @@ Tcl_ZlibDeflate(
return TCL_OK;
error:
- ConvertError(interp, e);
+ ConvertError(interp, e, stream.adler);
TclDecrRefCount(obj);
return TCL_ERROR;
}
@@ -1691,7 +1697,7 @@ Tcl_ZlibInflate(
error:
TclDecrRefCount(obj);
- ConvertError(interp, e);
+ ConvertError(interp, e, stream.adler);
if (nameBuf) {
ckfree(nameBuf);
}
@@ -2629,7 +2635,7 @@ ZlibTransformClose(
if (e != Z_OK && e != Z_STREAM_END) {
/* TODO: is this the right way to do errors on close? */
if (!TclInThreadExit()) {
- ConvertError(interp, e);
+ ConvertError(interp, e, cd->outStream.adler);
}
result = TCL_ERROR;
break;
@@ -2915,7 +2921,7 @@ ZlibTransformSetOption( /* not used */
if (cd->mode == TCL_ZLIB_STREAM_DEFLATE) {
code = SetDeflateDictionary(&cd->outStream, compDictObj);
if (code != Z_OK) {
- ConvertError(interp, code);
+ ConvertError(interp, code, cd->outStream.adler);
return TCL_ERROR;
}
}
@@ -2951,7 +2957,7 @@ ZlibTransformSetOption( /* not used */
if (e == Z_BUF_ERROR) {
break;
} else if (e != Z_OK) {
- ConvertError(interp, e);
+ ConvertError(interp, e, cd->outStream.adler);
return TCL_ERROR;
} else if (cd->outStream.avail_out == 0) {
break;
diff --git a/tests/zlib.test b/tests/zlib.test
index cc3900d..ba21cd1 100644
--- a/tests/zlib.test
+++ b/tests/zlib.test
@@ -230,16 +230,19 @@ test zlib-8.8 {transformtion and fconfigure} -setup {
set msg "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n"
set dict "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchif-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser-agent100101200201202203204205206300301302303304305306307400401402403404405406407408409410411412413414415416417500501502503504505accept-rangesageetaglocationproxy-authenticatepublicretry-afterservervarywarningwww-authenticateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertransfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locationcontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMondayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSepOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplication/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1.1statusversionurl"
} -constraints zlib -body {
- zlib push deflate $outSide -dictionary $dict
+ zlib push compress $outSide -dictionary $dict
fconfigure $outSide -blocking 0 -translation binary -buffering none
fconfigure $inSide -blocking 0 -translation binary
puts -nonewline $outSide $msg
chan pop $outSide
- list [string length [zlib deflate $msg]] [string length [read $inSide]]
+ set compressed [read $inSide]
+ catch {zlib decompress $compressed} err opt
+ list [string length [zlib deflate $msg]] [string length $compressed] \
+ $err [dict get $opt -errorcode] [zlib adler32 $dict]
} -cleanup {
catch {close $outSide}
catch {close $inSide}
-} -result {254 212}
+} -result {254 222 {need dictionary} {TCL ZLIB NEED_DICT 2381337010} 2381337010}
test zlib-9.1 "check fcopy with push" -constraints zlib -setup {
set sfile [makeFile {} testsrc.gz]