]> git.proxmox.com Git - libgit2.git/blob - tests/stream/deprecated.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / stream / deprecated.c
1 #include "clar_libgit2.h"
2 #include "git2/sys/stream.h"
3 #include "streams/tls.h"
4 #include "streams/socket.h"
5 #include "stream.h"
6
7 void test_stream_deprecated__cleanup(void)
8 {
9 cl_git_pass(git_stream_register(GIT_STREAM_TLS | GIT_STREAM_STANDARD, NULL));
10 }
11
12 #ifndef GIT_DEPRECATE_HARD
13 static git_stream test_stream;
14 static int ctor_called;
15
16 static int test_stream_init(git_stream **out, const char *host, const char *port)
17 {
18 GIT_UNUSED(host);
19 GIT_UNUSED(port);
20
21 ctor_called = 1;
22 *out = &test_stream;
23
24 return 0;
25 }
26 #endif
27
28 void test_stream_deprecated__register_tls(void)
29 {
30 #ifndef GIT_DEPRECATE_HARD
31 git_stream *stream;
32 int error;
33
34 ctor_called = 0;
35 cl_git_pass(git_stream_register_tls(test_stream_init));
36 cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
37 cl_assert_equal_i(1, ctor_called);
38 cl_assert_equal_p(&test_stream, stream);
39
40 ctor_called = 0;
41 stream = NULL;
42 cl_git_pass(git_stream_register_tls(NULL));
43 error = git_tls_stream_new(&stream, "localhost", "443");
44
45 /*
46 * We don't have TLS support enabled, or we're on Windows,
47 * which has no arbitrary TLS stream support.
48 */
49 #if defined(GIT_WIN32) || !defined(GIT_HTTPS)
50 cl_git_fail_with(-1, error);
51 #else
52 cl_git_pass(error);
53 #endif
54
55 cl_assert_equal_i(0, ctor_called);
56 cl_assert(&test_stream != stream);
57
58 git_stream_free(stream);
59 #endif
60 }