70 lines · cpp
1//===- CallableTraitsHelperTest.cpp ---------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Tests for orc-rt's CallableTraitsHelper.h APIs.10//11// NOTE: All tests in this file are testing compile-time functionality, so the12// tests at runtime all end up being noops. That's fine -- those are13// cheap.14//===----------------------------------------------------------------------===//15 16#include "orc-rt/CallableTraitsHelper.h"17#include "gtest/gtest.h"18 19using namespace orc_rt;20 21static void freeVoidVoid() {}22 23TEST(CallableTraitsHelperTest, FreeVoidVoid) {24 (void)freeVoidVoid;25 typedef CallableArgInfo<decltype(freeVoidVoid)> CAI;26 static_assert(std::is_void_v<CAI::return_type>);27 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<>>);28}29 30static int freeBinaryOp(int, float) { return 0; }31 32TEST(CallableTraitsHelperTest, FreeBinaryOp) {33 (void)freeBinaryOp;34 typedef CallableArgInfo<decltype(freeBinaryOp)> CAI;35 static_assert(std::is_same_v<CAI::return_type, int>);36 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<int, float>>);37}38 39TEST(CallableTraitsHelperTest, VoidVoidObj) {40 auto VoidVoid = []() {};41 typedef CallableArgInfo<decltype(VoidVoid)> CAI;42 static_assert(std::is_void_v<CAI::return_type>);43 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<>>);44}45 46TEST(CallableTraitsHelperTest, BinaryOpObj) {47 auto BinaryOp = [](int X, float Y) -> int { return X + Y; };48 typedef CallableArgInfo<decltype(BinaryOp)> CAI;49 static_assert(std::is_same_v<CAI::return_type, int>);50 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<int, float>>);51}52 53TEST(CallableTraitsHelperTest, PreservesLValueRef) {54 auto RefOp = [](int &) {};55 typedef CallableArgInfo<decltype(RefOp)> CAI;56 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<int &>>);57}58 59TEST(CallableTraitsHelperTest, PreservesLValueRefConstness) {60 auto RefOp = [](const int &) {};61 typedef CallableArgInfo<decltype(RefOp)> CAI;62 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<const int &>>);63}64 65TEST(CallableTraitsHelperTest, PreservesRValueRef) {66 auto RefOp = [](int &&) {};67 typedef CallableArgInfo<decltype(RefOp)> CAI;68 static_assert(std::is_same_v<CAI::args_tuple_type, std::tuple<int &&>>);69}70