-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test to write/read an EBML header
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright © 2024 Steve Lhomme. | ||
// SPDX-License-Identifier: ISC | ||
|
||
#include <ebml/EbmlHead.h> | ||
#include <ebml/EbmlSubHead.h> | ||
#include <ebml/EbmlMaster.h> | ||
#include <ebml/EbmlStream.h> | ||
#include <ebml/MemIOCallback.h> | ||
|
||
int main(int /*argc*/, char** /*argv*/) | ||
{ | ||
///// Writing test | ||
libebml::MemIOCallback Ebml_file; | ||
libebml::EbmlHead TestHead; | ||
|
||
libebml::EDocType & MyDocType = libebml::GetChild<libebml::EDocType>(TestHead); | ||
MyDocType.SetValue("matroska"); | ||
|
||
libebml::EDocTypeVersion & MyDocTypeVer = libebml::GetChild<libebml::EDocTypeVersion>(TestHead); | ||
MyDocTypeVer.SetValue(1); | ||
|
||
libebml::GetChild<libebml::EDocTypeReadVersion>(TestHead).SetValue(1); | ||
|
||
libebml::GetChild<libebml::EMaxSizeLength>(TestHead).SetValue(8); | ||
|
||
auto length = TestHead.Render(Ebml_file, libebml::EbmlElement::WriteAll); | ||
if (length != 40) | ||
return 1; | ||
|
||
///// Reading test | ||
Ebml_file.setFilePointer(0); | ||
libebml::EbmlStream aStream(Ebml_file); | ||
libebml::EbmlElement * ElementLevel0; | ||
|
||
// find the EBML head in the file | ||
ElementLevel0 = aStream.FindNextID(EBML_INFO(libebml::EbmlHead), 0xFFFFFFFFL); | ||
if (ElementLevel0 == nullptr) | ||
return 1; | ||
|
||
if (ElementLevel0->GetClassId() != libebml::EbmlHead::ClassId()) | ||
return 1; | ||
|
||
libebml::EbmlHead &ReadHead = static_cast<libebml::EbmlHead &>(*ElementLevel0); | ||
|
||
auto read = ReadHead.ReadData(Ebml_file, libebml::SCOPE_ALL_DATA); | ||
if (read != 35) | ||
return 1; | ||
|
||
libebml::EDocType & ReadDocType = libebml::GetChild<libebml::EDocType>(ReadHead); | ||
const std::string & DocTypeStr = static_cast<const std::string &>(ReadDocType); | ||
if (DocTypeStr != "matroska") | ||
return 1; | ||
|
||
auto & ReadMaxLength = libebml::GetChild<const libebml::EMaxSizeLength>(ReadHead); | ||
if (static_cast<std::uint64_t>(ReadMaxLength) != 8) | ||
return 1; | ||
|
||
return 0; | ||
} |