llvm-project/orc-rt/unittests/WrapperFunctionResultTest.cpp
Lang Hames 3292edb7b4
[orc-rt] Add C and C++ APIs for WrapperFunctionResult. (#154927)
orc_rt_WrapperFunctionResult is a byte-buffer with inline storage and a
builtin error state. It is intended as a general purpose return type for
functions that return a serialized result (e.g. for communication across
ABIs or via IPC/RPC).

orc_rt_WrapperFunctionResult contains a small amount of inline storage,
allowing it to avoid heap-allocation for small return types (e.g. bools,
chars, pointers).
2025-08-22 21:18:30 +10:00

61 lines
2.1 KiB
C++

//===-- wrapper_function_utils_test.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of the ORC runtime.
//
//===----------------------------------------------------------------------===//
#include "orc-rt-c/WrapperFunctionResult.h"
#include "orc-rt/WrapperFunctionResult.h"
#include "gtest/gtest.h"
using namespace orc_rt;
namespace {
constexpr const char *TestString = "test string";
} // end anonymous namespace
TEST(WrapperFunctionUtilsTest, DefaultWrapperFunctionResult) {
WrapperFunctionResult R;
EXPECT_TRUE(R.empty());
EXPECT_EQ(R.size(), 0U);
EXPECT_EQ(R.getOutOfBandError(), nullptr);
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromCStruct) {
orc_rt_WrapperFunctionResult CR =
orc_rt_CreateWrapperFunctionResultFromString(TestString);
WrapperFunctionResult R(CR);
EXPECT_EQ(R.size(), strlen(TestString) + 1);
EXPECT_TRUE(strcmp(R.data(), TestString) == 0);
EXPECT_FALSE(R.empty());
EXPECT_EQ(R.getOutOfBandError(), nullptr);
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromRange) {
auto R = WrapperFunctionResult::copyFrom(TestString, strlen(TestString) + 1);
EXPECT_EQ(R.size(), strlen(TestString) + 1);
EXPECT_TRUE(strcmp(R.data(), TestString) == 0);
EXPECT_FALSE(R.empty());
EXPECT_EQ(R.getOutOfBandError(), nullptr);
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromCString) {
auto R = WrapperFunctionResult::copyFrom(TestString);
EXPECT_EQ(R.size(), strlen(TestString) + 1);
EXPECT_TRUE(strcmp(R.data(), TestString) == 0);
EXPECT_FALSE(R.empty());
EXPECT_EQ(R.getOutOfBandError(), nullptr);
}
TEST(WrapperFunctionUtilsTest, WrapperFunctionResultFromOutOfBandError) {
auto R = WrapperFunctionResult::createOutOfBandError(TestString);
EXPECT_FALSE(R.empty());
EXPECT_TRUE(strcmp(R.getOutOfBandError(), TestString) == 0);
}