File: shared_library_test.c

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (83 lines) | stat: -rw-r--r-- 2,530 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/io/shared_library.h>

#include <aws/testing/aws_test_harness.h>

#ifdef _WIN32
/*
 * We may need to monkey with paths (or copy .dlls) a bit when we create shared library builds
 */
static const char *s_self_path = ".\\aws-c-io.dll";
#else
static const char *s_self_path = "../libaws-c-io.so";
#endif

static int s_shared_library_open_failure(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    (void)allocator;

    struct aws_shared_library library;
    ASSERT_FAILS(aws_shared_library_init(&library, "not-a-real-library.blah"));

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(shared_library_open_failure, s_shared_library_open_failure);

static int s_shared_library_open_success(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    (void)allocator;

    struct aws_shared_library library;
    ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path));

    aws_shared_library_clean_up(&library);

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(shared_library_open_success, s_shared_library_open_success);

typedef int (*find_symbol_function)(struct aws_shared_library *, const char *, aws_generic_function *);

static int s_shared_library_find_function_success(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    (void)allocator;

    struct aws_shared_library library;
    ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path));

    aws_generic_function find_symbol = NULL;
    ASSERT_SUCCESS(aws_shared_library_find_function(&library, "aws_shared_library_find_function", &find_symbol));

    find_symbol_function find = (find_symbol_function)find_symbol;
    ASSERT_TRUE(find != NULL);

    aws_shared_library_clean_up(&library);

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(shared_library_find_function_success, s_shared_library_find_function_success);

static int s_shared_library_find_function_failure(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    (void)allocator;

    struct aws_shared_library library;
    ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path));

    aws_generic_function find_symbol = NULL;
    ASSERT_FAILS(aws_shared_library_find_function(&library, "not_a_real_function", &find_symbol));
    ASSERT_TRUE(find_symbol == NULL);

    aws_shared_library_clean_up(&library);

    return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(shared_library_find_function_failure, s_shared_library_find_function_failure);