#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
#include "OrcTestCommon.h"
using namespace llvm;
using namespace llvm::orc;
namespace {
TEST(ExecutorAddrTest, DefaultAndNull) {
ExecutorAddr Default;
ExecutorAddr Null(0);
ExecutorAddr NonNull(1);
EXPECT_TRUE(Null.isNull());
EXPECT_EQ(Default, Null);
EXPECT_FALSE(NonNull.isNull());
EXPECT_NE(Default, NonNull);
}
TEST(ExecutorAddrTest, Ordering) {
ExecutorAddr A1(1), A2(2);
EXPECT_LE(A1, A1);
EXPECT_LT(A1, A2);
EXPECT_GT(A2, A1);
EXPECT_GE(A2, A2);
}
TEST(ExecutorAddrTest, PtrConversion) {
int X = 0;
auto XAddr = ExecutorAddr::fromPtr(&X);
int *XPtr = XAddr.toPtr<int *>();
EXPECT_EQ(XPtr, &X);
}
static void F() {}
TEST(ExecutorAddrTest, PtrConversionWithFunctionType) {
auto FAddr = ExecutorAddr::fromPtr(F);
void (*FPtr)() = FAddr.toPtr<void()>();
EXPECT_EQ(FPtr, &F);
}
TEST(ExecutorAddrTest, AddrRanges) {
ExecutorAddr A0(0), A1(1), A2(2), A3(3);
ExecutorAddrRange R0(A0, A1), R1(A1, A2), R2(A2, A3), R3(A0, A2), R4(A1, A3);
EXPECT_EQ(R1, ExecutorAddrRange(A1, A2));
EXPECT_EQ(R1, ExecutorAddrRange(A1, ExecutorAddrDiff(1)));
EXPECT_NE(R1, R2);
EXPECT_TRUE(R1.contains(A1));
EXPECT_FALSE(R1.contains(A0));
EXPECT_FALSE(R1.contains(A2));
EXPECT_FALSE(R1.overlaps(R0));
EXPECT_FALSE(R1.overlaps(R2));
EXPECT_TRUE(R1.overlaps(R3));
EXPECT_TRUE(R1.overlaps(R4));
}
}