Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /*********************************************************************** |
michael@0 | 7 | ** |
michael@0 | 8 | ** Name: errset.c |
michael@0 | 9 | ** |
michael@0 | 10 | ** Description: errset.c exercises the functions in prerror.c. |
michael@0 | 11 | ** This code is a unit test of the prerror.c capability. |
michael@0 | 12 | ** |
michael@0 | 13 | ** Note: There's some fluff in here. The guts of the test |
michael@0 | 14 | ** were plagerized from another test. So, sue me. |
michael@0 | 15 | ** |
michael@0 | 16 | ** |
michael@0 | 17 | */ |
michael@0 | 18 | #include "prerror.h" |
michael@0 | 19 | #include "plgetopt.h" |
michael@0 | 20 | #include "prlog.h" |
michael@0 | 21 | |
michael@0 | 22 | #include <stdio.h> |
michael@0 | 23 | #include <string.h> |
michael@0 | 24 | |
michael@0 | 25 | static int _debug_on = 0; |
michael@0 | 26 | |
michael@0 | 27 | struct errinfo { |
michael@0 | 28 | PRErrorCode errcode; |
michael@0 | 29 | char *errname; |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | struct errinfo errcodes[] = { |
michael@0 | 33 | {PR_OUT_OF_MEMORY_ERROR, "PR_OUT_OF_MEMORY_ERROR"}, |
michael@0 | 34 | {PR_UNKNOWN_ERROR, "An intentionally long error message text intended to force a delete of the current errorString buffer and get another one."}, |
michael@0 | 35 | {PR_BAD_DESCRIPTOR_ERROR, "PR_BAD_DESCRIPTOR_ERROR"}, |
michael@0 | 36 | {PR_WOULD_BLOCK_ERROR, "PR_WOULD_BLOCK_ERROR"}, |
michael@0 | 37 | {PR_ACCESS_FAULT_ERROR, "PR_ACCESS_FAULT_ERROR"}, |
michael@0 | 38 | {PR_INVALID_METHOD_ERROR, "PR_INVALID_METHOD_ERROR"}, |
michael@0 | 39 | {PR_ILLEGAL_ACCESS_ERROR, "PR_ILLEGAL_ACCESS_ERROR"}, |
michael@0 | 40 | {PR_UNKNOWN_ERROR, "PR_UNKNOWN_ERROR"}, |
michael@0 | 41 | {PR_PENDING_INTERRUPT_ERROR, "PR_PENDING_INTERRUPT_ERROR"}, |
michael@0 | 42 | {PR_NOT_IMPLEMENTED_ERROR, "PR_NOT_IMPLEMENTED_ERROR"}, |
michael@0 | 43 | {PR_IO_ERROR, "PR_IO_ERROR"}, |
michael@0 | 44 | {PR_IO_TIMEOUT_ERROR, "PR_IO_TIMEOUT_ERROR"}, |
michael@0 | 45 | {PR_IO_PENDING_ERROR, "PR_IO_PENDING_ERROR"}, |
michael@0 | 46 | {PR_DIRECTORY_OPEN_ERROR, "PR_DIRECTORY_OPEN_ERROR"}, |
michael@0 | 47 | {PR_INVALID_ARGUMENT_ERROR, "PR_INVALID_ARGUMENT_ERROR"}, |
michael@0 | 48 | {PR_ADDRESS_NOT_AVAILABLE_ERROR, "PR_ADDRESS_NOT_AVAILABLE_ERROR"}, |
michael@0 | 49 | {PR_ADDRESS_NOT_SUPPORTED_ERROR, "PR_ADDRESS_NOT_SUPPORTED_ERROR"}, |
michael@0 | 50 | {PR_IS_CONNECTED_ERROR, "PR_IS_CONNECTED_ERROR"}, |
michael@0 | 51 | {PR_BAD_ADDRESS_ERROR, "PR_BAD_ADDRESS_ERROR"}, |
michael@0 | 52 | {PR_ADDRESS_IN_USE_ERROR, "PR_ADDRESS_IN_USE_ERROR"}, |
michael@0 | 53 | {PR_CONNECT_REFUSED_ERROR, "PR_CONNECT_REFUSED_ERROR"}, |
michael@0 | 54 | {PR_NETWORK_UNREACHABLE_ERROR, "PR_NETWORK_UNREACHABLE_ERROR"}, |
michael@0 | 55 | {PR_CONNECT_TIMEOUT_ERROR, "PR_CONNECT_TIMEOUT_ERROR"}, |
michael@0 | 56 | {PR_NOT_CONNECTED_ERROR, "PR_NOT_CONNECTED_ERROR"}, |
michael@0 | 57 | {PR_LOAD_LIBRARY_ERROR, "PR_LOAD_LIBRARY_ERROR"}, |
michael@0 | 58 | {PR_UNLOAD_LIBRARY_ERROR, "PR_UNLOAD_LIBRARY_ERROR"}, |
michael@0 | 59 | {PR_FIND_SYMBOL_ERROR, "PR_FIND_SYMBOL_ERROR"}, |
michael@0 | 60 | {PR_INSUFFICIENT_RESOURCES_ERROR, "PR_INSUFFICIENT_RESOURCES_ERROR"}, |
michael@0 | 61 | {PR_DIRECTORY_LOOKUP_ERROR, "PR_DIRECTORY_LOOKUP_ERROR"}, |
michael@0 | 62 | {PR_TPD_RANGE_ERROR, "PR_TPD_RANGE_ERROR"}, |
michael@0 | 63 | {PR_PROC_DESC_TABLE_FULL_ERROR, "PR_PROC_DESC_TABLE_FULL_ERROR"}, |
michael@0 | 64 | {PR_SYS_DESC_TABLE_FULL_ERROR, "PR_SYS_DESC_TABLE_FULL_ERROR"}, |
michael@0 | 65 | {PR_NOT_SOCKET_ERROR, "PR_NOT_SOCKET_ERROR"}, |
michael@0 | 66 | {PR_NOT_TCP_SOCKET_ERROR, "PR_NOT_TCP_SOCKET_ERROR"}, |
michael@0 | 67 | {PR_SOCKET_ADDRESS_IS_BOUND_ERROR, "PR_SOCKET_ADDRESS_IS_BOUND_ERROR"}, |
michael@0 | 68 | {PR_NO_ACCESS_RIGHTS_ERROR, "PR_NO_ACCESS_RIGHTS_ERROR"}, |
michael@0 | 69 | {PR_OPERATION_NOT_SUPPORTED_ERROR, "PR_OPERATION_NOT_SUPPORTED_ERROR"}, |
michael@0 | 70 | {PR_PROTOCOL_NOT_SUPPORTED_ERROR, "PR_PROTOCOL_NOT_SUPPORTED_ERROR"}, |
michael@0 | 71 | {PR_REMOTE_FILE_ERROR, "PR_REMOTE_FILE_ERROR"}, |
michael@0 | 72 | {PR_BUFFER_OVERFLOW_ERROR, "PR_BUFFER_OVERFLOW_ERROR"}, |
michael@0 | 73 | {PR_CONNECT_RESET_ERROR, "PR_CONNECT_RESET_ERROR"}, |
michael@0 | 74 | {PR_RANGE_ERROR, "PR_RANGE_ERROR"}, |
michael@0 | 75 | {PR_DEADLOCK_ERROR, "PR_DEADLOCK_ERROR"}, |
michael@0 | 76 | {PR_FILE_IS_LOCKED_ERROR, "PR_FILE_IS_LOCKED_ERROR"}, |
michael@0 | 77 | {PR_FILE_TOO_BIG_ERROR, "PR_FILE_TOO_BIG_ERROR"}, |
michael@0 | 78 | {PR_NO_DEVICE_SPACE_ERROR, "PR_NO_DEVICE_SPACE_ERROR"}, |
michael@0 | 79 | {PR_PIPE_ERROR, "PR_PIPE_ERROR"}, |
michael@0 | 80 | {PR_NO_SEEK_DEVICE_ERROR, "PR_NO_SEEK_DEVICE_ERROR"}, |
michael@0 | 81 | {PR_IS_DIRECTORY_ERROR, "PR_IS_DIRECTORY_ERROR"}, |
michael@0 | 82 | {PR_LOOP_ERROR, "PR_LOOP_ERROR"}, |
michael@0 | 83 | {PR_NAME_TOO_LONG_ERROR, "PR_NAME_TOO_LONG_ERROR"}, |
michael@0 | 84 | {PR_FILE_NOT_FOUND_ERROR, "PR_FILE_NOT_FOUND_ERROR"}, |
michael@0 | 85 | {PR_NOT_DIRECTORY_ERROR, "PR_NOT_DIRECTORY_ERROR"}, |
michael@0 | 86 | {PR_READ_ONLY_FILESYSTEM_ERROR, "PR_READ_ONLY_FILESYSTEM_ERROR"}, |
michael@0 | 87 | {PR_DIRECTORY_NOT_EMPTY_ERROR, "PR_DIRECTORY_NOT_EMPTY_ERROR"}, |
michael@0 | 88 | {PR_FILESYSTEM_MOUNTED_ERROR, "PR_FILESYSTEM_MOUNTED_ERROR"}, |
michael@0 | 89 | {PR_NOT_SAME_DEVICE_ERROR, "PR_NOT_SAME_DEVICE_ERROR"}, |
michael@0 | 90 | {PR_DIRECTORY_CORRUPTED_ERROR, "PR_DIRECTORY_CORRUPTED_ERROR"}, |
michael@0 | 91 | {PR_FILE_EXISTS_ERROR, "PR_FILE_EXISTS_ERROR"}, |
michael@0 | 92 | {PR_MAX_DIRECTORY_ENTRIES_ERROR, "PR_MAX_DIRECTORY_ENTRIES_ERROR"}, |
michael@0 | 93 | {PR_INVALID_DEVICE_STATE_ERROR, "PR_INVALID_DEVICE_STATE_ERROR"}, |
michael@0 | 94 | {PR_DEVICE_IS_LOCKED_ERROR, "PR_DEVICE_IS_LOCKED_ERROR"}, |
michael@0 | 95 | {PR_NO_MORE_FILES_ERROR, "PR_NO_MORE_FILES_ERROR"}, |
michael@0 | 96 | {PR_END_OF_FILE_ERROR, "PR_END_OF_FILE_ERROR"}, |
michael@0 | 97 | {PR_FILE_SEEK_ERROR, "PR_FILE_SEEK_ERROR"}, |
michael@0 | 98 | {PR_FILE_IS_BUSY_ERROR, "PR_FILE_IS_BUSY_ERROR"}, |
michael@0 | 99 | {PR_IN_PROGRESS_ERROR, "PR_IN_PROGRESS_ERROR"}, |
michael@0 | 100 | {PR_ALREADY_INITIATED_ERROR, "PR_ALREADY_INITIATED_ERROR"}, |
michael@0 | 101 | {PR_GROUP_EMPTY_ERROR, "PR_GROUP_EMPTY_ERROR"}, |
michael@0 | 102 | {PR_INVALID_STATE_ERROR, "PR_INVALID_STATE_ERROR"}, |
michael@0 | 103 | {PR_NETWORK_DOWN_ERROR, "PR_NETWORK_DOWN_ERROR"}, |
michael@0 | 104 | {PR_SOCKET_SHUTDOWN_ERROR, "PR_SOCKET_SHUTDOWN_ERROR"}, |
michael@0 | 105 | {PR_CONNECT_ABORTED_ERROR, "PR_CONNECT_ABORTED_ERROR"}, |
michael@0 | 106 | {PR_HOST_UNREACHABLE_ERROR, "PR_HOST_UNREACHABLE_ERROR"} |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | int main(int argc, char **argv) |
michael@0 | 110 | { |
michael@0 | 111 | |
michael@0 | 112 | int count, errnum; |
michael@0 | 113 | |
michael@0 | 114 | /* |
michael@0 | 115 | * -d debug mode |
michael@0 | 116 | */ |
michael@0 | 117 | |
michael@0 | 118 | PLOptStatus os; |
michael@0 | 119 | PLOptState *opt = PL_CreateOptState(argc, argv, "d"); |
michael@0 | 120 | while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) |
michael@0 | 121 | { |
michael@0 | 122 | if (PL_OPT_BAD == os) continue; |
michael@0 | 123 | switch (opt->option) |
michael@0 | 124 | { |
michael@0 | 125 | case 'd': /* debug mode */ |
michael@0 | 126 | _debug_on = 1; |
michael@0 | 127 | break; |
michael@0 | 128 | default: |
michael@0 | 129 | break; |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | PL_DestroyOptState(opt); |
michael@0 | 133 | |
michael@0 | 134 | count = sizeof(errcodes)/sizeof(errcodes[0]); |
michael@0 | 135 | printf("\nNumber of error codes = %d\n\n",count); |
michael@0 | 136 | for (errnum = 0; errnum < count; errnum++) { |
michael@0 | 137 | PRInt32 len1, len2, err; |
michael@0 | 138 | char msg[256]; |
michael@0 | 139 | |
michael@0 | 140 | PR_SetError( errnum, -5 ); |
michael@0 | 141 | err = PR_GetError(); |
michael@0 | 142 | PR_ASSERT( err == errnum ); |
michael@0 | 143 | err = PR_GetOSError(); |
michael@0 | 144 | PR_ASSERT( err == -5 ); |
michael@0 | 145 | PR_SetErrorText( strlen(errcodes[errnum].errname), errcodes[errnum].errname ); |
michael@0 | 146 | len1 = PR_GetErrorTextLength(); |
michael@0 | 147 | len2 = PR_GetErrorText( msg ); |
michael@0 | 148 | PR_ASSERT( len1 == len2 ); |
michael@0 | 149 | printf("%5.5d -- %s\n", errnum, msg ); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | return 0; |
michael@0 | 153 | } |