Skip to content

Commit

Permalink
Transfer old extension header and transfer tests into new framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickhopes committed Nov 3, 2022
1 parent 855a5bb commit 9ab1aa8
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 240 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ set(EXPORT_TARGET_NAME ortp)

add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS)
if(ENABLE_UNIT_TESTS AND NOT WIN32)
add_subdirectory(tester)
endif()

Expand Down
1 change: 0 additions & 1 deletion src/tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ tevmrtprecv
tevrtprecv
tevrtpsend
rtpsend_stupid
rtpextensionheader
4 changes: 2 additions & 2 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
############################################################################

if (NOT IOS)
set(EXECUTABLES rtpsend rtprecv mrtpsend mrtprecv test_timer tevrtpsend tevrtprecv rtpsend_stupid rtpextensionheader rtptransfer)
set(EXECUTABLES rtpsend rtprecv mrtpsend mrtprecv test_timer tevrtpsend tevrtprecv rtpsend_stupid)
foreach(executable ${EXECUTABLES})
bc_apply_compile_flags(${executable}.c STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
add_executable(${executable} ${executable}.c)
target_link_libraries(${executable} ortp ${BCTOOLBOX_CORE_LIBRARIES})
endforeach()

install(TARGETS ${EXECUTABLES}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
146 changes: 0 additions & 146 deletions src/tests/rtpextensionheader.c

This file was deleted.

7 changes: 7 additions & 0 deletions tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ if(WIN32)
list(APPEND ORTP_LIBS_FOR_TESTER Ws2_32)
endif()

set(RAW_FILES
raw/h265-iframe
)

set(SOURCE_FILES_C
ortp_tester.c
extension_header_tester.c
fec_tester.c
rtp_tester.c
)

set(IOS_RESOURCE_FILE)
Expand Down Expand Up @@ -88,5 +94,6 @@ else()
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES ${RAW_FILES} DESTINATION "${CMAKE_INSTALL_DATADIR}/ortp_tester/raw")
endif()
endif()
190 changes: 190 additions & 0 deletions tester/extension_header_tester.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of oRTP.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "ortp_tester.h"
#include <ortp/ortp.h>

static RtpSession *session = NULL;

static int tester_before_all(void) {
ortp_init();
ortp_scheduler_init();

session = rtp_session_new(RTP_SESSION_SENDONLY);

return 0;
}

static int tester_after_all(void) {
rtp_session_destroy(session);
session = NULL;

ortp_exit();

return 0;
}

static void insert_extension_header_into_packet(void) {
uint16_t extbit;
size_t size, expected_size;
char *test = "Running test";

mblk_t *packet = rtp_session_create_packet(session, RTP_FIXED_HEADER_SIZE, NULL, 0);

rtp_add_extension_header(packet, 10, strlen(test), (uint8_t *) test);

extbit = rtp_get_extbit(packet);
BC_ASSERT_EQUAL(extbit, 1, uint16_t, "%d");

size = rtp_get_extheader(packet, NULL, NULL);

expected_size = (strlen(test) + 1); // extension + 1-byte header + potential padding
if (expected_size % 4 != 0) {
expected_size = expected_size + (4 - expected_size % 4);
}

BC_ASSERT_EQUAL(size, expected_size, size_t, "%zu");

freemsg(packet);
}

static void insert_multiple_extension_headers_into_packet(void) {
size_t size;
char *test = "Running test";
char *test2 = "foo";
char *test3 = "C'est pas faux";
uint8_t *data;
char *copy;

mblk_t *packet = rtp_session_create_packet(session, RTP_FIXED_HEADER_SIZE, NULL, 0);

rtp_add_extension_header(packet, 1, strlen(test), (uint8_t *) test);
rtp_add_extension_header(packet, 2, strlen(test2), (uint8_t *) test2);
rtp_add_extension_header(packet, 3, strlen(test3), (uint8_t *) test3);

size = rtp_get_extheader(packet, NULL, NULL);
BC_ASSERT_GREATER(size, 0, size_t, "%zu");

size = rtp_get_extension_header(packet, 1, &data);
BC_ASSERT_EQUAL(size, strlen(test), size_t, "%zu");

copy = ortp_strndup((char *) data, (int) size);
BC_ASSERT_STRING_EQUAL(copy, test);
free(copy);

size = rtp_get_extension_header(packet, 2, &data);
BC_ASSERT_EQUAL(size, strlen(test2), size_t, "%zu");

copy = ortp_strndup((char *) data, (int) size);
BC_ASSERT_STRING_EQUAL(copy, test2);
free(copy);

size = rtp_get_extension_header(packet, 3, &data);
BC_ASSERT_EQUAL(size, strlen(test3), size_t, "%zu");

copy = ortp_strndup((char *) data, (int) size);
BC_ASSERT_STRING_EQUAL(copy, test3);
free(copy);

freemsg(packet);
}

static void insert_client_to_mixer_into_packet(void) {
int result;
bool_t voice_activity;

mblk_t *packet = rtp_session_create_packet(session, RTP_FIXED_HEADER_SIZE, NULL, 0);

rtp_add_client_to_mixer_audio_level(packet, RTP_EXTENSION_CLIENT_TO_MIXER_AUDIO_LEVEL, TRUE, -64);

result = rtp_get_client_to_mixer_audio_level(packet, RTP_EXTENSION_CLIENT_TO_MIXER_AUDIO_LEVEL, &voice_activity);
BC_ASSERT_EQUAL(result, -64, int, "%d");
BC_ASSERT_EQUAL(voice_activity, TRUE, bool_t, "%d");

freemsg(packet);
}

static void insert_mixer_to_client_into_packet(void) {
int audio_size;
rtp_audio_level_t audio_levels[15];

mblk_t *packet = rtp_session_create_packet(session, RTP_FIXED_HEADER_SIZE, NULL, 0);
rtp_audio_level_t values[5] = {{1, -127}, {2, -115}, {0, -53}, {4, -28}, {5, 0}};

rtp_add_mixer_to_client_audio_level(packet, RTP_EXTENSION_MIXER_TO_CLIENT_AUDIO_LEVEL, 5, values);
audio_size = rtp_get_mixer_to_client_audio_level(packet, RTP_EXTENSION_MIXER_TO_CLIENT_AUDIO_LEVEL, audio_levels);

BC_ASSERT_EQUAL(audio_size, 5, int, "%d");

BC_ASSERT_EQUAL(audio_levels[0].csrc, 1, int, "%d");
BC_ASSERT_EQUAL(audio_levels[0].dbov, -127, int, "%d");

BC_ASSERT_EQUAL(audio_levels[1].csrc, 2, int, "%d");
BC_ASSERT_EQUAL(audio_levels[1].dbov, -115, int, "%d");

BC_ASSERT_EQUAL(audio_levels[2].csrc, 0, int, "%d");
BC_ASSERT_EQUAL(audio_levels[2].dbov, -53, int, "%d");

BC_ASSERT_EQUAL(audio_levels[3].csrc, 4, int, "%d");
BC_ASSERT_EQUAL(audio_levels[3].dbov, -28, int, "%d");

BC_ASSERT_EQUAL(audio_levels[4].csrc, 5, int, "%d");
BC_ASSERT_EQUAL(audio_levels[4].dbov, 0, int, "%d");

freemsg(packet);
}

static void insert_frame_marking_into_packet(void) {
size_t size;
int ret;
uint8_t result;

mblk_t *packet = rtp_session_create_packet(session, RTP_FIXED_HEADER_SIZE, NULL, 0);
uint8_t marker = RTP_FRAME_MARKER_START | RTP_FRAME_MARKER_INDEPENDENT;

rtp_add_frame_marker(packet, RTP_EXTENSION_FRAME_MARKING, marker);

size = rtp_get_extheader(packet, NULL, NULL);
BC_ASSERT_GREATER(size, 0, size_t, "%zu");

ret = rtp_get_frame_marker(packet, RTP_EXTENSION_FRAME_MARKING, &result);
BC_ASSERT_EQUAL(ret, 1, int, "%d");
BC_ASSERT_TRUE(result & RTP_FRAME_MARKER_START);
BC_ASSERT_TRUE(result & RTP_FRAME_MARKER_INDEPENDENT);

freemsg(packet);
}

static test_t tests[] = {
TEST_NO_TAG("Insert an extension header into a packet", insert_extension_header_into_packet),
TEST_NO_TAG("Insert multiple extension headers into a packet", insert_multiple_extension_headers_into_packet),
TEST_NO_TAG("Insert client to mixer audio level into a packet", insert_client_to_mixer_into_packet),
TEST_NO_TAG("Insert mixer to client audio level into a packet", insert_mixer_to_client_into_packet),
TEST_NO_TAG("Insert frame marking into a packet", insert_frame_marking_into_packet)
};

test_suite_t extension_header_test_suite = {
"Extension header", // Name of test suite
tester_before_all, // Before all callback
tester_after_all, // After all callback
NULL, // Before each callback
NULL, // After each callback
sizeof(tests) / sizeof(tests[0]), // Size of test table
tests // Table of test suite
};
Loading

0 comments on commit 9ab1aa8

Please sign in to comment.