#include "llvm/Remarks/Remark.h"
#include "llvm/Remarks/RemarkStringTable.h"
#include "gtest/gtest.h"
using namespace llvm;
TEST(RemarksAPI, Comparison) {
remarks::Remark R;
R.RemarkType = remarks::Type::Missed;
R.PassName = "pass";
R.RemarkName = "name";
R.FunctionName = "func";
R.Loc = remarks::RemarkLocation{"path", 3, 4};
R.Hotness = 5;
R.Args.emplace_back();
R.Args.back().Key = "key";
R.Args.back().Val = "value";
R.Args.emplace_back();
R.Args.back().Key = "keydebug";
R.Args.back().Val = "valuedebug";
R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
EXPECT_EQ(R, R);
remarks::Remark R2 = R.clone();
R2.FunctionName = "func0";
EXPECT_NE(R, R2);
remarks::Remark R3 = R.clone();
R3.Args.back().Val = "not";
EXPECT_NE(R, R3);
}
TEST(RemarksAPI, Clone) {
remarks::Remark R;
R.RemarkType = remarks::Type::Missed;
R.PassName = "pass";
R.RemarkName = "name";
R.FunctionName = "func";
R.Loc = remarks::RemarkLocation{"path", 3, 4};
R.Hotness = 5;
R.Args.emplace_back();
R.Args.back().Key = "key";
R.Args.back().Val = "value";
R.Args.emplace_back();
R.Args.back().Key = "keydebug";
R.Args.back().Val = "valuedebug";
R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
remarks::Remark R2 = R.clone();
EXPECT_EQ(R, R2);
}
TEST(RemarksAPI, ArgsAsMsg) {
remarks::Remark R;
R.RemarkType = remarks::Type::Missed;
R.Args.emplace_back();
R.Args.back().Key = "key";
R.Args.back().Val = "can not do this ";
R.Args.emplace_back();
R.Args.back().Key = "keydebug";
R.Args.back().Val = "because of that.";
R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
EXPECT_EQ(R.getArgsAsMsg(), "can not do this because of that.");
}
TEST(RemarksAPI, StringTableInternalize) {
remarks::StringTable StrTab;
EXPECT_EQ(StrTab.SerializedSize, 0UL);
remarks::Remark R;
R.RemarkType = remarks::Type::Missed;
R.PassName = "pass";
R.RemarkName = "name";
R.FunctionName = "func";
R.Loc = remarks::RemarkLocation{"path", 3, 4};
R.Args.emplace_back();
R.Args.back().Key = "keydebug";
R.Args.back().Val = "valuedebug";
R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
remarks::Remark R2 = R.clone();
StrTab.internalize(R2);
EXPECT_NE(R.PassName.data(), R2.PassName.data());
EXPECT_NE(R.RemarkName.data(), R2.RemarkName.data());
EXPECT_NE(R.FunctionName.data(), R2.FunctionName.data());
EXPECT_NE(R.Loc->SourceFilePath.data(), R2.Loc->SourceFilePath.data());
EXPECT_NE(R.Args.back().Key.data(), R2.Args.back().Key.data());
EXPECT_NE(R.Args.back().Val.data(), R2.Args.back().Val.data());
EXPECT_NE(R.Args.back().Loc->SourceFilePath.data(),
R2.Args.back().Loc->SourceFilePath.data());
EXPECT_EQ(StrTab.add(R.PassName).second.data(), R2.PassName.data());
EXPECT_EQ(StrTab.add(R.RemarkName).second.data(), R2.RemarkName.data());
EXPECT_EQ(StrTab.add(R.FunctionName).second.data(), R2.FunctionName.data());
EXPECT_EQ(StrTab.add(R.Loc->SourceFilePath).second.data(),
R2.Loc->SourceFilePath.data());
EXPECT_EQ(StrTab.add(R.Args.back().Key).second.data(),
R2.Args.back().Key.data());
EXPECT_EQ(StrTab.add(R.Args.back().Val).second.data(),
R2.Args.back().Val.data());
EXPECT_EQ(StrTab.add(R.Args.back().Loc->SourceFilePath).second.data(),
R2.Args.back().Loc->SourceFilePath.data());
}