forked from Haivision/srt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Unit tests, including test from issue Haivision#468
- Loading branch information
1 parent
a9de399
commit ff9e916
Showing
9 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# code copied from https://crascit.com/2015/07/25/cmake-gtest/ | ||
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) | ||
|
||
project(googletest-download NONE) | ||
|
||
include(ExternalProject) | ||
|
||
ExternalProject_Add( | ||
googletest | ||
SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src" | ||
BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build" | ||
GIT_REPOSITORY | ||
https://github.com/google/googletest.git | ||
GIT_TAG release-1.8.1 | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND "" | ||
TEST_COMMAND "" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# the following code to fetch googletest | ||
# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/ | ||
# download and unpack googletest at configure time | ||
|
||
macro(fetch_googletest _download_module_path _download_root) | ||
set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root}) | ||
configure_file( | ||
${_download_module_path}/googletest-download.cmake | ||
${_download_root}/CMakeLists.txt | ||
@ONLY | ||
) | ||
unset(GOOGLETEST_DOWNLOAD_ROOT) | ||
|
||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
execute_process( | ||
COMMAND | ||
"${CMAKE_COMMAND}" --build . | ||
WORKING_DIRECTORY | ||
${_download_root} | ||
) | ||
|
||
# adds the targers: gtest, gtest_main, gmock, gmock_main | ||
add_subdirectory( | ||
${_download_root}/googletest-src | ||
${_download_root}/googletest-build | ||
) | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "gtest/gtest.h" | ||
#include "buffer.h" | ||
|
||
TEST(CRcvBuffer, Create) | ||
{ | ||
const int buffer_size = 65536; | ||
CUnitQueue unit_queue; | ||
CRcvBuffer rcv_buffer(&unit_queue, buffer_size); | ||
|
||
EXPECT_EQ(rcv_buffer.getAvailBufSize(), buffer_size - 1); // logic | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#ifdef _WIN32 | ||
#define _WINSOCKAPI_ // to include Winsock2.h instead of Winsock.h from windows.h | ||
#include <winsock2.h> | ||
|
||
#if defined(__GNUC__) || defined(__MINGW32__) | ||
extern "C" { | ||
WINSOCK_API_LINKAGE INT WSAAPI inet_pton( INT Family, PCSTR pszAddrString, PVOID pAddrBuf); | ||
WINSOCK_API_LINKAGE PCSTR WSAAPI inet_ntop(INT Family, PVOID pAddr, PSTR pStringBuf, size_t StringBufSize); | ||
} | ||
#endif | ||
|
||
#define INC__WIN_WINTIME // exclude gettimeofday from srt headers | ||
#endif | ||
|
||
#include "srt.h" | ||
|
||
|
||
TEST(SRT, ConnectionTimeoutTest) { | ||
ASSERT_EQ(srt_startup(), 0); | ||
|
||
const int yes = 1; | ||
const int no = 0; | ||
|
||
SRTSOCKET m_client_sock = srt_socket(AF_INET, SOCK_DGRAM, 0); | ||
ASSERT_NE(m_client_sock, SRT_ERROR); | ||
|
||
ASSERT_NE(srt_setsockopt(m_client_sock, 0, SRTO_RCVSYN, &no, sizeof no), SRT_ERROR); // for async connect | ||
ASSERT_NE(srt_setsockopt(m_client_sock, 0, SRTO_SNDSYN, &no, sizeof no), SRT_ERROR); // for async connect | ||
ASSERT_NE(srt_setsockflag(m_client_sock, SRTO_SENDER, &yes, sizeof yes), SRT_ERROR); | ||
ASSERT_NE(srt_setsockopt(m_client_sock, 0, SRTO_TSBPDMODE, &yes, sizeof yes), SRT_ERROR); | ||
|
||
const int pollid = srt_epoll_create(); | ||
ASSERT_GE(pollid, 0); | ||
const int epoll_out = SRT_EPOLL_OUT | SRT_EPOLL_ERR; | ||
ASSERT_NE(srt_epoll_add_usock(pollid, m_client_sock, &epoll_out), SRT_ERROR); | ||
|
||
sockaddr_in sa; | ||
memset(&sa, 0, sizeof sa); | ||
sa.sin_family = AF_INET; | ||
sa.sin_port = htons(5555); | ||
|
||
ASSERT_EQ(inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr), 1); | ||
|
||
sockaddr* psa = (sockaddr*)&sa; | ||
|
||
ASSERT_NE(srt_connect(m_client_sock, psa, sizeof sa), SRT_ERROR); | ||
|
||
|
||
// Socket readiness for connection is checked by polling on WRITE allowed sockets. | ||
|
||
{ | ||
int rlen = 2; | ||
SRTSOCKET read[2]; | ||
|
||
int wlen = 2; | ||
SRTSOCKET write[2]; | ||
|
||
ASSERT_NE(srt_epoll_wait(pollid, read, &rlen, | ||
write, &wlen, | ||
-1, | ||
0, 0, 0, 0), SRT_ERROR); | ||
|
||
ASSERT_EQ(rlen, 1); | ||
ASSERT_EQ(read[0], m_client_sock); | ||
|
||
} | ||
|
||
ASSERT_NE(srt_epoll_remove_usock(pollid, m_client_sock), SRT_ERROR); | ||
ASSERT_NE(srt_close(m_client_sock), SRT_ERROR); | ||
(void)srt_epoll_release(pollid); | ||
(void)srt_cleanup(); | ||
} |