You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
8.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/unit/test.unit.bec.COMErrorObject/test.unit.bec.COMErrorObject.cpp
  3. *
  4. * Purpose: Implementation file for the test.unit.be.COMErrorObject project.
  5. *
  6. * Created: 1st January 2008
  7. * Updated: 22nd March 2010
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2008-2010, Synesis Software Pty Ltd.
  14. * All rights reserved.
  15. *
  16. * www: http://www.synesis.com.au/software
  17. *
  18. * ////////////////////////////////////////////////////////////////////// */
  19. #include <pantheios/util/test/compiler_warnings_suppression.first_include.h>
  20. /* Pantheios Header Files */
  21. #include <pantheios/backends/bec.COMErrorObject.h>
  22. #include <pantheios/init_codes.h>
  23. /* xTests Header Files */
  24. #include <xtests/xtests.h>
  25. /* STLSoft Header Files */
  26. #include <stlsoft/shims/access/string.hpp>
  27. #include <comstl/error/errorinfo_desc.hpp>
  28. #include <comstl/error/errorinfo_functions.h>
  29. #include <comstl/util/initialisers.hpp>
  30. /* Standard C++ Header Files */
  31. #include <exception> // for std::exception
  32. #include <new> // for std::bad_alloc
  33. /* Standard C Header Files */
  34. #include <stdio.h> // for fprintf()
  35. #include <stdlib.h> // for exit codes
  36. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  37. /* /////////////////////////////////////////////////////////////////////////
  38. * Macros
  39. */
  40. #define PANTHEIOS_SEV_LEVELS_EQUAL(x, y) XTESTS_TEST_INTEGER_EQUAL(static_cast<int>(x), static_cast<int>(y))
  41. /* /////////////////////////////////////////////////////////////////////////
  42. * Character encoding
  43. */
  44. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  45. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_WIDE_STRING_EQUAL
  46. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  47. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_MULTIBYTE_STRING_EQUAL
  48. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  49. /* /////////////////////////////////////////////////////////////////////////
  50. * Globals
  51. */
  52. PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.be.COMErrorObject");
  53. /* ////////////////////////////////////////////////////////////////////// */
  54. static int main_(int argc, char** argv)
  55. {
  56. int retCode = EXIT_SUCCESS;
  57. int verbosity = 2;
  58. static PAN_CHAR_T const* strings[] =
  59. {
  60. PANTHEIOS_LITERAL_STRING("abc")
  61. , PANTHEIOS_LITERAL_STRING("ABC")
  62. , PANTHEIOS_LITERAL_STRING("abcdefghijklmnopqrstuvwxyz")
  63. , PANTHEIOS_LITERAL_STRING("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  64. , PANTHEIOS_LITERAL_STRING("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
  65. };
  66. static int severities[] =
  67. {
  68. PANTHEIOS_SEV_DEBUG
  69. , PANTHEIOS_SEV_INFORMATIONAL
  70. , PANTHEIOS_SEV_NOTICE
  71. , PANTHEIOS_SEV_WARNING
  72. , PANTHEIOS_SEV_ERROR
  73. , PANTHEIOS_SEV_CRITICAL
  74. , PANTHEIOS_SEV_ALERT
  75. , PANTHEIOS_SEV_EMERGENCY
  76. };
  77. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  78. if(XTESTS_START_RUNNER("test.unit.be.COMErrorObject", verbosity))
  79. {
  80. /* Case 1 - verifying be.COMErrorObject, with flags 0 */
  81. if(!XTESTS_CASE_BEGIN("case-1", "verifying be.COMErrorObject, with flags 0"))
  82. {
  83. retCode = EXIT_FAILURE;
  84. }
  85. else
  86. {
  87. pan_be_COMErrorObject_init_t init;
  88. init.flags = 0
  89. // | PANTHEIOS_BE_INIT_F_NO_PROCESS_ID
  90. // | PANTHEIOS_BE_INIT_F_NO_THREAD_ID
  91. | PANTHEIOS_BE_INIT_F_NO_SEVERITY
  92. ;
  93. void* token;
  94. int res = pantheios_be_COMErrorObject_init(PANTHEIOS_FE_PROCESS_IDENTITY, PANTHEIOS_BEID_ALL, &init, NULL, &token);
  95. if(PANTHEIOS_INIT_RC_SUCCESS != res)
  96. {
  97. XTESTS_FAIL_WITH_QUALIFIER("failed to initialise bec.COMErrorObject", pantheios::getInitErrorString(res));
  98. }
  99. else
  100. {
  101. { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(severities); ++i)
  102. {
  103. { for(size_t j = 0; j != STLSOFT_NUM_ELEMENTS(strings); ++j)
  104. {
  105. const int severity = severities[i];
  106. pantheios_be_COMErrorObject_logEntry(NULL, token, severity, strings[j], stlsoft::c_str_len(strings[j]));
  107. if( PANTHEIOS_SEV_DEBUG == severity ||
  108. PANTHEIOS_SEV_INFORMATIONAL == severity)
  109. {
  110. ; // be.COMErrorObject does not write out debug-level or informational-level messages
  111. }
  112. else
  113. {
  114. comstl::errorinfo_desc ed;
  115. XTESTS_TEST_STRING_EQUAL(strings[j], ed);
  116. }
  117. }}
  118. }}
  119. pantheios_be_COMErrorObject_uninit(token);
  120. }
  121. XTESTS_CASE_END("");
  122. }
  123. /* Case 2 - verifying be.COMErrorObject, with PANTHEIOS_BE_COMERROROBJECT_F_DONT_OVERWRITE_EXISTING flag */
  124. if(!XTESTS_CASE_BEGIN("case-2", "verifying be.COMErrorObject, with PANTHEIOS_BE_COMERROROBJECT_F_DONT_OVERWRITE_EXISTING flag"))
  125. {
  126. retCode = EXIT_FAILURE;
  127. }
  128. else
  129. {
  130. pan_be_COMErrorObject_init_t init;
  131. init.flags = 0
  132. // | PANTHEIOS_BE_INIT_F_NO_PROCESS_ID
  133. // | PANTHEIOS_BE_INIT_F_NO_THREAD_ID
  134. | PANTHEIOS_BE_INIT_F_NO_SEVERITY
  135. | PANTHEIOS_BE_COMERROROBJECT_F_DONT_OVERWRITE_EXISTING
  136. ;
  137. void* token;
  138. int res = pantheios_be_COMErrorObject_init(PANTHEIOS_FE_PROCESS_IDENTITY, PANTHEIOS_BEID_ALL, &init, NULL, &token);
  139. if(PANTHEIOS_INIT_RC_SUCCESS != res)
  140. {
  141. XTESTS_FAIL_WITH_QUALIFIER("failed to initialise bec.COMErrorObject", pantheios::getInitErrorString(res));
  142. }
  143. else
  144. {
  145. { for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(severities); ++i)
  146. {
  147. { for(size_t j = 0; j != STLSOFT_NUM_ELEMENTS(strings); ++j)
  148. {
  149. const int severity = severities[i];
  150. comstl::set_error_info(L"the first string");
  151. pantheios_be_COMErrorObject_logEntry(NULL, token, severity, strings[j], stlsoft::c_str_len(strings[j]));
  152. if( PANTHEIOS_SEV_DEBUG == severity ||
  153. PANTHEIOS_SEV_INFORMATIONAL == severity)
  154. {
  155. ; // be.COMErrorObject does not write out debug-level or informational-level messages
  156. }
  157. else
  158. {
  159. comstl::errorinfo_desc ed;
  160. XTESTS_TEST_MULTIBYTE_STRING_EQUAL("the first string", ed);
  161. }
  162. }}
  163. }}
  164. pantheios_be_COMErrorObject_uninit(token);
  165. }
  166. XTESTS_CASE_END("");
  167. }
  168. XTESTS_PRINT_RESULTS();
  169. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  170. }
  171. return retCode;
  172. }
  173. int main(int argc, char** argv)
  174. {
  175. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  176. try
  177. {
  178. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  179. comstl::com_initialiser coinit;
  180. return main_(argc, argv);
  181. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  182. }
  183. catch(std::exception &x)
  184. {
  185. ::fprintf(stderr, "Unhandled error: %s\n", x.what());
  186. }
  187. catch(...)
  188. {
  189. ::fprintf(stderr, "Unhandled unknown error\n");
  190. }
  191. return EXIT_FAILURE;
  192. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  193. }
  194. /* ////////////////////////////////////////////////////////////////////// */