Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ZenLib_Checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ jobs:
echo "::endgroup::"
if [ -z "${{ matrix.no_cmake }}" ] ; then
echo "::group::CMake, Unicode ${Unicode}"
cmake -S Project/CMake -B build_${Unicode} -DCMAKE_BUILD_TYPE=Release -DENABLE_UNICODE=$([ "${Unicode}" == "yes" ] && echo ON || echo OFF)
cmake -S Project/CMake -B build_${Unicode} -DCMAKE_BUILD_TYPE=Release -DBUILD_ZENLIB_TESTS=ON -DENABLE_UNICODE=$([ "${Unicode}" == "yes" ] && echo ON || echo OFF)
cmake --build build_${Unicode} -j4
ctest --test-dir build_${Unicode} --output-on-failure
echo "::endgroup::"
fi
done
Expand Down Expand Up @@ -213,10 +214,12 @@ jobs:
run: |
foreach ($Unicode in 'ON', 'OFF') {
Write-Host "::group::Unicode $Unicode"
cmake -S Project/CMake -B build_$Unicode -DCMAKE_BUILD_TYPE=Release -DENABLE_UNICODE=$Unicode
cmake -S Project/CMake -B build_$Unicode -DCMAKE_BUILD_TYPE=Release -DBUILD_ZENLIB_TESTS=ON -DENABLE_UNICODE=$Unicode
if ($LASTEXITCODE) { exit 1 }
cmake --build build_$Unicode --config Release
if ($LASTEXITCODE) { exit 1 }
ctest --test-dir build_$Unicode -C Release --output-on-failure
if ($LASTEXITCODE) { exit 1 }
Write-Host "::endgroup::"
}

Expand Down
10 changes: 10 additions & 0 deletions Project/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ endif()

option(ENABLE_UNICODE "Enable unicode support" ON)
option(LARGE_FILES "Enable large files support" ON)
option(BUILD_ZENLIB_TESTS "Build ZenLib tests" OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/Modules/")
set(ZenLib_SOURCES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../Source)
Expand Down Expand Up @@ -186,6 +187,15 @@ set_target_properties(zen PROPERTIES
include(EnableLatestCXX)
enable_latest_cxx(zen)

if(BUILD_ZENLIB_TESTS)
enable_testing()
add_executable(zen_bitstream_tests
${CMAKE_CURRENT_SOURCE_DIR}/../GNU/Library/Tests/BitStream.cpp)
target_link_libraries(zen_bitstream_tests PRIVATE zen)
enable_latest_cxx(zen_bitstream_tests)
add_test(NAME ZenLib.BitStream COMMAND zen_bitstream_tests)
endif()

install(TARGETS zen EXPORT zen-export
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/ZenLib
RUNTIME DESTINATION ${BIN_INSTALL_DIR}
Expand Down
12 changes: 10 additions & 2 deletions Project/GNU/Library/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ pkgconfig_DATA = libzen.pc

AM_TESTS_FD_REDIRECT = 9>&2

TESTS = test/filename.sh
TESTS = \
test/filename.sh \
Tests/zen_bitstream

check_PROGRAMS = test/zen_filename
check_PROGRAMS = \
test/zen_filename \
Tests/zen_bitstream
test_zen_filename_SOURCES = test/Source/filename.cpp
test_zen_filename_CXXFLAGS = $(AM_CXXFLAGS) -Wall -Wextra
test_zen_filename_LDADD = libzen.la

Tests_zen_bitstream_SOURCES = Tests/BitStream.cpp
Tests_zen_bitstream_CXXFLAGS = $(AM_CXXFLAGS) -Wall -Wextra
Tests_zen_bitstream_LDADD = libzen.la

AM_CXXFLAGS = -std=c++11
AM_CPPFLAGS = -I../../../Source
68 changes: 68 additions & 0 deletions Project/GNU/Library/Tests/BitStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a zlib-style license that can
* be found in the License.txt file in the root of the source tree.
*/

#include "ZenLib/BitStream_LE.h"

#include <iostream>

using namespace ZenLib;

namespace
{

bool Check(bool Condition, const char* Message)
{
if (Condition)
return true;

std::cerr << Message << '\n';
return false;
}

bool InvalidReadDoesNotChangePreviousOffset()
{
const int8u Data[] = { 0x11, 0x22, 0x33 };
BitStream_LE BitStream(Data, sizeof(Data));

if (!Check(BitStream.Get(8)==0x11, "Initial read returned an unexpected value"))
return false;
if (!Check(BitStream.OffsetBeforeLastCall_Get()==0, "Initial read stored an unexpected previous offset"))
return false;

const auto Remain=BitStream.Remain();
const auto Offset=BitStream.Offset_Get();
const auto BitOffset=BitStream.BitOffset_Get();
const auto PreviousOffset=BitStream.OffsetBeforeLastCall_Get();

if (!Check(BitStream.Get(0)==0, "A zero-bit read returned an unexpected value"))
return false;
if (!Check(BitStream.Get(33)==0, "An oversized read returned an unexpected value"))
return false;
BitStream.Skip(0);

if (!Check(BitStream.Remain()==Remain, "An invalid read changed the remaining bit count"))
return false;
if (!Check(BitStream.Offset_Get()==Offset, "An invalid read changed the byte offset"))
return false;
if (!Check(BitStream.BitOffset_Get()==BitOffset, "An invalid read changed the bit offset"))
return false;
if (!Check(BitStream.OffsetBeforeLastCall_Get()==PreviousOffset, "An invalid read changed the previous-call offset"))
return false;

if (!Check(BitStream.Get(8)==0x22, "Second valid read returned an unexpected value"))
return false;
if (!Check(BitStream.OffsetBeforeLastCall_Get()==1, "A valid read did not update the previous-call offset"))
return false;

return true;
}

} // unnamed namespace

int main()
{
return InvalidReadDoesNotChangePreviousOffset() ? 0 : 1;
}
Loading