]>
Commit | Line | Data |
---|---|---|
7fafde63 CMN |
1 | #include "clar_libgit2.h" |
2 | #include "git2/sys/stream.h" | |
3 | #include "tls_stream.h" | |
4 | #include "stream.h" | |
5 | ||
6 | static git_stream test_stream; | |
7 | static int ctor_called; | |
8 | ||
9 | static int test_ctor(git_stream **out, const char *host, const char *port) | |
10 | { | |
11 | GIT_UNUSED(host); | |
12 | GIT_UNUSED(port); | |
13 | ||
14 | ctor_called = 1; | |
15 | *out = &test_stream; | |
16 | ||
17 | return 0; | |
18 | } | |
19 | ||
20 | void test_core_stream__register_tls(void) | |
21 | { | |
22 | git_stream *stream; | |
23 | int error; | |
24 | ||
25 | ctor_called = 0; | |
26 | cl_git_pass(git_stream_register_tls(test_ctor)); | |
27 | cl_git_pass(git_tls_stream_new(&stream, "localhost", "443")); | |
28 | cl_assert_equal_i(1, ctor_called); | |
29 | cl_assert_equal_p(&test_stream, stream); | |
30 | ||
31 | ctor_called = 0; | |
32 | stream = NULL; | |
33 | cl_git_pass(git_stream_register_tls(NULL)); | |
34 | error = git_tls_stream_new(&stream, "localhost", "443"); | |
35 | ||
36 | /* We don't have arbitrary TLS stream support on Windows */ | |
37 | #if GIT_WIN32 | |
38 | cl_git_fail_with(-1, error); | |
39 | #else | |
40 | cl_git_pass(error); | |
41 | #endif | |
42 | ||
43 | cl_assert_equal_i(0, ctor_called); | |
44 | cl_assert(&test_stream != stream); | |
45 | ||
46 | git_stream_free(stream); | |
47 | } |