File: test-mongocrypt-dll.c

package info (click to toggle)
libmongocrypt 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,572 kB
  • sloc: ansic: 70,067; python: 4,547; cpp: 615; sh: 460; makefile: 44; awk: 8
file content (44 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "mongocrypt.h"

#include "mongocrypt-dll-private.h"

#include <mc-mlib/path.h>

#include "test-mongocrypt.h"

static void _test_load_simple_library(_mongocrypt_tester_t *t) {
    (void)t;
    mstr self_path = mstr_copy_cstr(TEST_MONGOCRYPT_OUTPUT_PATH);

    mstr dll_path =
        mpath_join(mpath_parent(self_path.view, MPATH_NATIVE), mstrv_view_cstr("test-dll.dll"), MPATH_NATIVE);

    mcr_dll lib = mcr_dll_open(dll_path.raw.data);
    BSON_ASSERT(lib.error_string.raw.len == 0);

    MC_BEGIN_CAST_FUNCTION_TYPE_STRICT_IGNORE
    int (*say_hello)(void) = (int (*)(void))mcr_dll_sym(lib, "say_hello");
    MC_END_CAST_FUNCTION_TYPE_STRICT_IGNORE

    BSON_ASSERT(say_hello != NULL);

    int rval = say_hello();
    ASSERT_CMPINT(rval, ==, 42);

    mcr_dll_close(lib);
    mstr_free(dll_path);
    mstr_free(self_path);
}

static void _test_load_nonesuch(_mongocrypt_tester_t *t) {
    (void)t;
    mcr_dll lib = mcr_dll_open("no-such-directory/no-such-lib.dll");
    BSON_ASSERT(lib._native_handle == NULL);
    BSON_ASSERT(lib.error_string.raw.len > 0);
    mcr_dll_close(lib);
}

void _mongocrypt_tester_install_dll(_mongocrypt_tester_t *tester) {
    INSTALL_TEST(_test_load_simple_library);
    INSTALL_TEST(_test_load_nonesuch);
}