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.

312 lines
13 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/unit/test.unit.be.N/test.unit.be.N.c
  3. *
  4. * Purpose: Implementation file for the test.unit.be.N project.
  5. *
  6. * Created: 29th 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/backends/be.N.h>
  20. #include <pantheios/init_codes.h>
  21. #include <xtests/xtests.h>
  22. #include <stlsoft/stlsoft.h> /* for STLSOFT_NUM_ELEMENTS */
  23. #include <stdio.h> /* for fprintf() */
  24. #include <stdlib.h> /* for EXIT_SUCCESS, EXIT_FAILURE */
  25. const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.be.N");
  26. #define DECLARE_BACK_END_IMPL_N(n) \
  27. \
  28. PANTHEIOS_CALL(int) pantheios_be_N_test_ ## n ## _init( \
  29. PAN_CHAR_T const* processIdentity \
  30. , int backEndId \
  31. , void const* init \
  32. , void* reserved \
  33. , void** ptoken \
  34. ); \
  35. PANTHEIOS_CALL(void) pantheios_be_N_test_ ## n ## _uninit(void* token); \
  36. PANTHEIOS_CALL(int) pantheios_be_N_test_ ## n ## _logEntry( \
  37. void* beToken \
  38. , void* feToken \
  39. , int severity \
  40. , PAN_CHAR_T const* entry \
  41. , size_t cchEntry \
  42. ); \
  43. \
  44. PANTHEIOS_CALL(int) pantheios_be_N_test_ ## n ## _init( \
  45. PAN_CHAR_T const* processIdentity \
  46. , int backEndId \
  47. , void const* init \
  48. , void* reserved \
  49. , void** ptoken \
  50. ) \
  51. { \
  52. STLSOFT_SUPPRESS_UNUSED(processIdentity); \
  53. STLSOFT_SUPPRESS_UNUSED(backEndId); \
  54. STLSOFT_SUPPRESS_UNUSED(init); \
  55. STLSOFT_SUPPRESS_UNUSED(reserved); \
  56. STLSOFT_SUPPRESS_UNUSED(ptoken); \
  57. \
  58. if(s_retVals[n] >= 0) \
  59. { \
  60. ++s_initCounts[n]; \
  61. } \
  62. \
  63. return s_retVals[n]; \
  64. } \
  65. \
  66. PANTHEIOS_CALL(void) pantheios_be_N_test_ ## n ## _uninit(void* token) \
  67. { \
  68. STLSOFT_SUPPRESS_UNUSED(token); \
  69. \
  70. --s_initCounts[n]; \
  71. } \
  72. \
  73. PANTHEIOS_CALL(int) pantheios_be_N_test_ ## n ## _logEntry( \
  74. void* beToken \
  75. , void* feToken \
  76. , int severity \
  77. , PAN_CHAR_T const* entry \
  78. , size_t cchEntry \
  79. ) \
  80. { \
  81. STLSOFT_SUPPRESS_UNUSED(beToken); \
  82. STLSOFT_SUPPRESS_UNUSED(feToken); \
  83. STLSOFT_SUPPRESS_UNUSED(severity); \
  84. STLSOFT_SUPPRESS_UNUSED(entry); \
  85. STLSOFT_SUPPRESS_UNUSED(cchEntry); \
  86. \
  87. return 0; \
  88. }
  89. #define NUM_BACKENDS (5)
  90. static int s_retVals[1 + NUM_BACKENDS]; /* 0th element is not used. */
  91. static int s_initCounts[1 + NUM_BACKENDS]; /* 0th element is not used. */
  92. static int s_flags[1 + NUM_BACKENDS] =
  93. {
  94. -1, /* 0th element is not used. */
  95. 0,
  96. PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE,
  97. 0,
  98. 0,
  99. PANTHEIOS_BE_N_F_INIT_ONLY_IF_PREVIOUS_FAILED
  100. };
  101. DECLARE_BACK_END_IMPL_N(1)
  102. DECLARE_BACK_END_IMPL_N(2)
  103. DECLARE_BACK_END_IMPL_N(3)
  104. DECLARE_BACK_END_IMPL_N(4)
  105. DECLARE_BACK_END_IMPL_N(5)
  106. pan_be_N_t PAN_BE_N_BACKEND_LIST[] =
  107. {
  108. /* NOTE: The flags in this one are ignored, as they're set up every time
  109. * by the reset_state_() function (below) and the test setup code.
  110. */
  111. PANTHEIOS_BE_N_STDFORM_ENTRY(1, pantheios_be_N_test_1, 0),
  112. PANTHEIOS_BE_N_STDFORM_ENTRY(2, pantheios_be_N_test_2, 0),
  113. PANTHEIOS_BE_N_STDFORM_ENTRY(3, pantheios_be_N_test_3, 0),
  114. PANTHEIOS_BE_N_STDFORM_ENTRY(4, pantheios_be_N_test_4, 0),
  115. PANTHEIOS_BE_N_STDFORM_ENTRY(5, pantheios_be_N_test_5, 0),
  116. PANTHEIOS_BE_N_TERMINATOR_ENTRY
  117. };
  118. static void reset_state_(void)
  119. {
  120. int i;
  121. for(i = 0; i != NUM_BACKENDS; ++i)
  122. {
  123. PAN_BE_N_BACKEND_LIST[i].flags = s_flags[1 + i]; /* Replace the desired flags */
  124. s_retVals[i] = 0; /* Mark to pass */
  125. s_initCounts[0] = 0; /* Reset init ref count */
  126. }
  127. }
  128. /* ////////////////////////////////////////////////////////////////////// */
  129. int main(int argc, char** argv)
  130. {
  131. int retCode = EXIT_SUCCESS;
  132. int verbosity = 2;
  133. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  134. STLSOFT_STATIC_ASSERT(NUM_BACKENDS + 1 == STLSOFT_NUM_ELEMENTS(s_retVals));
  135. STLSOFT_STATIC_ASSERT(NUM_BACKENDS + 1 == STLSOFT_NUM_ELEMENTS(s_initCounts));
  136. STLSOFT_STATIC_ASSERT(NUM_BACKENDS + 1 == STLSOFT_NUM_ELEMENTS(s_flags));
  137. if(XTESTS_START_RUNNER("test.unit.be.N", verbosity))
  138. {
  139. /* Test-1 */
  140. if(XTESTS_CASE_BEGIN("Test-1", "Verify that all five succeed"))
  141. {
  142. void* token;
  143. int res;
  144. reset_state_();
  145. res = pantheios_be_init(PANTHEIOS_FE_PROCESS_IDENTITY, NULL, &token);
  146. XTESTS_TEST_INTEGER_EQUAL(PANTHEIOS_INIT_RC_SUCCESS, res);
  147. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[1]);
  148. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[2]);
  149. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[3]);
  150. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[4]);
  151. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[5]);
  152. pantheios_be_uninit(token);
  153. XTESTS_CASE_END("Test-1");
  154. }
  155. /* Test-2 */
  156. if(XTESTS_CASE_BEGIN("Test-2", "Verify that #1 failure causes all to fail"))
  157. {
  158. void* token;
  159. int res;
  160. reset_state_();
  161. s_retVals[1] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  162. res = pantheios_be_init(PANTHEIOS_FE_PROCESS_IDENTITY, NULL, &token);
  163. XTESTS_TEST_INTEGER_EQUAL(PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE, res);
  164. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[1]);
  165. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[2]);
  166. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[3]);
  167. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[4]);
  168. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[5]);
  169. /* pantheios_be_uninit(token); */
  170. XTESTS_CASE_END("Test-2");
  171. }
  172. /* Test-3 */
  173. if(XTESTS_CASE_BEGIN("Test-3", "Verify that #2 failure is benign"))
  174. {
  175. void* token;
  176. int res;
  177. reset_state_();
  178. s_retVals[2] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  179. res = pantheios_be_init(PANTHEIOS_FE_PROCESS_IDENTITY, NULL, &token);
  180. XTESTS_TEST_INTEGER_EQUAL(PANTHEIOS_INIT_RC_SUCCESS, res);
  181. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[1]);
  182. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[2]);
  183. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[3]);
  184. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[4]);
  185. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[5]);
  186. pantheios_be_uninit(token);
  187. XTESTS_CASE_END("Test-3");
  188. }
  189. /* Test-4 */
  190. if(XTESTS_CASE_BEGIN("Test-4", "Verify that failure of 4 out of five, where all ignore init-failure, does not cause failure"))
  191. {
  192. void* token;
  193. int res;
  194. reset_state_();
  195. PAN_BE_N_BACKEND_LIST[0].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  196. PAN_BE_N_BACKEND_LIST[1].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  197. PAN_BE_N_BACKEND_LIST[2].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  198. PAN_BE_N_BACKEND_LIST[3].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  199. PAN_BE_N_BACKEND_LIST[4].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  200. s_retVals[1] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  201. s_retVals[2] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  202. s_retVals[3] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  203. s_retVals[4] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  204. s_retVals[5] = 0;
  205. res = pantheios_be_init(PANTHEIOS_FE_PROCESS_IDENTITY, NULL, &token);
  206. XTESTS_TEST_INTEGER_EQUAL(PANTHEIOS_INIT_RC_SUCCESS, res);
  207. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[1]);
  208. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[2]);
  209. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[3]);
  210. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[4]);
  211. XTESTS_TEST_INTEGER_EQUAL(1, s_initCounts[5]);
  212. pantheios_be_uninit(token);
  213. XTESTS_CASE_END("Test-4");
  214. }
  215. /* Test-5 */
  216. if(XTESTS_CASE_BEGIN("Test-5", "Verify that failure of 5 out of five, where all ignore init-failure, does cause failure"))
  217. {
  218. void* token;
  219. int res;
  220. reset_state_();
  221. PAN_BE_N_BACKEND_LIST[0].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  222. PAN_BE_N_BACKEND_LIST[1].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  223. PAN_BE_N_BACKEND_LIST[2].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  224. PAN_BE_N_BACKEND_LIST[3].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  225. PAN_BE_N_BACKEND_LIST[4].flags = PANTHEIOS_BE_N_F_IGNORE_INIT_FAILURE;
  226. s_retVals[1] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  227. s_retVals[2] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  228. s_retVals[3] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  229. s_retVals[4] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  230. s_retVals[5] = PANTHEIOS_FE_INIT_RC_INTENDED_FAILURE;
  231. res = pantheios_be_init(PANTHEIOS_FE_PROCESS_IDENTITY, NULL, &token);
  232. XTESTS_TEST_INTEGER_EQUAL(PANTHEIOS_BE_INIT_RC_ALL_BACKEND_INITS_FAILED, res);
  233. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[1]);
  234. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[2]);
  235. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[3]);
  236. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[4]);
  237. XTESTS_TEST_INTEGER_EQUAL(0, s_initCounts[5]);
  238. /* pantheios_be_uninit(token); */
  239. XTESTS_CASE_END("Test-5");
  240. }
  241. XTESTS_PRINT_RESULTS();
  242. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  243. }
  244. return retCode;
  245. }
  246. /* ///////////////////////////// end of file //////////////////////////// */