Skip to content

Commit

Permalink
Merge pull request #175 from OpenVisualCloud/unit-tests
Browse files Browse the repository at this point in the history
Add skeleton for unit tests
  • Loading branch information
Sakoram authored Aug 16, 2024
2 parents 76ad529 + 122b471 commit 41c6c45
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(CMAKE_SKIP_RPATH TRUE)
set(MCM_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(MP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/media-proxy)
set(SDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk)
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests/unit)
set(SDK_INCLUDE_DIR ${SDK_DIR}/include)

# Setup output folder
Expand All @@ -32,5 +33,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(${SDK_DIR})
add_subdirectory(${MP_DIR})

target_include_directories(media_proxy PUBLIC ${SDK_INCLUDE_DIR})
target_link_libraries(media_proxy PUBLIC mcm_dp)
option(BUILD_UNIT_TESTS "Build and enable unit tests" ON)
if (BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(${TESTS_DIR})
endif()

target_include_directories(media_proxy_lib PUBLIC ${SDK_INCLUDE_DIR})
target_link_libraries(media_proxy_lib PUBLIC mcm_dp)
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ SCRIPT_DIR="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")"

# Set build type. ("Debug" or "Release")
BUILD_TYPE="${BUILD_TYPE:-Release}"
# To disable the building of unit tests, set the value to "OFF".
BUILD_UNIT_TESTS="${BUILD_UNIT_TESTS:-ON}"
INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}"

cmake -B "${SCRIPT_DIR}/out" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
-DBUILD_UNIT_TESTS="${BUILD_UNIT_TESTS}" \
"${SCRIPT_DIR}"
cmake --build "${SCRIPT_DIR}/out" -j

Expand Down
8 changes: 6 additions & 2 deletions media-proxy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ ADD_DEFINITIONS(-DIMTL_CONFIG_PATH=\"${CMAKE_INSTALL_PREFIX}/etc/imtl.json\")
# Include generated *.pb.h files
include_directories(${CMAKE_CURRENT_BINARY_DIR} ./include)

add_executable(media_proxy ${proto_srcs} ${grpc_srcs} ${proxy_srcs})
target_link_libraries(media_proxy PRIVATE m ${MTL_LIB} ${_REFLECTION} ${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} ${MEMIF_LIB})
add_library(media_proxy_lib ${proto_srcs} ${grpc_srcs} ${proxy_srcs})
target_link_libraries(media_proxy_lib PUBLIC m ${MTL_LIB} ${_REFLECTION}
${_GRPC_GRPCPP} ${_PROTOBUF_LIBPROTOBUF} ${MEMIF_LIB})

add_executable(media_proxy ${proxy_srcs})
target_link_libraries(media_proxy PRIVATE media_proxy_lib)

install(TARGETS media_proxy DESTINATION ${CMAKE_INSTALL_PATH} COMPONENT media_proxy)
install(FILES imtl.json DESTINATION ${CMAKE_CONFIG_PATH} COMPONENT config)
10 changes: 10 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024 Intel Corporation

set -eo pipefail
SCRIPT_DIR="$(readlink -f "$(dirname -- "${BASH_SOURCE[0]}")")"

# Run all tests verbosely
ctest --test-dir ${SCRIPT_DIR}/out --verbose
18 changes: 18 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Find source files for tests
file(GLOB TEST_SOURCES "*.cc")

set(MP_LIB media_proxy_lib)

# Add an executable for tests
add_executable(mcm_unit_tests ${TEST_SOURCES})

# Link the executable with gtest and gtest_main
target_link_libraries(mcm_unit_tests PRIVATE gtest gtest_main ${MP_LIB})
target_include_directories(mcm_unit_tests PUBLIC
${CMAKE_SOURCE_DIR}/media-proxy/include
# Include generated *.pb.h files
${CMAKE_BINARY_DIR}/media-proxy/
)

# Add tests to CTest
add_test(NAME mcm_unit_tests COMMAND mcm_unit_tests)
10 changes: 10 additions & 0 deletions tests/unit/proxy_context_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <gtest/gtest.h>
#include "proxy_context.h"

// TODO: Create real tests
TEST(ProxyContextTests, ProxyContextConstructor) {
ProxyContext ctx;
EXPECT_EQ(ctx.getTCPListenPort(), 8002);
EXPECT_EQ(ctx.getRPCListenAddress(), "0.0.0.0:8001");
EXPECT_EQ(ctx.getTCPListenAddress(), "0.0.0.0:8002");
}

0 comments on commit 41c6c45

Please sign in to comment.