memgraph/tests/unit/test_utils.hpp

26 lines
949 B
C++
Raw Normal View History

2021-09-09 16:44:47 +08:00
#pragma once
#include <memory>
2021-09-09 16:44:47 +08:00
#include <fmt/format.h>
#include <gtest/gtest.h>
#include "mg_procedure.h"
#include "query/procedure/mg_procedure_impl.hpp"
namespace test_utils {
using MgpValueOwningPtr = std::unique_ptr<mgp_value, void (*)(mgp_value *)>;
MgpValueOwningPtr CreateValueOwningPtr(mgp_value *value) { return MgpValueOwningPtr(value, &mgp_value_destroy); }
2021-09-09 16:44:47 +08:00
template <typename TResult, typename TFunc, typename... TArgs>
TResult ExpectNoError(const char *file, int line, TFunc func, TArgs &&...args) {
static_assert(std::is_trivially_copyable_v<TFunc>);
static_assert((std::is_trivially_copyable_v<std::remove_reference_t<TArgs>> && ...));
TResult result{};
EXPECT_EQ(func(args..., &result), MGP_ERROR_NO_ERROR) << fmt::format("Source of error: {} at line {}", file, line);
return result;
}
} // namespace test_utils
2021-09-09 16:44:47 +08:00
#define EXPECT_MGP_NO_ERROR(type, ...) test_utils::ExpectNoError<type>(__FILE__, __LINE__, __VA_ARGS__)