1 /*
2  * error-code-test.c -- tests for error codes
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <apr_general.h>
27 
28 #include "svn_error.h"
29 
30 /* Duplicate of the same typedef in libsvn_subr/error.c */
31 typedef struct err_defn {
32   svn_errno_t errcode; /* 160004 */
33   const char *errname; /* SVN_ERR_FS_CORRUPT */
34   const char *errdesc; /* default message */
35 } err_defn;
36 
37 /* To understand what is going on here, read svn_error_codes.h. */
38 #define SVN_ERROR_BUILD_ARRAY
39 #include "svn_error_codes.h"
40 
41 #include "../svn_test.h"
42 
43 #define NUM_ERRORS (sizeof(error_table)/sizeof(error_table[0]))
44 
45 static svn_error_t *
check_error_codes_unique(apr_pool_t * pool)46 check_error_codes_unique(apr_pool_t *pool)
47 {
48   int i;
49   struct err_defn e = error_table[0];
50 
51   /* Ensure error codes are strictly monotonically increasing. */
52   for (i = 1; i < NUM_ERRORS; i++)
53     {
54       struct err_defn e2 = error_table[i];
55 
56       /* Don't fail the test if there is an odd number of errors.
57        * The error array's sentinel has an error code of zero. */
58       if (i == NUM_ERRORS - 1 && e2.errcode == 0)
59         break;
60 
61       /* SVN_ERR_WC_NOT_DIRECTORY is an alias for SVN_ERR_WC_NOT_WORKING_COPY
62        * and shares the same error code. */
63       if (e.errcode != SVN_ERR_WC_NOT_DIRECTORY &&
64           e.errcode >= e2.errcode)
65         return svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
66                                  "Error 0x%x (%s) is not < 0x%x (%s)\n",
67                                  e.errcode, e.errdesc, e2.errcode, e2.errdesc);
68       e = e2;
69     }
70 
71   return SVN_NO_ERROR;
72 }
73 
74 
75 /* The test table.  */
76 
77 static int max_threads = 1;
78 
79 static struct svn_test_descriptor_t test_funcs[] =
80   {
81     SVN_TEST_NULL,
82     SVN_TEST_PASS2(check_error_codes_unique,
83                    "check that error codes are unique"),
84     SVN_TEST_NULL
85   };
86 
87 SVN_TEST_MAIN
88