aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/MC/AsmStreamerTest.cpp
blob: 80cd45608590a9741a9f6469b5e691d598567b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//===- AsmStreamerTest.cpp - Triple unit tests ----------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;

namespace {

// Helper class.
class StringAsmStreamer {
  std::string Str;
  raw_string_ostream OS;
  MCContext Context;
  MCStreamer *Streamer;

public:
  StringAsmStreamer() : OS(Str), Streamer(createAsmStreamer(Context, OS)) {}
  ~StringAsmStreamer() { 
    delete Streamer;
  }

  MCContext &getContext() { return Context; }
  MCStreamer &getStreamer() { return *Streamer; }

  const std::string &getString() {
    Streamer->Finish();
    return Str;
  }
};

TEST(AsmStreamer, EmptyOutput) {
  StringAsmStreamer S;
  EXPECT_EQ(S.getString(), "");
}

TEST(AsmStreamer, Sections) {
  StringAsmStreamer S;
  MCSection *Sec0 = S.getContext().GetSection("foo");
  S.getStreamer().SwitchSection(Sec0);
  EXPECT_EQ(S.getString(), ".section foo\n");
}

}