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.

419 lines
11 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/unit/test.unit.fe.N/test.unit.fe.N.c
  3. *
  4. * Purpose: Implementation file for the test.unit.fe.N project.
  5. *
  6. * Created: 24th August 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. /* /////////////////////////////////////////////////////////////////////////
  20. * Test component header file include(s)
  21. */
  22. #include <pantheios/frontends/fe.N.h>
  23. /* /////////////////////////////////////////////////////////////////////////
  24. * Includes
  25. */
  26. /* xTests Header Files */
  27. #include <xtests/xtests.h>
  28. /* STLSoft Header Files */
  29. #include <stlsoft/stlsoft.h>
  30. /* Standard C Header Files */
  31. #include <stdlib.h>
  32. #include <string.h>
  33. /* /////////////////////////////////////////////////////////////////////////
  34. * Forward declarations
  35. */
  36. static void test_empty_array_with_negative_default_ceiling(void);
  37. static void test_empty_array_with_EMERGENCY_default_ceiling(void);
  38. static void test_empty_array_with_ALERT_default_ceiling(void);
  39. static void test_array_with_one_specific_id(void);
  40. static void test_array_with_three_specific_ids(void);
  41. /* /////////////////////////////////////////////////////////////////////////
  42. * Main
  43. */
  44. int main(int argc, char **argv)
  45. {
  46. int retCode = EXIT_SUCCESS;
  47. int verbosity = 2;
  48. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  49. if(XTESTS_START_RUNNER("test.unit.fe.N", verbosity))
  50. {
  51. XTESTS_RUN_CASE(test_empty_array_with_negative_default_ceiling);
  52. XTESTS_RUN_CASE(test_empty_array_with_EMERGENCY_default_ceiling);
  53. XTESTS_RUN_CASE(test_empty_array_with_ALERT_default_ceiling);
  54. XTESTS_RUN_CASE(test_array_with_one_specific_id);
  55. XTESTS_RUN_CASE(test_array_with_three_specific_ids);
  56. XTESTS_PRINT_RESULTS();
  57. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  58. }
  59. return retCode;
  60. }
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Constants
  63. */
  64. static const int s_severityLevels[] =
  65. {
  66. PANTHEIOS_SEV_EMERGENCY
  67. , PANTHEIOS_SEV_ALERT
  68. , PANTHEIOS_SEV_CRITICAL
  69. , PANTHEIOS_SEV_ERROR
  70. , PANTHEIOS_SEV_WARNING
  71. , PANTHEIOS_SEV_NOTICE
  72. , PANTHEIOS_SEV_INFORMATIONAL
  73. , PANTHEIOS_SEV_DEBUG
  74. };
  75. #define s_defaultCeiling -1
  76. /* /////////////////////////////////////////////////////////////////////////
  77. * Globals
  78. */
  79. const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.unit.fe.N");
  80. const pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS_DEFAULT[10] =
  81. {
  82. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  83. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  84. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  85. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  86. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  87. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  88. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  89. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  90. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  91. PANTHEIOS_FE_N_TERMINATOR_ENTRY(s_defaultCeiling),
  92. };
  93. pan_fe_N_t PAN_FE_N_SEVERITY_CEILINGS[10];
  94. static void reinitialise_ceilings(void)
  95. {
  96. STLSOFT_STATIC_ASSERT(sizeof(PAN_FE_N_SEVERITY_CEILINGS_DEFAULT) == sizeof(PAN_FE_N_SEVERITY_CEILINGS));
  97. memcpy(&PAN_FE_N_SEVERITY_CEILINGS[0], &PAN_FE_N_SEVERITY_CEILINGS_DEFAULT[0], sizeof(PAN_FE_N_SEVERITY_CEILINGS_DEFAULT));
  98. }
  99. /* /////////////////////////////////////////////////////////////////////////
  100. * Test function implementations
  101. */
  102. static void test_empty_array_with_negative_default_ceiling()
  103. {
  104. static const int severityLevelResults[] =
  105. {
  106. 0
  107. , 0
  108. , 0
  109. , 0
  110. , 0
  111. , 0
  112. , 0
  113. , 0
  114. };
  115. void* token;
  116. int res;
  117. reinitialise_ceilings();
  118. res = pantheios_fe_init(NULL, &token);
  119. if(0 != res)
  120. {
  121. XTESTS_TEST_FAIL_WITH_QUALIFIER("failed to initialise front-end", pantheios_getInitCodeString(res));
  122. }
  123. else
  124. {
  125. { size_t i; for(i = 0; i != STLSOFT_NUM_ELEMENTS(s_severityLevels); ++i)
  126. {
  127. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], 0));
  128. }}
  129. pantheios_fe_uninit(token);
  130. }
  131. }
  132. static void test_empty_array_with_EMERGENCY_default_ceiling()
  133. {
  134. static const int severityLevelResults[] =
  135. {
  136. 1
  137. , 0
  138. , 0
  139. , 0
  140. , 0
  141. , 0
  142. , 0
  143. , 0
  144. };
  145. void* token;
  146. int res;
  147. reinitialise_ceilings();
  148. PAN_FE_N_SEVERITY_CEILINGS[0].severityCeiling = PANTHEIOS_SEV_EMERGENCY;
  149. res = pantheios_fe_init(NULL, &token);
  150. if(0 != res)
  151. {
  152. XTESTS_TEST_FAIL_WITH_QUALIFIER("failed to initialise front-end", pantheios_getInitCodeString(res));
  153. }
  154. else
  155. {
  156. { size_t i; for(i = 0; i != STLSOFT_NUM_ELEMENTS(s_severityLevels); ++i)
  157. {
  158. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], 0));
  159. }}
  160. pantheios_fe_uninit(token);
  161. }
  162. }
  163. static void test_empty_array_with_ALERT_default_ceiling()
  164. {
  165. static const int severityLevelResults[] =
  166. {
  167. 1
  168. , 1
  169. , 0
  170. , 0
  171. , 0
  172. , 0
  173. , 0
  174. , 0
  175. };
  176. void* token;
  177. int res;
  178. reinitialise_ceilings();
  179. PAN_FE_N_SEVERITY_CEILINGS[0].severityCeiling = PANTHEIOS_SEV_ALERT;
  180. res = pantheios_fe_init(NULL, &token);
  181. if(0 != res)
  182. {
  183. XTESTS_TEST_FAIL_WITH_QUALIFIER("failed to initialise front-end", pantheios_getInitCodeString(res));
  184. }
  185. else
  186. {
  187. { size_t i; for(i = 0; i != STLSOFT_NUM_ELEMENTS(s_severityLevels); ++i)
  188. {
  189. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], 0));
  190. }}
  191. pantheios_fe_uninit(token);
  192. }
  193. }
  194. static void test_array_with_one_specific_id()
  195. {
  196. #define BACKEND_0_ID 1001
  197. static const int severityLevelResults_for_0[] =
  198. {
  199. 1
  200. , 1
  201. , 1
  202. , 1
  203. , 1
  204. , 0
  205. , 0
  206. , 0
  207. };
  208. static const int severityLevelResults_for_N[] =
  209. {
  210. 1
  211. , 1
  212. , 1
  213. , 1
  214. , 0
  215. , 0
  216. , 0
  217. , 0
  218. };
  219. static const int severityLevelResults_for_all[] =
  220. {
  221. 1
  222. , 1
  223. , 1
  224. , 1
  225. , 1
  226. , 0
  227. , 0
  228. , 0
  229. };
  230. void* token;
  231. int res;
  232. reinitialise_ceilings();
  233. PAN_FE_N_SEVERITY_CEILINGS[0].backEndId = BACKEND_0_ID;
  234. PAN_FE_N_SEVERITY_CEILINGS[0].severityCeiling = PANTHEIOS_SEV_WARNING;
  235. PAN_FE_N_SEVERITY_CEILINGS[1].severityCeiling = PANTHEIOS_SEV_ERROR;
  236. res = pantheios_fe_init(NULL, &token);
  237. if(0 != res)
  238. {
  239. XTESTS_TEST_FAIL_WITH_QUALIFIER("failed to initialise front-end", pantheios_getInitCodeString(res));
  240. }
  241. else
  242. {
  243. { size_t i; for(i = 0; i != STLSOFT_NUM_ELEMENTS(s_severityLevels); ++i)
  244. {
  245. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_all[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], 0));
  246. { int id; for(id = 1; id != 1000000; ++id)
  247. {
  248. switch(id)
  249. {
  250. case BACKEND_0_ID:
  251. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_0[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  252. break;
  253. default:
  254. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_N[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  255. break;
  256. }
  257. }}
  258. }}
  259. pantheios_fe_uninit(token);
  260. }
  261. }
  262. static void test_array_with_three_specific_ids()
  263. {
  264. #define BACKEND_0_ID 1001
  265. #define BACKEND_1_ID 3
  266. #define BACKEND_2_ID 54321
  267. static const int severityLevelResults_for_0[] =
  268. {
  269. 1
  270. , 1
  271. , 1
  272. , 1
  273. , 1
  274. , 0
  275. , 0
  276. , 0
  277. };
  278. static const int severityLevelResults_for_1[] =
  279. {
  280. 1
  281. , 1
  282. , 1
  283. , 1
  284. , 1
  285. , 1
  286. , 1
  287. , 0
  288. };
  289. static const int severityLevelResults_for_2[] =
  290. {
  291. 1
  292. , 1
  293. , 1
  294. , 0
  295. , 0
  296. , 0
  297. , 0
  298. , 0
  299. };
  300. static const int severityLevelResults_for_N[] =
  301. {
  302. 1
  303. , 1
  304. , 1
  305. , 1
  306. , 0
  307. , 0
  308. , 0
  309. , 0
  310. };
  311. static const int severityLevelResults_for_all[] =
  312. {
  313. 1
  314. , 1
  315. , 1
  316. , 1
  317. , 1
  318. , 1
  319. , 1
  320. , 0
  321. };
  322. void* token;
  323. int res;
  324. reinitialise_ceilings();
  325. PAN_FE_N_SEVERITY_CEILINGS[0].backEndId = BACKEND_0_ID;
  326. PAN_FE_N_SEVERITY_CEILINGS[0].severityCeiling = PANTHEIOS_SEV_WARNING;
  327. PAN_FE_N_SEVERITY_CEILINGS[1].backEndId = BACKEND_1_ID;
  328. PAN_FE_N_SEVERITY_CEILINGS[1].severityCeiling = PANTHEIOS_SEV_INFORMATIONAL;
  329. PAN_FE_N_SEVERITY_CEILINGS[2].backEndId = BACKEND_2_ID;
  330. PAN_FE_N_SEVERITY_CEILINGS[2].severityCeiling = PANTHEIOS_SEV_CRITICAL;
  331. PAN_FE_N_SEVERITY_CEILINGS[3].severityCeiling = PANTHEIOS_SEV_ERROR;
  332. res = pantheios_fe_init(NULL, &token);
  333. if(0 != res)
  334. {
  335. XTESTS_TEST_FAIL_WITH_QUALIFIER("failed to initialise front-end", pantheios_getInitCodeString(res));
  336. }
  337. else
  338. {
  339. { size_t i; for(i = 0; i != STLSOFT_NUM_ELEMENTS(s_severityLevels); ++i)
  340. {
  341. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_all[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], 0));
  342. { int id; for(id = 1; id != 1000000; ++id)
  343. {
  344. switch(id)
  345. {
  346. case BACKEND_0_ID:
  347. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_0[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  348. break;
  349. case BACKEND_1_ID:
  350. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_1[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  351. break;
  352. case BACKEND_2_ID:
  353. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_2[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  354. break;
  355. default:
  356. XTESTS_TEST_INTEGER_EQUAL(severityLevelResults_for_N[i], pantheios_fe_isSeverityLogged(token, s_severityLevels[i], id));
  357. break;
  358. }
  359. }}
  360. }}
  361. pantheios_fe_uninit(token);
  362. }
  363. }
  364. /* ///////////////////////////// end of file //////////////////////////// */