1 //===- BitstreamReaderTest.cpp - Tests for BitstreamReader ----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/Bitcode/BitstreamReader.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 
15 namespace {
16 
TEST(BitstreamReaderTest,AtEndOfStream)17 TEST(BitstreamReaderTest, AtEndOfStream) {
18   uint8_t Bytes[4] = {
19     0x00, 0x01, 0x02, 0x03
20   };
21   BitstreamReader Reader(std::begin(Bytes), std::end(Bytes));
22   BitstreamCursor Cursor(Reader);
23 
24   EXPECT_FALSE(Cursor.AtEndOfStream());
25   (void)Cursor.Read(8);
26   EXPECT_FALSE(Cursor.AtEndOfStream());
27   (void)Cursor.Read(24);
28   EXPECT_TRUE(Cursor.AtEndOfStream());
29 
30   Cursor.JumpToBit(0);
31   EXPECT_FALSE(Cursor.AtEndOfStream());
32 
33   Cursor.JumpToBit(32);
34   EXPECT_TRUE(Cursor.AtEndOfStream());
35 }
36 
TEST(BitstreamReaderTest,AtEndOfStreamJump)37 TEST(BitstreamReaderTest, AtEndOfStreamJump) {
38   uint8_t Bytes[4] = {
39     0x00, 0x01, 0x02, 0x03
40   };
41   BitstreamReader Reader(std::begin(Bytes), std::end(Bytes));
42   BitstreamCursor Cursor(Reader);
43 
44   Cursor.JumpToBit(32);
45   EXPECT_TRUE(Cursor.AtEndOfStream());
46 }
47 
TEST(BitstreamReaderTest,AtEndOfStreamEmpty)48 TEST(BitstreamReaderTest, AtEndOfStreamEmpty) {
49   uint8_t Dummy = 0xFF;
50   BitstreamReader Reader(&Dummy, &Dummy);
51   BitstreamCursor Cursor(Reader);
52 
53   EXPECT_TRUE(Cursor.AtEndOfStream());
54 }
55 
56 } // end anonymous namespace
57