xref: /aosp_15_r20/external/libwebm/webm_parser/tests/size_parser_test.cc (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 #include "src/size_parser.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "test_utils/parser_test.h"
13 #include "webm/status.h"
14 
15 using webm::ParserTest;
16 using webm::SizeParser;
17 using webm::Status;
18 
19 namespace {
20 
21 class SizeParserTest : public ParserTest<SizeParser> {};
22 
TEST_F(SizeParserTest,InvalidSize)23 TEST_F(SizeParserTest, InvalidSize) {
24   SetReaderData({0x00});
25   ParseAndExpectResult(Status::kInvalidElementSize);
26 }
27 
TEST_F(SizeParserTest,EarlyEndOfFile)28 TEST_F(SizeParserTest, EarlyEndOfFile) {
29   SetReaderData({0x01});
30   ParseAndExpectResult(Status::kEndOfFile);
31 }
32 
TEST_F(SizeParserTest,ValidSize)33 TEST_F(SizeParserTest, ValidSize) {
34   SetReaderData({0x80});
35   ParseAndVerify();
36   EXPECT_EQ(static_cast<std::uint64_t>(0), parser_.size());
37 
38   ResetParser();
39   SetReaderData({0x01, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE});
40   ParseAndVerify();
41   EXPECT_EQ(static_cast<std::uint64_t>(0x123456789ABCDE), parser_.size());
42 }
43 
TEST_F(SizeParserTest,UnknownSize)44 TEST_F(SizeParserTest, UnknownSize) {
45   SetReaderData({0xFF});
46   ParseAndVerify();
47   EXPECT_EQ(static_cast<std::uint64_t>(0xFFFFFFFFFFFFFFFF), parser_.size());
48 
49   ResetParser();
50   SetReaderData({0x1F, 0xFF, 0xFF, 0xFF});
51   ParseAndVerify();
52   EXPECT_EQ(static_cast<std::uint64_t>(0xFFFFFFFFFFFFFFFF), parser_.size());
53 }
54 
TEST_F(SizeParserTest,IncrementalParse)55 TEST_F(SizeParserTest, IncrementalParse) {
56   SetReaderData({0x11, 0x23, 0x45, 0x67});
57   IncrementalParseAndVerify();
58   EXPECT_EQ(static_cast<std::uint64_t>(0x01234567), parser_.size());
59 }
60 
61 }  // namespace
62