Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for native addon making use of zlib #7535

Closed
ghost opened this issue Jul 4, 2016 · 2 comments
Closed

Add test for native addon making use of zlib #7535

ghost opened this issue Jul 4, 2016 · 2 comments
Labels
addons Issues and PRs related to native addons. test Issues and PRs related to the tests. zlib Issues and PRs related to the zlib subsystem.

Comments

@ghost
Copy link

ghost commented Jul 4, 2016

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);
}
@mscdex mscdex added addons Issues and PRs related to native addons. test Issues and PRs related to the tests. zlib Issues and PRs related to the zlib subsystem. labels Jul 4, 2016
@jasnell
Copy link
Member

jasnell commented Aug 9, 2016

/cc @addaleax :-)

@addaleax
Copy link
Member

addaleax commented 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.

addaleax added a commit to addaleax/node that referenced this issue Aug 9, 2016
Add a test addon that makes use of the zlib implementation bundled
with node, checking that a compression/decompression round-trip works.

This is largely based on the already-existing OpenSSL addon.

Fixes: nodejs#7535
evanlucas pushed a commit that referenced this issue Aug 20, 2016
Add a test addon that makes use of the zlib implementation bundled
with node, checking that a compression/decompression round-trip works.

This is largely based on the already-existing OpenSSL addon.

Fixes: #7535
PR-URL: #8039
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins pushed a commit that referenced this issue Sep 30, 2016
Add a test addon that makes use of the zlib implementation bundled
with node, checking that a compression/decompression round-trip works.

This is largely based on the already-existing OpenSSL addon.

Fixes: #7535
PR-URL: #8039
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. test Issues and PRs related to the tests. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants