2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright (C) 2013-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <string_view>
|
|
|
|
|
2023-01-02 16:23:51 +00:00
|
|
|
#include <libtransmission/error.h>
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2022-03-21 20:22:50 +00:00
|
|
|
#include "test-fixtures.h"
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2021-12-28 02:32:22 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
TEST(Error, errorSet)
|
|
|
|
{
|
2023-11-04 16:39:41 +00:00
|
|
|
auto error = tr_error{};
|
|
|
|
|
|
|
|
EXPECT_FALSE(error) << error;
|
|
|
|
EXPECT_FALSE(error.has_value()) << error;
|
|
|
|
error.set(2, "oops"sv);
|
|
|
|
EXPECT_TRUE(error);
|
|
|
|
EXPECT_TRUE(error.has_value()) << error;
|
|
|
|
EXPECT_EQ(2, error.code());
|
|
|
|
EXPECT_EQ("oops"sv, error.message());
|
|
|
|
|
|
|
|
error.prefix_message("error: ");
|
|
|
|
EXPECT_TRUE(error);
|
|
|
|
EXPECT_TRUE(error.has_value()) << error;
|
|
|
|
EXPECT_EQ(2, error.code());
|
|
|
|
EXPECT_EQ("error: oops"sv, error.message());
|
|
|
|
|
|
|
|
error = {};
|
|
|
|
EXPECT_FALSE(error) << error;
|
|
|
|
EXPECT_FALSE(error.has_value()) << error;
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|