#include "src/chapter_atom_parser.h"
#include "gtest/gtest.h"
#include "test_utils/element_parser_test.h"
#include "webm/id.h"
#include "webm/status.h"
using webm::ChapterAtom;
using webm::ChapterAtomParser;
using webm::ChapterDisplay;
using webm::ElementParserTest;
using webm::Id;
using webm::Status;
namespace {
class ChapterAtomParserTest
: public ElementParserTest<ChapterAtomParser, Id::kChapterAtom> {};
TEST_F(ChapterAtomParserTest, DefaultParse) {
ParseAndVerify();
const ChapterAtom chapter_atom = parser_.value();
EXPECT_FALSE(chapter_atom.uid.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.uid.value());
EXPECT_FALSE(chapter_atom.string_uid.is_present());
EXPECT_EQ("", chapter_atom.string_uid.value());
EXPECT_FALSE(chapter_atom.time_start.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.time_start.value());
EXPECT_FALSE(chapter_atom.time_end.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.time_end.value());
EXPECT_EQ(static_cast<std::size_t>(0), chapter_atom.displays.size());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.atoms.size());
}
TEST_F(ChapterAtomParserTest, DefaultValues) {
SetReaderData({
0x73, 0xC4, 0x80,
0x56, 0x54, 0x80,
0x91, 0x40, 0x00,
0x92, 0x40, 0x00,
0x80, 0x40, 0x00,
0xB6, 0x40, 0x00, });
ParseAndVerify();
const ChapterAtom chapter_atom = parser_.value();
EXPECT_TRUE(chapter_atom.uid.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.uid.value());
EXPECT_TRUE(chapter_atom.string_uid.is_present());
EXPECT_EQ("", chapter_atom.string_uid.value());
EXPECT_TRUE(chapter_atom.time_start.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.time_start.value());
EXPECT_TRUE(chapter_atom.time_end.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(0), chapter_atom.time_end.value());
ASSERT_EQ(static_cast<std::uint64_t>(1), chapter_atom.displays.size());
EXPECT_TRUE(chapter_atom.displays[0].is_present());
EXPECT_EQ(ChapterDisplay{}, chapter_atom.displays[0].value());
ASSERT_EQ(static_cast<std::uint64_t>(1), chapter_atom.atoms.size());
EXPECT_TRUE(chapter_atom.atoms[0].is_present());
EXPECT_EQ(ChapterAtom{}, chapter_atom.atoms[0].value());
}
TEST_F(ChapterAtomParserTest, CustomValues) {
SetReaderData({
0x73, 0xC4, 0x81, 0x01,
0x56, 0x54, 0x81, 0x41,
0x91, 0x40, 0x01, 0x02,
0x92, 0x40, 0x01, 0x03,
0x80, 0x40, 0x04,
0x85, 0x40, 0x01, 0x42,
0x80, 0x40, 0x04,
0x85, 0x40, 0x01, 0x43,
0xB6, 0x40, 0x12,
0x73, 0xC4, 0x81, 0x04,
0xB6, 0x40, 0x04,
0x73, 0xC4, 0x81, 0x05,
0xB6, 0x40, 0x04,
0x73, 0xC4, 0x81, 0x06, });
ParseAndVerify();
const ChapterAtom chapter_atom = parser_.value();
EXPECT_TRUE(chapter_atom.uid.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(1), chapter_atom.uid.value());
EXPECT_TRUE(chapter_atom.string_uid.is_present());
EXPECT_EQ("A", chapter_atom.string_uid.value());
EXPECT_TRUE(chapter_atom.time_start.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(2), chapter_atom.time_start.value());
EXPECT_TRUE(chapter_atom.time_end.is_present());
EXPECT_EQ(static_cast<std::uint64_t>(3), chapter_atom.time_end.value());
ChapterDisplay expected_chapter_display;
ASSERT_EQ(static_cast<std::size_t>(2), chapter_atom.displays.size());
expected_chapter_display.string.Set("B", true);
EXPECT_TRUE(chapter_atom.displays[0].is_present());
EXPECT_EQ(expected_chapter_display, chapter_atom.displays[0].value());
expected_chapter_display.string.Set("C", true);
EXPECT_TRUE(chapter_atom.displays[1].is_present());
EXPECT_EQ(expected_chapter_display, chapter_atom.displays[1].value());
ChapterAtom expected_chapter_atom;
expected_chapter_atom.uid.Set(4, true);
ChapterAtom tmp_atom{};
tmp_atom.uid.Set(5, true);
expected_chapter_atom.atoms.emplace_back(tmp_atom, true);
tmp_atom.uid.Set(6, true);
expected_chapter_atom.atoms.emplace_back(tmp_atom, true);
ASSERT_EQ(static_cast<std::size_t>(1), chapter_atom.atoms.size());
EXPECT_TRUE(chapter_atom.atoms[0].is_present());
EXPECT_EQ(expected_chapter_atom, chapter_atom.atoms[0].value());
}
TEST_F(ChapterAtomParserTest, ExceedMaxRecursionDepth) {
ResetParser(1);
SetReaderData({
0xB6, 0x80, });
ParseAndVerify();
SetReaderData({
0xB6, 0x82,
0xB6, 0x80, });
ParseAndExpectResult(Status::kExceededRecursionDepthLimit);
}
}