2014-06-23 02:38:53 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int test_error_set(void)
|
2014-06-23 02:38:53 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error* err = NULL;
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_prefix(&err, "error: ");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, ==, NULL);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_set(&err, 1, "error: %s (%d)", "oops", 2);
|
|
|
|
check(err != NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err->code, ==, 1);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err->message, ==, "error: oops (2)");
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_clear(&err);
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, ==, NULL);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_set_literal(&err, 2, "oops");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, !=, NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err->code, ==, 2);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err->message, ==, "oops");
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_prefix(&err, "error: ");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, !=, NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err->code, ==, 2);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err->message, ==, "error: oops");
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_free(err);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return 0;
|
2014-06-23 02:38:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int test_error_propagate(void)
|
2014-06-23 02:38:53 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error* err = NULL;
|
|
|
|
tr_error* err2 = NULL;
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_set_literal(&err, 1, "oops");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, !=, NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err->code, ==, 1);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err->message, ==, "oops");
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_propagate(&err2, &err);
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err2, !=, NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err2->code, ==, 1);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err2->message, ==, "oops");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, ==, NULL);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_propagate_prefixed(&err, &err2, "error: ");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, !=, NULL);
|
2017-05-29 20:22:36 +00:00
|
|
|
check_int(err->code, ==, 1);
|
2017-05-29 19:48:02 +00:00
|
|
|
check_str(err->message, ==, "error: oops");
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err2, ==, NULL);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_propagate(NULL, &err);
|
2017-05-30 17:56:12 +00:00
|
|
|
check_ptr(err, ==, NULL);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_error_free(err2);
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return 0;
|
2014-06-23 02:38:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int main(void)
|
2014-06-23 02:38:53 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
testFunc const tests[] =
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
test_error_set,
|
|
|
|
test_error_propagate
|
|
|
|
};
|
2014-06-23 02:38:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return runTests(tests, NUM_TESTS(tests));
|
2014-06-23 02:38:53 +00:00
|
|
|
}
|