Add test for native addon making use of zlib #7535
Copy link
Copy link
Closed
Labels
addonsIssues and PRs related to native addons.Issues and PRs related to native addons.testIssues and PRs related to Node.js core tests and test infrastructure.Issues and PRs related to Node.js core tests and test infrastructure.zlibIssues and PRs related to the zlib module and its compression dependencies.Issues and PRs related to the zlib module and its compression dependencies.
Description
Just like #6274 we need a test for zlib usage. The node.exe binary on Windows does not export zlib symbols and this can be fixed by linking against a .def file with these symbols added.
A basic test could be something like this:
#include <zlib.h>
#include <cassert>
int main() {
z_stream zStream = {};
int err = deflateInit2(&zStream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
assert(Z_OK == err);
unsigned char helloString[] = "hello";
unsigned char expectedDeflation[] = {0xca, 0x48, 0xcd, 0xc9, 0xc9, 0x7, 0x0, 0x0, 0x0, 0xff, 0xff};
unsigned char outputString[512];
zStream.avail_in = sizeof(helloString) - 1;
zStream.next_in = (unsigned char *) helloString;
zStream.avail_out = sizeof(outputString);
zStream.next_out = outputString;
err = deflate(&zStream, Z_SYNC_FLUSH);
assert(err == Z_OK || err == Z_STREAM_END);
int deflatedLength = sizeof(outputString) - zStream.avail_out;
for (int i = 0; i < deflatedLength; i++) {
assert(outputString[i] == expectedDeflation[i]);
}
deflateEnd(&zStream);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
addonsIssues and PRs related to native addons.Issues and PRs related to native addons.testIssues and PRs related to Node.js core tests and test infrastructure.Issues and PRs related to Node.js core tests and test infrastructure.zlibIssues and PRs related to the zlib module and its compression dependencies.Issues and PRs related to the zlib module and its compression dependencies.
Activity
jasnell commentedon Aug 9, 2016
/cc @addaleax :-)
addaleax commentedon Aug 9, 2016
Yeah, this should be possible since 359352c. I’ll try and see if I can get something together based on what @bnoordhuis already did in #6274.
test: add an zlib binding addon test
test: add an zlib binding addon test
test: add an zlib binding addon test
test: add an zlib binding addon test