Blame tests/core/stream.c
|
Packit Service |
20376f |
#include "clar_libgit2.h"
|
|
Packit Service |
20376f |
#include "git2/sys/stream.h"
|
|
Packit Service |
20376f |
#include "tls_stream.h"
|
|
Packit Service |
20376f |
#include "stream.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
static git_stream test_stream;
|
|
Packit Service |
20376f |
static int ctor_called;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
static int test_ctor(git_stream **out, const char *host, const char *port)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
GIT_UNUSED(host);
|
|
Packit Service |
20376f |
GIT_UNUSED(port);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
ctor_called = 1;
|
|
Packit Service |
20376f |
*out = &test_stream;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
return 0;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void test_core_stream__register_tls(void)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
git_stream *stream;
|
|
Packit Service |
20376f |
int error;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
ctor_called = 0;
|
|
Packit Service |
20376f |
cl_git_pass(git_stream_register_tls(test_ctor));
|
|
Packit Service |
20376f |
cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
|
|
Packit Service |
20376f |
cl_assert_equal_i(1, ctor_called);
|
|
Packit Service |
20376f |
cl_assert_equal_p(&test_stream, stream);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
ctor_called = 0;
|
|
Packit Service |
20376f |
stream = NULL;
|
|
Packit Service |
20376f |
cl_git_pass(git_stream_register_tls(NULL));
|
|
Packit Service |
20376f |
error = git_tls_stream_new(&stream, "localhost", "443");
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
/* We don't have arbitrary TLS stream support on Windows
|
|
Packit Service |
20376f |
* or when openssl support is disabled (except on OSX
|
|
Packit Service |
20376f |
* with Security framework).
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
#if defined(GIT_WIN32) || \
|
|
Packit Service |
20376f |
(!defined(GIT_SECURE_TRANSPORT) && !defined(GIT_OPENSSL))
|
|
Packit Service |
20376f |
cl_git_fail_with(-1, error);
|
|
Packit Service |
20376f |
#else
|
|
Packit Service |
20376f |
cl_git_pass(error);
|
|
Packit Service |
20376f |
#endif
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
cl_assert_equal_i(0, ctor_called);
|
|
Packit Service |
20376f |
cl_assert(&test_stream != stream);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_stream_free(stream);
|
|
Packit Service |
20376f |
}
|