Daniel Dunbar | a11af53 | 2009-06-24 01:03:06 +0000 | [diff] [blame] | 1 | //===- 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" |
| 14 | using namespace llvm; |
| 15 | |
| 16 | namespace { |
| 17 | |
| 18 | // Helper class. |
| 19 | class StringAsmStreamer { |
| 20 | std::string Str; |
| 21 | raw_string_ostream OS; |
| 22 | MCContext Context; |
| 23 | MCStreamer *Streamer; |
| 24 | |
| 25 | public: |
| 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 | |
| 40 | TEST(AsmStreamer, EmptyOutput) { |
| 41 | StringAsmStreamer S; |
| 42 | EXPECT_EQ(S.getString(), ""); |
| 43 | } |
| 44 | |
| 45 | TEST(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 | } |