From 6796d0b59231874271e7627f4453d6bff91c4936 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 23 Dec 2019 14:01:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0c=20api=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=8C=83=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/CMakeLists.txt | 2 ++ api/source/common.cpp | 2 +- api/tests/CMakeLists.txt | 25 +++++++++++++++++++++++++ api/tests/server.cpp | 21 +++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 api/tests/CMakeLists.txt create mode 100644 api/tests/server.cpp diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt index 03901c12..3cea8196 100644 --- a/api/CMakeLists.txt +++ b/api/CMakeLists.txt @@ -7,5 +7,7 @@ if(WIN32) endif() target_link_libraries(api ${LINK_LIB_LIST}) +add_subdirectory(tests) + diff --git a/api/source/common.cpp b/api/source/common.cpp index ef89390d..6dfc99fb 100755 --- a/api/source/common.cpp +++ b/api/source/common.cpp @@ -47,7 +47,7 @@ static TcpServer::Ptr http_server[2]; #include "Rtp/UdpRecver.h" #include "Rtp/RtpSession.h" static std::shared_ptr udpRtpServer; -static TcpServer::Ptr tcpRtpServer(new TcpServer()); +static TcpServer::Ptr tcpRtpServer; #endif //////////////////////////environment init/////////////////////////// diff --git a/api/tests/CMakeLists.txt b/api/tests/CMakeLists.txt new file mode 100644 index 00000000..02c6cdd6 --- /dev/null +++ b/api/tests/CMakeLists.txt @@ -0,0 +1,25 @@ +aux_source_directory(. TEST_SRC_LIST) +foreach(TEST_SRC ${TEST_SRC_LIST}) + STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC}) + message(STATUS "add c api tester:${TEST_EXE_NAME}") + set(exe_name api_tester_${TEST_EXE_NAME}) + add_executable(${exe_name} ${TEST_SRC}) + + if(WIN32) + set_target_properties(${exe_name} PROPERTIES COMPILE_FLAGS ${VS_FALGS} ) + endif(WIN32) + + target_link_libraries(${exe_name} api) +endforeach() + + + + + + + + + + + + diff --git a/api/tests/server.cpp b/api/tests/server.cpp new file mode 100644 index 00000000..10bad23e --- /dev/null +++ b/api/tests/server.cpp @@ -0,0 +1,21 @@ +// +// Created by xzl on 2019/12/23. +// + +#include +#include "mediakit.h" +#include "unistd.h" +int main(int argc,char *argv[]){ + mk_env_init1(0,0,0, nullptr,0, nullptr, nullptr); + mk_http_server_start(80,false); + mk_rtsp_server_start(554,false); + mk_rtmp_server_start(1935,false); + mk_rtp_server_start(10000); + + static bool flag = true; + signal(SIGINT, [](int) { flag = false; });// 设置退出信号 + + while (flag){ + sleep(1); + } +} \ No newline at end of file