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/date_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::DateParser;
16 using webm::ElementParserTest;
17 using webm::kUnknownElementSize;
18 using webm::Status;
19 
20 namespace {
21 
22 class DateParserTest : public ElementParserTest<DateParser> {};
23 
TEST_F(DateParserTest,InvalidSize)24 TEST_F(DateParserTest, InvalidSize) {
25   TestInit(4, Status::kInvalidElementSize);
26   TestInit(9, Status::kInvalidElementSize);
27   TestInit(kUnknownElementSize, Status::kInvalidElementSize);
28 }
29 
TEST_F(DateParserTest,CustomDefault)30 TEST_F(DateParserTest, CustomDefault) {
31   ResetParser(-1);
32 
33   ParseAndVerify();
34 
35   EXPECT_EQ(-1, parser_.value());
36 }
37 
TEST_F(DateParserTest,ValidDate)38 TEST_F(DateParserTest, ValidDate) {
39   ParseAndVerify();
40   EXPECT_EQ(0, parser_.value());
41 
42   SetReaderData({0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0});
43   ParseAndVerify();
44   EXPECT_EQ(0x123456789ABCDEF0, parser_.value());
45 }
46 
TEST_F(DateParserTest,IncrementalParse)47 TEST_F(DateParserTest, IncrementalParse) {
48   SetReaderData({0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10});
49 
50   IncrementalParseAndVerify();
51 
52   EXPECT_EQ(static_cast<std::int64_t>(0xFEDCBA9876543210), parser_.value());
53 }
54 
55 }  // namespace
56