1 //===- BitstreamWriterTest.cpp - Tests for BitstreamWriter ----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Bitstream/BitstreamWriter.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "gtest/gtest.h"
18 TEST(BitstreamWriterTest
, emitBlob
) {
19 SmallString
<64> Buffer
;
20 BitstreamWriter
W(Buffer
);
21 W
.emitBlob("str", /* ShouldEmitSize */ false);
22 EXPECT_EQ(StringRef("str\0", 4), Buffer
);
25 TEST(BitstreamWriterTest
, emitBlobWithSize
) {
26 SmallString
<64> Buffer
;
28 BitstreamWriter
W(Buffer
);
31 SmallString
<64> Expected
;
33 BitstreamWriter
W(Expected
);
41 EXPECT_EQ(Expected
.str(), Buffer
);
44 TEST(BitstreamWriterTest
, emitBlobEmpty
) {
45 SmallString
<64> Buffer
;
46 BitstreamWriter
W(Buffer
);
47 W
.emitBlob("", /* ShouldEmitSize */ false);
48 EXPECT_EQ(StringRef(""), Buffer
);
51 TEST(BitstreamWriterTest
, emitBlob4ByteAligned
) {
52 SmallString
<64> Buffer
;
53 BitstreamWriter
W(Buffer
);
54 W
.emitBlob("str0", /* ShouldEmitSize */ false);
55 EXPECT_EQ(StringRef("str0"), Buffer
);