Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

zlib: Fix test so that it's not trivially passing, then pass it.

Regression from the refactor to move more things into JS.
  • Loading branch information...
isaacs committed Sep 18, 2011
1 parent 5b8e1da commit d104bfd5a6d825c58a09e325b7475183d2738849
Showing with 19 additions and 13 deletions.
  1. +8 −10 lib/zlib.js
  2. +2 −2 src/node_zlib.cc
  3. +9 −1 test/simple/test-zlib.js
@@ -22,6 +22,7 @@
var binding = process.binding('zlib');
var util = require('util');
var stream = require('stream');
var assert = require('assert').ok;

// zlib doesn't provide these, so kludge them in following the same
// const naming scheme zlib uses.
@@ -176,14 +177,6 @@ function Zlib(opts, Binding) {
this._buffer = new Buffer(this._chunkSize);
this._offset = 0;
var self = this;

this._binding.onData = function(c) {
self.emit('data', c);
};

this._binding.onEnd = function() {
self.emit('end');
};
}

util.inherits(Zlib, stream.Stream);
@@ -269,16 +262,21 @@ Zlib.prototype._process = function() {
req.callback = callback;
this._processing = req;

function callback(availInAfter, availOutAfter) {
var have = self.chunkSize - availOutAfter;
function callback(availInAfter, availOutAfter, buffer) {
var have = availOutBefore - availOutAfter;

assert(have >= 0, 'have should not go down');

if (have > 0) {
var out = self._buffer.slice(self._offset, self._offset + have);
self._offset += have;
self.emit('data', out);
}

// XXX Maybe have a 'min buffer' size so we don't dip into the
// thread pool with only 1 byte available or something?
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
availOutBefore = self._chunkSize;
self._offset = 0;
self._buffer = new Buffer(self._chunkSize);
}
@@ -39,7 +39,6 @@ using namespace v8;
// write() returns one of these, and then calls the cb() when it's done.
typedef ReqWrap<uv_work_t> WorkReqWrap;

static Persistent<String> ondata_sym;
static Persistent<String> callback_sym;

enum node_zlib_mode {
@@ -78,6 +77,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
// write(flush, in, in_off, in_len, out, out_off, out_len)
static Handle<Value>
Write(const Arguments& args) {
HandleScope scope;
assert(args.Length() == 7);

ZCtx<mode> *ctx = ObjectWrap::Unwrap< ZCtx<mode> >(args.This());
@@ -177,6 +177,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
// v8 land!
static void
After(uv_work_t* work_req) {
HandleScope scope;
WorkReqWrap *req_wrap = reinterpret_cast<WorkReqWrap *>(work_req->data);
ZCtx<mode> *ctx = (ZCtx<mode> *)req_wrap->data_;
Local<Integer> avail_out = Integer::New(ctx->strm_.avail_out);
@@ -322,7 +323,6 @@ void InitZlib(Handle<Object> target) {
NODE_ZLIB_CLASS(GUNZIP, "Gunzip")
NODE_ZLIB_CLASS(UNZIP, "Unzip")

ondata_sym = NODE_PSYMBOL("onData");
callback_sym = NODE_PSYMBOL("callback");

NODE_DEFINE_CONSTANT(target, Z_NO_FLUSH);
@@ -59,6 +59,12 @@ if (!process.env.PUMMEL) {
var fs = require('fs');

var testFiles = [ 'person.jpg', 'elipses.txt', 'empty.txt' ];

if (process.env.FAST) {
zlibPairs = [ [zlib.Gzip, zlib.Unzip] ];
var testFiles = [ 'person.jpg' ];
}

var tests = {}
testFiles.forEach(function(file) {
tests[file] = fs.readFileSync(path.resolve(common.fixturesDir, file));
@@ -81,6 +87,7 @@ util.inherits(BufferStream, stream.Stream);
BufferStream.prototype.write = function(c) {
this.chunks.push(c);
this.length += c.length;
return true;
};

BufferStream.prototype.end = function(c) {
@@ -94,6 +101,7 @@ BufferStream.prototype.end = function(c) {
});
this.emit('data', buf);
this.emit('end');
return true;
};


@@ -184,7 +192,7 @@ Object.keys(tests).forEach(function(file) {
Def.name + ' -> ' + Inf.name;
var ok = true;
var testNum = ++done;
for (var i = 0; i < c.length; i++) {
for (var i = 0; i < Math.max(c.length, test.length); i++) {
if (c[i] !== test[i]) {
ok = false;
failures ++;

0 comments on commit d104bfd

Please sign in to comment.
You can’t perform that action at this time.