libobs: Add sample unit tests leveraging cmocka
parent
381960a7bc
commit
35088e0d9e
|
@ -2,8 +2,6 @@ name: 'CI Multiplatform Build'
|
|||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
@ -121,11 +119,15 @@ jobs:
|
|||
run: |
|
||||
mkdir ./build
|
||||
cd ./build
|
||||
cmake -DENABLE_SPARKLE_UPDATER=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DQTDIR="/usr/local/Cellar/qt/${{ env.QT_VERSION }}" -DDepsPath="/tmp/obsdeps" -DVLCPath="${{ github.workspace }}/cmbuild/vlc-${{ env.VLC_VERSION }}" -DENABLE_VLC=ON -DBUILD_BROWSER=ON -DBROWSER_DEPLOY=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64" ..
|
||||
cmake -DENABLE_UNIT_TESTS=YES -DENABLE_SPARKLE_UPDATER=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 -DQTDIR="/usr/local/Cellar/qt/${{ env.QT_VERSION }}" -DDepsPath="/tmp/obsdeps" -DVLCPath="${{ github.workspace }}/cmbuild/vlc-${{ env.VLC_VERSION }}" -DENABLE_VLC=ON -DBUILD_BROWSER=ON -DBROWSER_DEPLOY=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64" ..
|
||||
- name: 'Build'
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}/build
|
||||
run: make -j4
|
||||
- name: 'Test'
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}/build
|
||||
run: make CTEST_OUTPUT_ON_FAILURE=1 test
|
||||
- name: 'Install prerequisite: Packages app'
|
||||
if: success() && (github.event_name != 'pull_request' || contains( github.event.pull_request.labels.*.name, 'Seeking Testers'))
|
||||
shell: bash
|
||||
|
@ -289,7 +291,8 @@ jobs:
|
|||
python3-dev \
|
||||
qtbase5-dev \
|
||||
libqt5svg5-dev \
|
||||
swig
|
||||
swig \
|
||||
libcmocka-dev
|
||||
- name: 'Restore Chromium Embedded Framework from cache'
|
||||
id: cef-cache
|
||||
uses: actions/cache@v1
|
||||
|
@ -310,11 +313,15 @@ jobs:
|
|||
run: |
|
||||
mkdir ./build
|
||||
cd ./build
|
||||
cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DENABLE_VLC=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_linux64" ..
|
||||
cmake -DUNIX_STRUCTURE=0 -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/obs-studio-portable" -DENABLE_UNIT_TESTS=ON -DENABLE_VLC=ON -DBUILD_CAPTIONS=ON -DWITH_RTMPS=ON -DBUILD_BROWSER=ON -DCEF_ROOT_DIR="${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_linux64" ..
|
||||
- name: 'Build'
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}/build
|
||||
run: make -j4
|
||||
- name: 'Test'
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}/build
|
||||
run: make CTEST_OUTPUT_ON_FAILURE=1 test
|
||||
- name: 'Package'
|
||||
if: success() && (github.event_name != 'pull_request' || contains( github.event.pull_request.labels.*.name, 'Seeking Testers'))
|
||||
shell: bash
|
||||
|
|
|
@ -28,7 +28,7 @@ sudo installer -pkg ./Packages.pkg -target /
|
|||
brew update
|
||||
|
||||
#Base OBS Deps and ccache
|
||||
for DEPENDENCY in jack speexdsp ccache mbedtls freetype fdk-aac; do
|
||||
for DEPENDENCY in jack speexdsp ccache mbedtls freetype fdk-aac cmocka; do
|
||||
if [ ! -d "$(brew --cellar)/${DEPENDENCY}" ]; then
|
||||
brew install $DEPENDENCY
|
||||
else
|
||||
|
|
|
@ -4,6 +4,7 @@ brew "speexdsp"
|
|||
brew "cmake"
|
||||
brew "freetype"
|
||||
brew "fdk-aac"
|
||||
brew "cmocka"
|
||||
brew "https://gist.githubusercontent.com/DDRBoxman/9c7a2b08933166f4b61ed9a44b242609/raw/ef4de6c587c6bd7f50210eccd5bd51ff08e6de13/qt.rb", link: true
|
||||
brew "https://gist.githubusercontent.com/DDRBoxman/4cada55c51803a2f963fa40ce55c9d3e/raw/572c67e908bfbc1bcb8c476ea77ea3935133f5b5/swig.rb", link: true
|
||||
brew "akeru-inc/tap/xcnotary"
|
||||
|
|
|
@ -244,7 +244,12 @@ if(NOT INSTALLER_RUN)
|
|||
add_subdirectory(libobs)
|
||||
add_subdirectory(plugins)
|
||||
add_subdirectory(UI)
|
||||
if (BUILD_TESTS)
|
||||
|
||||
if (ENABLE_UNIT_TESTS)
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
if (BUILD_TESTS OR ENABLE_UNIT_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
|
||||
add_subdirectory(test-input)
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(test-input)
|
||||
|
||||
if(WIN32)
|
||||
add_subdirectory(win)
|
||||
if(WIN32)
|
||||
add_subdirectory(win)
|
||||
endif()
|
||||
|
||||
if(APPLE AND UNIX)
|
||||
add_subdirectory(osx)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE AND UNIX)
|
||||
add_subdirectory(osx)
|
||||
if (ENABLE_UNIT_TESTS)
|
||||
add_subdirectory(cmocka)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
project(obs-cmocka)
|
||||
|
||||
# Fix libobs path
|
||||
macro(fixLink target_arg)
|
||||
if(APPLE AND UNIX)
|
||||
add_custom_command (TARGET ${target_arg}
|
||||
POST_BUILD COMMAND "${CMAKE_INSTALL_NAME_TOOL}"
|
||||
"-change" "@rpath/libobs.0.dylib" "@executable_path/../../libobs/libobs.0.dylib"
|
||||
"$<TARGET_FILE:${target_arg}>" VERBATIM)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(CMAKE_MACOSX_RPATH TRUE)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/")
|
||||
|
||||
find_package(CMocka CONFIG REQUIRED)
|
||||
include_directories(${CMOCKA_INCLUDE_DIR})
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
|
||||
|
||||
# fix rpath on linux
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN";../../libobs)
|
||||
endif()
|
||||
|
||||
# Serializer test
|
||||
add_executable(test_serializer test_serializer.c)
|
||||
target_link_libraries(test_serializer ${CMOCKA_LIBRARIES} libobs)
|
||||
|
||||
add_test(test_serializer ${CMAKE_CURRENT_BINARY_DIR}/test_serializer)
|
||||
fixLink(test_serializer)
|
||||
|
||||
|
||||
# darray test
|
||||
add_executable(test_darray test_darray.c)
|
||||
target_link_libraries(test_darray ${CMOCKA_LIBRARIES} libobs)
|
||||
|
||||
add_test(test_darray ${CMAKE_CURRENT_BINARY_DIR}/test_darray)
|
||||
fixLink(test_darray)
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <util/darray.h>
|
||||
|
||||
static void array_basic_test(void **state)
|
||||
{
|
||||
DARRAY(uint8_t) testarray;
|
||||
da_init(testarray);
|
||||
|
||||
uint8_t t = 1;
|
||||
da_push_back_array(testarray, &t, sizeof(uint8_t));
|
||||
|
||||
assert_int_equal(testarray.num, 1);
|
||||
assert_memory_equal(testarray.array, &t, 1);
|
||||
|
||||
da_free(testarray);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(array_basic_test),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <util/array-serializer.h>
|
||||
|
||||
static void serialize_test(void **state)
|
||||
{
|
||||
struct array_output_data output;
|
||||
struct serializer s;
|
||||
|
||||
array_output_serializer_init(&s, &output);
|
||||
|
||||
s_w8(&s, 0x01);
|
||||
s_w8(&s, 0xff);
|
||||
s_w8(&s, 0xe1);
|
||||
|
||||
assert_int_equal(output.bytes.num, 3);
|
||||
uint8_t expected[3] = {0x01, 0xff, 0xe1};
|
||||
assert_memory_equal(output.bytes.array, expected, 3);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(serialize_test),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
|
@ -40,7 +40,7 @@ using DisplayContext =
|
|||
|
||||
static void CreateOBS()
|
||||
{
|
||||
if (!obs_startup("en", nullptr))
|
||||
if (!obs_startup("en", nullptr, nullptr))
|
||||
throw "Couldn't create OBS";
|
||||
|
||||
struct obs_video_info ovi;
|
||||
|
@ -67,7 +67,7 @@ static DisplayContext CreateDisplay(NSView *view)
|
|||
info.zsformat = GS_ZS_NONE;
|
||||
info.window.view = view;
|
||||
|
||||
return DisplayContext{obs_display_create(&info)};
|
||||
return DisplayContext{obs_display_create(&info, 0)};
|
||||
}
|
||||
|
||||
static SceneContext SetupScene()
|
||||
|
|
Loading…
Reference in New Issue