2022-11-24 08:52:47 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2022-11-24 08:52:47 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "qtcassert.h"
|
|
|
|
|
|
|
|
|
|
#include "../3rdparty/tl_expected/include/tl/expected.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
2023-05-15 14:04:34 +02:00
|
|
|
using namespace tl;
|
2022-11-24 08:52:47 +01:00
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
using expected_str = tl::expected<T, QString>;
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|
|
|
|
|
|
|
|
|
|
//! If 'expected' has an error the error will be printed and the 'action' will be executed.
|
|
|
|
|
#define QTC_ASSERT_EXPECTED(expected, action) \
|
2023-01-10 08:01:50 +01:00
|
|
|
if (Q_LIKELY(expected)) { \
|
|
|
|
|
} else { \
|
|
|
|
|
::Utils::writeAssertLocation(QString("%1:%2: %3") \
|
|
|
|
|
.arg(__FILE__) \
|
|
|
|
|
.arg(__LINE__) \
|
|
|
|
|
.arg(expected.error()) \
|
|
|
|
|
.toUtf8() \
|
|
|
|
|
.data()); \
|
|
|
|
|
action; \
|
|
|
|
|
} \
|
|
|
|
|
do { \
|
|
|
|
|
} while (0)
|