blob: 80cd45608590a9741a9f6469b5e691d598567b90 [file] [log] [blame]
Daniel Dunbara11af532009-06-24 01:03:06 +00001//===- AsmStreamerTest.cpp - Triple unit tests ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "gtest/gtest.h"
11#include "llvm/MC/MCContext.h"
12#include "llvm/MC/MCStreamer.h"
13#include "llvm/Support/raw_ostream.h"
14using namespace llvm;
15
16namespace {
17
18// Helper class.
19class StringAsmStreamer {
20 std::string Str;
21 raw_string_ostream OS;
22 MCContext Context;
23 MCStreamer *Streamer;
24
25public:
26 StringAsmStreamer() : OS(Str), Streamer(createAsmStreamer(Context, OS)) {}
27 ~StringAsmStreamer() {
28 delete Streamer;
29 }
30
31 MCContext &getContext() { return Context; }
32 MCStreamer &getStreamer() { return *Streamer; }
33
34 const std::string &getString() {
35 Streamer->Finish();
36 return Str;
37 }
38};
39
40TEST(AsmStreamer, EmptyOutput) {
41 StringAsmStreamer S;
42 EXPECT_EQ(S.getString(), "");
43}
44
45TEST(AsmStreamer, Sections) {
46 StringAsmStreamer S;
47 MCSection *Sec0 = S.getContext().GetSection("foo");
48 S.getStreamer().SwitchSection(Sec0);
49 EXPECT_EQ(S.getString(), ".section foo\n");
50}
51
52}