diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-10-13 12:25:41 +0300 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-11-03 19:10:29 +0300 |
commit | 7fafde632580f75ff3647ddf9e1e92ee388f317e (patch) | |
tree | d5ca0c2de9d73d24313366d89110c2d7c0b17a7a /tests/core | |
parent | d39f643a0a09336ad77f04b7037cbc1c486bdd50 (diff) |
stream: allow registering a user-provided TLS constructor
This allows the application to use their own TLS stream, regardless of
the capabilities of libgit2 itself.
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/stream.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/core/stream.c b/tests/core/stream.c new file mode 100644 index 000000000..ace6a05da --- /dev/null +++ b/tests/core/stream.c @@ -0,0 +1,47 @@ +#include "clar_libgit2.h" +#include "git2/sys/stream.h" +#include "tls_stream.h" +#include "stream.h" + +static git_stream test_stream; +static int ctor_called; + +static int test_ctor(git_stream **out, const char *host, const char *port) +{ + GIT_UNUSED(host); + GIT_UNUSED(port); + + ctor_called = 1; + *out = &test_stream; + + return 0; +} + +void test_core_stream__register_tls(void) +{ + git_stream *stream; + int error; + + ctor_called = 0; + cl_git_pass(git_stream_register_tls(test_ctor)); + cl_git_pass(git_tls_stream_new(&stream, "localhost", "443")); + cl_assert_equal_i(1, ctor_called); + cl_assert_equal_p(&test_stream, stream); + + ctor_called = 0; + stream = NULL; + cl_git_pass(git_stream_register_tls(NULL)); + error = git_tls_stream_new(&stream, "localhost", "443"); + + /* We don't have arbitrary TLS stream support on Windows */ +#if GIT_WIN32 + cl_git_fail_with(-1, error); +#else + cl_git_pass(error); +#endif + + cl_assert_equal_i(0, ctor_called); + cl_assert(&test_stream != stream); + + git_stream_free(stream); +} |