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/bool_parser.h"
9
10 #include "gtest/gtest.h"
11
12 #include "test_utils/element_parser_test.h"
13 #include "webm/status.h"
14
15 using webm::BoolParser;
16 using webm::ElementParserTest;
17 using webm::kUnknownElementSize;
18 using webm::Status;
19
20 namespace {
21
22 class BoolParserTest : public ElementParserTest<BoolParser> {};
23
TEST_F(BoolParserTest,InvalidSize)24 TEST_F(BoolParserTest, InvalidSize) {
25 TestInit(9, Status::kInvalidElementSize);
26 TestInit(kUnknownElementSize, Status::kInvalidElementSize);
27 }
28
TEST_F(BoolParserTest,InvalidValue)29 TEST_F(BoolParserTest, InvalidValue) {
30 SetReaderData({0x02});
31 ParseAndExpectResult(Status::kInvalidElementValue);
32
33 SetReaderData({0xFF, 0xFF});
34 ParseAndExpectResult(Status::kInvalidElementValue);
35 }
36
TEST_F(BoolParserTest,CustomDefault)37 TEST_F(BoolParserTest, CustomDefault) {
38 ResetParser(true);
39
40 ParseAndVerify();
41
42 EXPECT_EQ(true, parser_.value());
43 }
44
TEST_F(BoolParserTest,ValidBool)45 TEST_F(BoolParserTest, ValidBool) {
46 ParseAndVerify();
47 EXPECT_EQ(false, parser_.value());
48
49 SetReaderData({0x00, 0x00, 0x01});
50 ParseAndVerify();
51 EXPECT_EQ(true, parser_.value());
52
53 SetReaderData({0x00, 0x00, 0x00, 0x00, 0x00});
54 ParseAndVerify();
55 EXPECT_EQ(false, parser_.value());
56
57 SetReaderData({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01});
58 ParseAndVerify();
59 EXPECT_EQ(true, parser_.value());
60 }
61
TEST_F(BoolParserTest,IncrementalParse)62 TEST_F(BoolParserTest, IncrementalParse) {
63 SetReaderData({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00});
64
65 IncrementalParseAndVerify();
66
67 EXPECT_EQ(false, parser_.value());
68 }
69
70 } // namespace
71