1 #include "clar_libgit2.h"
2 #include "git2/sys/stream.h"
3 #include "streams/tls.h"
4 #include "streams/socket.h"
7 static git_stream test_stream
;
8 static int ctor_called
;
10 void test_stream_registration__cleanup(void)
12 cl_git_pass(git_stream_register(GIT_STREAM_TLS
| GIT_STREAM_STANDARD
, NULL
));
15 static int test_stream_init(git_stream
**out
, const char *host
, const char *port
)
26 static int test_stream_wrap(git_stream
**out
, git_stream
*in
, const char *host
)
37 void test_stream_registration__insecure(void)
40 git_stream_registration registration
= {0};
42 registration
.version
= 1;
43 registration
.init
= test_stream_init
;
44 registration
.wrap
= test_stream_wrap
;
47 cl_git_pass(git_stream_register(GIT_STREAM_STANDARD
, ®istration
));
48 cl_git_pass(git_socket_stream_new(&stream
, "localhost", "80"));
49 cl_assert_equal_i(1, ctor_called
);
50 cl_assert_equal_p(&test_stream
, stream
);
54 cl_git_pass(git_stream_register(GIT_STREAM_STANDARD
, NULL
));
55 cl_git_pass(git_socket_stream_new(&stream
, "localhost", "80"));
57 cl_assert_equal_i(0, ctor_called
);
58 cl_assert(&test_stream
!= stream
);
60 git_stream_free(stream
);
63 void test_stream_registration__tls(void)
66 git_stream_registration registration
= {0};
69 registration
.version
= 1;
70 registration
.init
= test_stream_init
;
71 registration
.wrap
= test_stream_wrap
;
74 cl_git_pass(git_stream_register(GIT_STREAM_TLS
, ®istration
));
75 cl_git_pass(git_tls_stream_new(&stream
, "localhost", "443"));
76 cl_assert_equal_i(1, ctor_called
);
77 cl_assert_equal_p(&test_stream
, stream
);
81 cl_git_pass(git_stream_register(GIT_STREAM_TLS
, NULL
));
82 error
= git_tls_stream_new(&stream
, "localhost", "443");
84 /* We don't have TLS support enabled, or we're on Windows,
85 * which has no arbitrary TLS stream support.
87 #if defined(GIT_WIN32) || !defined(GIT_HTTPS)
88 cl_git_fail_with(-1, error
);
93 cl_assert_equal_i(0, ctor_called
);
94 cl_assert(&test_stream
!= stream
);
96 git_stream_free(stream
);
99 void test_stream_registration__both(void)
102 git_stream_registration registration
= {0};
104 registration
.version
= 1;
105 registration
.init
= test_stream_init
;
106 registration
.wrap
= test_stream_wrap
;
108 cl_git_pass(git_stream_register(GIT_STREAM_STANDARD
| GIT_STREAM_TLS
, ®istration
));
111 cl_git_pass(git_tls_stream_new(&stream
, "localhost", "443"));
112 cl_assert_equal_i(1, ctor_called
);
113 cl_assert_equal_p(&test_stream
, stream
);
116 cl_git_pass(git_socket_stream_new(&stream
, "localhost", "80"));
117 cl_assert_equal_i(1, ctor_called
);
118 cl_assert_equal_p(&test_stream
, stream
);