1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-04 05:56:02 +00:00
transmission/libtransmission/error-test.c
Mike Gelfand dadffa2c0f Align type qualifiers to the right (code style)
This way all the qualifiers (`const`, `volatile`, `mutable`) are grouped
together, e.g. `T const* const x` vs. `const T* const x`. Also helps reading
types right-to-left, e.g. "constant pointer to constant T" vs. "constant
pointer to T which is constant".
2017-04-20 19:53:20 +03:00

82 lines
1.7 KiB
C

/*
* This file Copyright (C) 2013-2014 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include "transmission.h"
#include "error.h"
#include "libtransmission-test.h"
static int test_error_set(void)
{
tr_error* err = NULL;
tr_error_prefix(&err, "error: ");
check(err == NULL);
tr_error_set(&err, 1, "error: %s (%d)", "oops", 2);
check(err != NULL);
check_int_eq(1, err->code);
check_streq("error: oops (2)", err->message);
tr_error_clear(&err);
check(err == NULL);
tr_error_set_literal(&err, 2, "oops");
check(err != NULL);
check_int_eq(2, err->code);
check_streq("oops", err->message);
tr_error_prefix(&err, "error: ");
check(err != NULL);
check_int_eq(2, err->code);
check_streq("error: oops", err->message);
tr_error_free(err);
return 0;
}
static int test_error_propagate(void)
{
tr_error* err = NULL;
tr_error* err2 = NULL;
tr_error_set_literal(&err, 1, "oops");
check(err != NULL);
check_int_eq(1, err->code);
check_streq("oops", err->message);
tr_error_propagate(&err2, &err);
check(err2 != NULL);
check_int_eq(1, err2->code);
check_streq("oops", err2->message);
check(err == NULL);
tr_error_propagate_prefixed(&err, &err2, "error: ");
check(err != NULL);
check_int_eq(1, err->code);
check_streq("error: oops", err->message);
check(err2 == NULL);
tr_error_propagate(NULL, &err);
check(err == NULL);
tr_error_free(err2);
return 0;
}
int main(void)
{
testFunc const tests[] =
{
test_error_set,
test_error_propagate
};
return runTests(tests, NUM_TESTS(tests));
}