| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/io/shared_library.h> |
| 7 |
|
| 8 |
#include <aws/testing/aws_test_harness.h> |
| 9 |
|
| 10 |
#ifdef _WIN32 |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
static const char *s_self_path = ".\\aws-c-io.dll"; |
| 15 |
#else |
| 16 |
static const char *s_self_path = "../libaws-c-io.so"; |
| 17 |
#endif |
| 18 |
|
| 19 |
static int s_shared_library_open_failure(struct aws_allocator *allocator, void *ctx) { |
| 20 |
(void)ctx; |
| 21 |
(void)allocator; |
| 22 |
|
| 23 |
struct aws_shared_library library; |
| 24 |
ASSERT_FAILS(aws_shared_library_init(&library, "not-a-real-library.blah")); |
| 25 |
|
| 26 |
return AWS_OP_SUCCESS; |
| 27 |
} |
| 28 |
|
| 29 |
AWS_TEST_CASE(shared_library_open_failure, s_shared_library_open_failure); |
| 30 |
|
| 31 |
static int s_shared_library_open_success(struct aws_allocator *allocator, void *ctx) { |
| 32 |
(void)ctx; |
| 33 |
(void)allocator; |
| 34 |
|
| 35 |
struct aws_shared_library library; |
| 36 |
ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path)); |
| 37 |
|
| 38 |
aws_shared_library_clean_up(&library); |
| 39 |
|
| 40 |
return AWS_OP_SUCCESS; |
| 41 |
} |
| 42 |
|
| 43 |
AWS_TEST_CASE(shared_library_open_success, s_shared_library_open_success); |
| 44 |
|
| 45 |
typedef int (*find_symbol_function)(struct aws_shared_library *, const char *, aws_generic_function *); |
| 46 |
|
| 47 |
static int s_shared_library_find_function_success(struct aws_allocator *allocator, void *ctx) { |
| 48 |
(void)ctx; |
| 49 |
(void)allocator; |
| 50 |
|
| 51 |
struct aws_shared_library library; |
| 52 |
ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path)); |
| 53 |
|
| 54 |
aws_generic_function find_symbol = NULL; |
| 55 |
ASSERT_SUCCESS(aws_shared_library_find_function(&library, "aws_shared_library_find_function", &find_symbol)); |
| 56 |
|
| 57 |
find_symbol_function find = (find_symbol_function)find_symbol; |
| 58 |
ASSERT_TRUE(find != NULL); |
| 59 |
|
| 60 |
aws_shared_library_clean_up(&library); |
| 61 |
|
| 62 |
return AWS_OP_SUCCESS; |
| 63 |
} |
| 64 |
|
| 65 |
AWS_TEST_CASE(shared_library_find_function_success, s_shared_library_find_function_success); |
| 66 |
|
| 67 |
static int s_shared_library_find_function_failure(struct aws_allocator *allocator, void *ctx) { |
| 68 |
(void)ctx; |
| 69 |
(void)allocator; |
| 70 |
|
| 71 |
struct aws_shared_library library; |
| 72 |
ASSERT_SUCCESS(aws_shared_library_init(&library, s_self_path)); |
| 73 |
|
| 74 |
aws_generic_function find_symbol = NULL; |
| 75 |
ASSERT_FAILS(aws_shared_library_find_function(&library, "not_a_real_function", &find_symbol)); |
| 76 |
ASSERT_TRUE(find_symbol == NULL); |
| 77 |
|
| 78 |
aws_shared_library_clean_up(&library); |
| 79 |
|
| 80 |
return AWS_OP_SUCCESS; |
| 81 |
} |
| 82 |
|
| 83 |
AWS_TEST_CASE(shared_library_find_function_failure, s_shared_library_find_function_failure); |