source: trunk/libtransmission/error-test.c

Last change on this file was 14657, checked in by mikedld, 5 years ago

Uncomment error prefixing tests

  • Property svn:keywords set to Date Rev Author Id
File size: 1.7 KB
Line 
1/*
2 * This file Copyright (C) 2013-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: error-test.c 14657 2016-01-03 21:03:54Z mikedld $
8 */
9
10#include "transmission.h"
11#include "error.h"
12
13#include "libtransmission-test.h"
14
15static int
16test_error_set (void)
17{
18  tr_error * err = NULL;
19
20  tr_error_prefix (&err, "error: ");
21  check (err == NULL);
22
23  tr_error_set (&err, 1, "error: %s (%d)", "oops", 2);
24  check (err != NULL);
25  check_int_eq (1, err->code);
26  check_streq ("error: oops (2)", err->message);
27  tr_error_clear (&err);
28  check (err == NULL);
29
30  tr_error_set_literal (&err, 2, "oops");
31  check (err != NULL);
32  check_int_eq (2, err->code);
33  check_streq ("oops", err->message);
34
35  tr_error_prefix (&err, "error: ");
36  check (err != NULL);
37  check_int_eq (2, err->code);
38  check_streq ("error: oops", err->message);
39
40  tr_error_free (err);
41
42  return 0;
43}
44
45static int
46test_error_propagate (void)
47{
48  tr_error * err = NULL;
49  tr_error * err2 = NULL;
50
51  tr_error_set_literal (&err, 1, "oops");
52  check (err != NULL);
53  check_int_eq (1, err->code);
54  check_streq ("oops", err->message);
55
56  tr_error_propagate (&err2, &err);
57  check (err2 != NULL);
58  check_int_eq (1, err2->code);
59  check_streq ("oops", err2->message);
60  check (err == NULL);
61
62  tr_error_propagate_prefixed (&err, &err2, "error: ");
63  check (err != NULL);
64  check_int_eq (1, err->code);
65  check_streq ("error: oops", err->message);
66  check (err2 == NULL);
67
68  tr_error_propagate (NULL, &err);
69  check (err == NULL);
70
71  tr_error_free (err2);
72
73  return 0;
74}
75
76int
77main (void)
78{
79  const testFunc tests[] = { test_error_set,
80                             test_error_propagate };
81
82  return runTests (tests, NUM_TESTS (tests));
83}
Note: See TracBrowser for help on using the repository browser.