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-01-02 16:23:51 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
tr_error* err = nullptr;
|
|
|
|
|
|
|
|
tr_error_prefix(&err, "error: ");
|
2022-03-21 20:22:50 +00:00
|
|
|
EXPECT_EQ(nullptr, err) << *err;
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2021-12-28 02:32:22 +00:00
|
|
|
tr_error_set(&err, 2, "oops"sv);
|
2020-08-11 18:11:55 +00:00
|
|
|
EXPECT_NE(nullptr, err);
|
|
|
|
EXPECT_EQ(2, err->code);
|
|
|
|
EXPECT_STREQ("oops", err->message);
|
|
|
|
|
|
|
|
tr_error_prefix(&err, "error: ");
|
|
|
|
EXPECT_NE(nullptr, err);
|
|
|
|
EXPECT_EQ(2, err->code);
|
|
|
|
EXPECT_STREQ("error: oops", err->message);
|
|
|
|
|
|
|
|
tr_error_free(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Error, propagate)
|
|
|
|
{
|
|
|
|
tr_error* err = nullptr;
|
|
|
|
tr_error* err2 = nullptr;
|
2021-12-16 02:09:46 +00:00
|
|
|
auto constexpr Code = int{ 1 };
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2021-12-28 02:32:22 +00:00
|
|
|
tr_error_set(&err, Code, "oops"sv);
|
2020-08-11 18:11:55 +00:00
|
|
|
EXPECT_NE(nullptr, err);
|
2021-12-16 02:09:46 +00:00
|
|
|
EXPECT_EQ(Code, err->code);
|
2020-08-11 18:11:55 +00:00
|
|
|
EXPECT_STREQ("oops", err->message);
|
|
|
|
|
|
|
|
tr_error_propagate(&err2, &err);
|
|
|
|
EXPECT_NE(nullptr, err2);
|
2021-12-16 02:09:46 +00:00
|
|
|
EXPECT_EQ(Code, err2->code);
|
2020-08-11 18:11:55 +00:00
|
|
|
EXPECT_STREQ("oops", err2->message);
|
2022-03-21 20:22:50 +00:00
|
|
|
EXPECT_EQ(nullptr, err) << *err;
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2021-12-16 02:09:46 +00:00
|
|
|
tr_error_clear(&err2);
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|