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/id_parser.h"
9
10 #include "gtest/gtest.h"
11
12 #include "test_utils/parser_test.h"
13 #include "webm/id.h"
14 #include "webm/status.h"
15
16 using webm::Id;
17 using webm::IdParser;
18 using webm::ParserTest;
19 using webm::Status;
20
21 namespace {
22
23 class IdParserTest : public ParserTest<IdParser> {};
24
TEST_F(IdParserTest,InvalidId)25 TEST_F(IdParserTest, InvalidId) {
26 SetReaderData({0x00});
27 ParseAndExpectResult(Status::kInvalidElementId);
28
29 ResetParser();
30 SetReaderData({0x0F});
31 ParseAndExpectResult(Status::kInvalidElementId);
32 }
33
TEST_F(IdParserTest,EarlyEndOfFile)34 TEST_F(IdParserTest, EarlyEndOfFile) {
35 SetReaderData({0x40});
36 ParseAndExpectResult(Status::kEndOfFile);
37 }
38
TEST_F(IdParserTest,ValidId)39 TEST_F(IdParserTest, ValidId) {
40 SetReaderData({0x80});
41 ParseAndVerify();
42 EXPECT_EQ(static_cast<Id>(0x80), parser_.id());
43
44 ResetParser();
45 SetReaderData({0x1F, 0xFF, 0xFF, 0xFF});
46 ParseAndVerify();
47 EXPECT_EQ(static_cast<Id>(0x1FFFFFFF), parser_.id());
48 }
49
TEST_F(IdParserTest,IncrementalParse)50 TEST_F(IdParserTest, IncrementalParse) {
51 SetReaderData({0x1A, 0x45, 0xDF, 0xA3});
52 IncrementalParseAndVerify();
53 EXPECT_EQ(Id::kEbml, parser_.id());
54 }
55
56 } // namespace
57