//===- llvm/unittest/XRay/FDRRecordPrinterTest.cpp --------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include "llvm/Support/raw_ostream.h" #include "llvm/XRay/FDRRecords.h" #include "llvm/XRay/RecordPrinter.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include namespace llvm { namespace xray { namespace { using ::testing::Eq; template struct Helper {}; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1, 2); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1, 2); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(4, 1, 2, "data"); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(1); } static const char *expected() { return ""; } }; template <> struct Helper { static std::unique_ptr construct() { return make_unique(); } static const char *expected() { return ""; } }; template class PrinterTest : public ::testing::Test { protected: std::string Data; raw_string_ostream OS; RecordPrinter P; std::unique_ptr R; public: PrinterTest() : Data(), OS(Data), P(OS), R(Helper::construct()) {} }; TYPED_TEST_CASE_P(PrinterTest); TYPED_TEST_P(PrinterTest, PrintsRecord) { ASSERT_NE(nullptr, this->R); ASSERT_FALSE(errorToBool(this->R->apply(this->P))); this->OS.flush(); EXPECT_THAT(this->Data, Eq(Helper::expected())); } REGISTER_TYPED_TEST_CASE_P(PrinterTest, PrintsRecord); using FDRRecordTypes = ::testing::Types; INSTANTIATE_TYPED_TEST_CASE_P(Records, PrinterTest, FDRRecordTypes); TEST(FDRRecordPrinterTest, WriteFunctionRecordEnter) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::ENTER, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordExit) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::EXIT, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordTailExit) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::TAIL_EXIT, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } TEST(FDRRecordPrinterTest, WriteFunctionRecordEnterArg) { std::string Data; raw_string_ostream OS(Data); RecordPrinter P(OS); FunctionRecord R(RecordTypes::ENTER_ARG, 1, 2); ASSERT_FALSE(errorToBool(R.apply(P))); OS.flush(); EXPECT_THAT(Data, Eq("")); } } // namespace } // namespace xray } // namespace llvm