[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / unittests / Bitstream / BitstreamWriterTest.cpp
blob054948e7e8b63b3d0495b57b456b9cf188cae23f
1 //===- BitstreamWriterTest.cpp - Tests for BitstreamWriter ----------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Bitstream/BitstreamWriter.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace {
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);
29 W.emitBlob("str");
31 SmallString<64> Expected;
33 BitstreamWriter W(Expected);
34 W.EmitVBR(3, 6);
35 W.FlushToWord();
36 W.Emit('s', 8);
37 W.Emit('t', 8);
38 W.Emit('r', 8);
39 W.Emit(0, 8);
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);
58 } // end namespace