File: error_test.c

package info (click to toggle)
globus-common 15.26-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,648 kB
  • ctags: 3,162
  • sloc: ansic: 36,114; sh: 11,654; makefile: 407; perl: 351; xml: 322
file content (152 lines) | stat: -rw-r--r-- 4,400 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright 1999-2006 University of Chicago
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file error_test.c
 * @brief Error Object Tests
 */

#include "globus_common.h"
#include "globus_test_tap.h"

#define MAX_ERROR_NUM 33

const globus_object_type_t *
switch_type(int class)
{
    const globus_object_type_t         *type;

#define num_type(n,t) case n: type = GLOBUS_ERROR_TYPE_ ## t; break;

    switch (class)
    {
        num_type(0, BASE);
        num_type(1, NO_AUTHENTICATION);
        num_type(2, NO_CREDENTIALS);
        num_type(3, NO_TRUST);
        num_type(4, INVALID_CREDENTIALS);
        num_type(5, ACCESS_FAILED);
        num_type(6, NO_AUTHORIZATION);
        num_type(7, NOT_AVAILABLE);
        num_type(8, DEPLETED);
        num_type(9, QUOTA_DEPLETED);
        num_type(10, OFFLINE);
        num_type(11, NAME_UNKNOWN);
        num_type(12, ABORTED);
        num_type(13, USER_CANCELLED);
        num_type(14, INTERNAL_ERROR);
        num_type(15, SYSTEM_ABORTED);
        num_type(16, BAD_DATA);
        num_type(17, NULL_REFERENCE);
        num_type(18, TYPE_MISMATCH);
        num_type(19, BAD_FORMAT);
        num_type(21, OUT_OF_RANGE);
        num_type(22, TOO_LARGE);
        num_type(23, TOO_SMALL);
        num_type(24, COMMUNICATION_FAILED);
        num_type(25, UNREACHABLE);
        num_type(26, PROTOCOL_MISMATCH);
        num_type(27, PROTOCOL_VIOLATED);
        num_type(28, INVALID_USE);
        num_type(29, ALREADY_DONE);
        num_type(30, ALREADY_REGISTERED);
        num_type(31, ALREADY_CANCELLED);
        num_type(32, NOT_INITIALIZED);

    default:
        type = GLOBUS_ERROR_TYPE_BASE;
        break;
    }

    return type;
}

globus_result_t
throw_error(int class)
{
    const globus_object_type_t         *type;
    globus_object_t                    *error;

    if (class == 0)
        return GLOBUS_SUCCESS;

    type = switch_type(class);
    error = globus_object_construct(type);

    return globus_error_put(error);
}




int
main()
{
    int                                 i;

    printf("1..231\n");
    globus_module_activate(GLOBUS_COMMON_MODULE);

    for (i = 0; i <= MAX_ERROR_NUM; i++)
    {
        globus_result_t                     result;

        result = throw_error(i);
    }

    for (i = 1; i <= MAX_ERROR_NUM; i++)
    {
        globus_result_t                     result;

        result = throw_error(i);

        ok(result != GLOBUS_SUCCESS, "create_error_%d", i);
        {
            char                               *errstring;
            globus_object_t                    *error,
                                               *error2;
            const globus_object_type_t         *type;
            int                                 j;

            error = globus_error_get(result);
            ok(error != NULL, "error_get_%d", i);
            errstring =globus_object_printable_to_string(error);
            ok(errstring != NULL, "error_printable_to_string_%d", i);
            printf("    %s\n", errstring);
            free(errstring);

            error2 = globus_object_upcast(error, GLOBUS_ERROR_TYPE_BASE);
            ok(error2 != NULL, "error_upcast_to_base_%d", i);
            errstring = globus_object_printable_to_string(error2);
            ok(errstring != NULL, "error_printable_to_string_%d_upcast", i);
            free(errstring);
            globus_object_free(error);
            error = NULL;

            error = globus_error_get(result);
            ok(error == GLOBUS_ERROR_NO_INFO, "error_get_after_get_%d", i);
            errstring = globus_object_printable_to_string(error);
            ok(errstring != NULL, "error_printable_to_string_%d_no_info", i);
            free(errstring);
            globus_object_free(error);
            error = NULL;
        }
    }

    globus_module_deactivate(GLOBUS_COMMON_MODULE);

    return TEST_EXIT_CODE;
}