errset.c 7.0 KB

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