Skip to content

Commit

Permalink
add tests for EbmlID usage
Browse files Browse the repository at this point in the history
  • Loading branch information
robUx4 committed Dec 19, 2023
1 parent eb40a1f commit 57ef002
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(ebml VERSION 2.0.0)
option(DISABLE_PKGCONFIG "Disable PkgConfig module generation" OFF)
option(DISABLE_CMAKE_CONFIG "Disable CMake package config module generation" OFF)
option(BUILD_SHARED_LIBS "Build libebml as a shared library" OFF)
option(BUILD_TESTING "Build tests" OFF)

include(GNUInstallDirs)

Expand Down Expand Up @@ -98,6 +99,15 @@ if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(ebml PUBLIC EBML_STATIC_DEFINE)
endif()

if (BUILD_TESTING)
enable_testing()

add_executable(test_id test/test_id.cxx)
target_link_libraries(test_id PUBLIC ebml)
add_test(test_id test_id)
endif(BUILD_TESTING)


install(TARGETS ebml
EXPORT EBMLTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
2 changes: 2 additions & 0 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ extern const EbmlSemanticContext Context_EbmlGlobal;
#define DEFINE_EBML_CLASS_GLOBAL(x,id,idl,name) DEFINE_xxx_CLASS_GLOBAL(x,id,idl,name,GetEbmlGlobal_Context)
#define DEFINE_EBML_CLASS_ORPHAN(x,id,idl,name) DEFINE_xxx_CLASS_ORPHAN(x,id,idl,name,GetEbmlGlobal_Context)
#define DEFINE_EBML_UINTEGER_DEF(x,id,idl,parent,name,val) DEFINE_xxx_UINTEGER_DEF(x,id,idl,parent,name,GetEbmlGlobal_Context,val)
#define DEFINE_EBML_STRING(x,id,idl,parent,name) DEFINE_xxx_STRING(x,id,idl,parent,name,GetEbmlGlobal_Context)
#define DEFINE_EBML_UINTEGER(x,id,idl,parent,name) DEFINE_xxx_UINTEGER(x,id,idl,parent,name,GetEbmlGlobal_Context)
#define DEFINE_EBML_STRING_DEF(x,id,idl,parent,name,val) DEFINE_xxx_STRING_DEF(x,id,idl,parent,name,GetEbmlGlobal_Context,val)
#define DEFINE_EBML_BINARY_CONS(x,id,idl,parent,name) DEFINE_xxx_CLASS_CONS(x,id,idl,parent,name,GetEbmlGlobal_Context)

Expand Down
27 changes: 27 additions & 0 deletions test/test_id.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright © 2023 Steve Lhomme.
// SPDX-License-Identifier: ISC

#include <ebml/EbmlId.h>

using namespace libebml;

int main(void)
{
constexpr binary buf[4] = { 0x12, 0x34, 0x56, 0x78 };
EbmlId frombuf(buf, 4);

EbmlId fromint(0x12345678, 4);

EbmlId copy(fromint);
binary read[4];
copy.Fill(read);
if (read[0] != 0x12 || read[1] != 0x34 || read[2] != 0x56 || read[3] != 0x78)
return 1;

EbmlId eq = fromint;
eq.Fill(read);
if (read[0] != 0x12 || read[1] != 0x34 || read[2] != 0x56 || read[3] != 0x78)
return 1;

return 0;
}

0 comments on commit 57ef002

Please sign in to comment.