brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · bf53ec1 Raw
55 lines · c
1//===- SimplePackedSerializationTestUtils.h -------------------------------===//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#ifndef ORC_RT_UNITTEST_SIMPLEPACKEDSERIALIZATIONTESTUTILS_H10#define ORC_RT_UNITTEST_SIMPLEPACKEDSERIALIZATIONTESTUTILS_H11 12#include "orc-rt/SimplePackedSerialization.h"13#include "orc-rt/WrapperFunction.h"14#include "gtest/gtest.h"15 16#include <optional>17 18template <typename SPSTraitsT, typename... ArgTs>19static inline std::optional<orc_rt::WrapperFunctionBuffer>20spsSerialize(const ArgTs &...Args) {21  auto B = orc_rt::WrapperFunctionBuffer::allocate(SPSTraitsT::size(Args...));22  orc_rt::SPSOutputBuffer OB(B.data(), B.size());23  if (!SPSTraitsT::serialize(OB, Args...))24    return std::nullopt;25  return B;26}27 28template <typename SPSTraitsT, typename... ArgTs>29static bool spsDeserialize(orc_rt::WrapperFunctionBuffer &B, ArgTs &...Args) {30  orc_rt::SPSInputBuffer IB(B.data(), B.size());31  return SPSTraitsT::deserialize(IB, Args...);32}33 34template <typename SPSTagT, typename T, typename Comparator = std::equal_to<T>>35static inline void blobSerializationRoundTrip(const T &Value,36                                              Comparator &&C = Comparator()) {37  using BST = orc_rt::SPSSerializationTraits<SPSTagT, T>;38 39  size_t Size = BST::size(Value);40  auto Buffer = std::make_unique<char[]>(Size);41  orc_rt::SPSOutputBuffer OB(Buffer.get(), Size);42 43  EXPECT_TRUE(BST::serialize(OB, Value));44 45  orc_rt::SPSInputBuffer IB(Buffer.get(), Size);46 47  T DSValue;48  EXPECT_TRUE(BST::deserialize(IB, DSValue));49 50  EXPECT_TRUE(C(Value, DSValue))51      << "Incorrect value after serialization/deserialization round-trip";52}53 54#endif // ORC_RT_UNITTEST_SIMPLEPACKEDSERIALIZATIONTESTUTILS_H55