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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « unittests/Bitcode/NaClBitReaderTest.cpp ('k') | unittests/Bitcode/NaClObjDumpTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: unittests/Bitcode/NaClBitstreamReaderTest.cpp
diff --git a/unittests/Bitcode/NaClBitstreamReaderTest.cpp b/unittests/Bitcode/NaClBitstreamReaderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a2a275a57dd785f88b5869a906f465d9ac7f7461
--- /dev/null
+++ b/unittests/Bitcode/NaClBitstreamReaderTest.cpp
@@ -0,0 +1,78 @@
+//===- llvm/unittest/Bitcode/NaClBitstreamReaderTest.cpp ------------------===//
+// Tests issues in NaCl Bitstream Reader.
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Tests issues in NaCl Bitstream Reader.
+
+// TODO(kschimpf) Add more Tests.
+
+#include "llvm/Bitcode/NaCl/NaClBitstreamReader.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+static const uint64_t BitZero = 0;
+
+// Initializes array to sequence of alternating zeros/ones.
+void* InitAltOnes(uint8_t *Array, size_t ArraySize) {
+ for (size_t i = 0; i <ArraySize; ++i) {
+ Array[i] = 0x9;
+ }
+ return Array;
+}
+
+// Tests that the default bitstream cursor is at bit zero.
+TEST(NaClBitstreamTest, DefaultCursorAtBitZero) {
+ uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
+ NaClBitstreamCursor *Cursor =
+ new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
+ NaClBitstreamCursor();
+ EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
+}
+
+// Tests that when we initialize the bitstream cursor with a default bitstream
+// reader, the cursor is at bit zero.
+TEST(NaClBitstreamTest, CursorOnDefaultReaderAtBitZero) {
+ NaClBitstreamReader Reader;
+ uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
+ NaClBitstreamCursor *Cursor =
+ new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
+ NaClBitstreamCursor(Reader);
+ EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
+}
+
+// Tests that when we initialize the bitstream cursor with an array-filled
+// bitstream reader, the cursor is at bit zero.
+TEST(NaClBitstreamTest, ReaderCursorAtBitZero) {
+ static const size_t BufferSize = 12;
+ unsigned char Buffer[BufferSize];
+ NaClBitstreamReader Reader(Buffer, Buffer+BufferSize);
+ uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
+ NaClBitstreamCursor *Cursor =
+ new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
+ NaClBitstreamCursor(Reader);
+ EXPECT_EQ(BitZero, Cursor->GetCurrentBitNo());
+}
+
+TEST(NaClBitstreamTest, CursorAtReaderInitialAddress) {
+ static const size_t BufferSize = 12;
+ static const size_t InitialAddress = 8;
+ unsigned char Buffer[BufferSize];
+ NaClBitstreamReader Reader(Buffer, Buffer+BufferSize, InitialAddress);
+ uint8_t CursorMemory[sizeof(NaClBitstreamCursor)];
+ NaClBitstreamCursor *Cursor =
+ new (InitAltOnes(CursorMemory, sizeof(NaClBitstreamCursor)))
+ NaClBitstreamCursor(Reader);
+ EXPECT_EQ(InitialAddress * CHAR_BIT, Cursor->GetCurrentBitNo());
+}
+
+} // end of anonymous namespace
« 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