Skip to content

Add test for native addon making use of zlib #7535

Closed
@ghost

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    addonsIssues and PRs related to native addons.testIssues and PRs related to the tests.zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions