1 | import dl |
2 | |
3 | fn test_dl() { |
4 | $if linux { |
5 | run_test_invalid_lib_linux() |
6 | return |
7 | } |
8 | $if windows { |
9 | run_test_invalid_lib_windows() |
10 | run_test_valid_lib_windows() |
11 | run_test_invalid_sym_windows() |
12 | run_test_valid_sym_windows() |
13 | return |
14 | } $else { |
15 | eprint('currently not implemented on this platform') |
16 | } |
17 | } |
18 | |
19 | fn run_test_invalid_lib_linux() { |
20 | // ensure a not-existing dl won't be loaded |
21 | h := dl.open('not-existing-dynamic-link-library', dl.rtld_now) |
22 | assert h == 0 |
23 | } |
24 | |
25 | fn run_test_invalid_lib_windows() { |
26 | // ensure a not-existing dl won't be loaded |
27 | h := dl.open('not-existing-dynamic-link-library', dl.rtld_now) |
28 | assert h == 0 |
29 | } |
30 | |
31 | fn run_test_valid_lib_windows() { |
32 | h := dl.open('shell32', dl.rtld_now) |
33 | assert h != 0 |
34 | } |
35 | |
36 | fn run_test_invalid_sym_windows() { |
37 | h := dl.open('shell32', dl.rtld_now) |
38 | proc := dl.sym(h, 'CommandLineToArgvW2') |
39 | assert proc == 0 |
40 | } |
41 | |
42 | fn run_test_valid_sym_windows() { |
43 | h := dl.open('shell32', dl.rtld_now) |
44 | proc := dl.sym(h, 'CommandLineToArgvW') |
45 | assert proc != 0 |
46 | } |