Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: unittests/Bitcode/NaClBitstreamReaderTest.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « unittests/Bitcode/NaClBitReaderTest.cpp ('k') | unittests/Bitcode/NaClObjDumpTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- llvm/unittest/Bitcode/NaClBitstreamReaderTest.cpp ------------------===//
2 // Tests issues in NaCl Bitstream Reader.
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 // Tests issues in NaCl Bitstream Reader.
12
13 // TODO(kschimpf) Add more Tests.
14
15 #include "llvm/Bitcode/NaCl/NaClBitstreamReader.h"
16
17 #include "gtest/gtest.h"
18
19 using namespace llvm;
20
21 namespace {
22
23 static const uint64_t BitZero = 0;
24
25 // Initializes array to sequence of alternating zeros/ones.
26 void* InitAltOnes(uint8_t *Array, size_t ArraySize) {
27 for (size_t i = 0; i <ArraySize; ++i) {
28 Array[i] = 0x9;
29 }
30 return Array;
31 }
32
33 // Tests that the default bitstream cursor is at bit zero.
34 TEST(NaClBitstreamTest, DefaultCursorAtBitZero) {
35 uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
36 NaClBitstreamCursor *Cursor =
37 new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
38 NaClBitstreamCursor();
39 EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
40 }
41
42 // Tests that when we initialize the bitstream cursor with a default bitstream
43 // reader, the cursor is at bit zero.
44 TEST(NaClBitstreamTest, CursorOnDefaultReaderAtBitZero) {
45 NaClBitstreamReader Reader;
46 uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
47 NaClBitstreamCursor *Cursor =
48 new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
49 NaClBitstreamCursor(Reader);
50 EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
51 }
52
53 // Tests that when we initialize the bitstream cursor with an array-filled
54 // bitstream reader, the cursor is at bit zero.
55 TEST(NaClBitstreamTest, ReaderCursorAtBitZero) {
56 static const size_t BufferSize = 12;
57 unsigned char Buffer[BufferSize];
58 NaClBitstreamReader Reader(Buffer, Buffer+BufferSize);
59 uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
60 NaClBitstreamCursor *Cursor =
61 new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
62 NaClBitstreamCursor(Reader);
63 EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
64 }
65
66 TEST(NaClBitstreamTest, CursorAtReaderInitialAddress) {
67 static const size_t BufferSize = 12;
68 static const size_t InitialAddress = 8;
69 unsigned char Buffer[BufferSize];
70 NaClBitstreamReader Reader(Buffer, Buffer+BufferSize, InitialAddress);
71 uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
72 NaClBitstreamCursor *Cursor =
73 new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
74 NaClBitstreamCursor(Reader);
75 EXPECT_EQ(InitialAddress * CHAR_BIT, Cursor->GetCurrentBitNo());
76 }
77
78 } // end of anonymous namespace
OLDNEW
« no previous file with comments | « unittests/Bitcode/NaClBitReaderTest.cpp ('k') | unittests/Bitcode/NaClObjDumpTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698