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.

494 lines
16 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/component/test.component.inserters.pointer/test.component.inserters.pointer.cpp
  3. *
  4. * Purpose: Implementation file for the test.component.inserters.pointer project.
  5. *
  6. * Created: 19th October 2006
  7. * Updated: 6th August 2012
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2006-2012, 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. /* xTests Header Files */
  21. #include <xtests/xtests.h>
  22. /* Pantheios Header Files */
  23. #include <pantheios/pantheios.hpp> // Pantheios C++ main header
  24. #include <pantheios/inserters/pointer.hpp> // for pantheios::pointer
  25. #include <pantheios/backends/bec.test.h>
  26. /* Standard C++ Header Files */
  27. #include <exception>
  28. /* Standard C Header Files */
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  32. /* /////////////////////////////////////////////////////////////////////////
  33. * Forward declarations
  34. */
  35. static void test_1_01();
  36. static void test_1_02();
  37. static void test_1_03();
  38. static void test_1_04();
  39. static void test_1_05();
  40. static void test_1_06();
  41. static void test_1_07();
  42. static void test_1_08();
  43. static void test_1_09();
  44. static void test_1_10();
  45. static void test_1_11();
  46. static void test_1_12();
  47. static void test_1_13();
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Globals
  50. */
  51. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.inserters.pointer");
  52. /* ////////////////////////////////////////////////////////////////////// */
  53. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Character encoding
  56. */
  57. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  58. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_WIDE_STRING_EQUAL
  59. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  60. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_MULTIBYTE_STRING_EQUAL
  61. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  62. /* ////////////////////////////////////////////////////////////////////// */
  63. int main(int argc, char** argv)
  64. {
  65. int retCode = EXIT_SUCCESS;
  66. int verbosity = 2;
  67. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  68. if(XTESTS_START_RUNNER("test.component.inserters.pointer", verbosity))
  69. {
  70. XTESTS_RUN_CASE(test_1_01);
  71. XTESTS_RUN_CASE(test_1_02);
  72. XTESTS_RUN_CASE(test_1_03);
  73. XTESTS_RUN_CASE(test_1_04);
  74. XTESTS_RUN_CASE(test_1_05);
  75. XTESTS_RUN_CASE(test_1_06);
  76. XTESTS_RUN_CASE(test_1_07);
  77. XTESTS_RUN_CASE(test_1_08);
  78. XTESTS_RUN_CASE(test_1_09);
  79. XTESTS_RUN_CASE(test_1_10);
  80. XTESTS_RUN_CASE(test_1_11);
  81. XTESTS_RUN_CASE(test_1_12);
  82. XTESTS_RUN_CASE(test_1_13);
  83. XTESTS_PRINT_RESULTS();
  84. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  85. }
  86. return retCode;
  87. }
  88. /* ////////////////////////////////////////////////////////////////////// */
  89. static void test_1_01()
  90. {
  91. // 1. Setup
  92. pantheios::be::test::reset();
  93. // 2. Create test data
  94. pantheios::log_NOTICE(pantheios::pointer(static_cast<void*>(0), 1));
  95. pantheios::log_NOTICE(pantheios::pointer(static_cast<void const*>(0), 1));
  96. pantheios::log_NOTICE(pantheios::pointer(static_cast<void volatile*>(0), 1));
  97. pantheios::log_NOTICE(pantheios::pointer(static_cast<void const volatile*>(0), 1));
  98. // 3. Verification
  99. pantheios::be::test::Results results = pantheios::be::test::results();
  100. XTESTS_TEST(!results.empty());
  101. XTESTS_TEST_INTEGER_EQUAL(4u, results.size());
  102. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[0].statement);
  103. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[1].statement);
  104. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[2].statement);
  105. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[3].statement);
  106. }
  107. static void test_1_02()
  108. {
  109. // 1. Setup
  110. pantheios::be::test::reset();
  111. // 2. Create test data
  112. pantheios::log_NOTICE(pantheios::pointer(static_cast<void*>(0), 4));
  113. pantheios::log_NOTICE(pantheios::pointer(static_cast<void*>(0), 8));
  114. // 3. Verification
  115. pantheios::be::test::Results results = pantheios::be::test::results();
  116. XTESTS_TEST(!results.empty());
  117. XTESTS_TEST_INTEGER_EQUAL(2u, results.size());
  118. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[0].statement);
  119. XTESTS_TEST_STRING_EQUAL(PSTR("(null)"), results[1].statement);
  120. }
  121. static void test_1_03()
  122. {
  123. // 1. Setup
  124. pantheios::be::test::reset();
  125. // 2. Create test data
  126. void* p1 = reinterpret_cast<void*>(0x1234);
  127. void* p2 = reinterpret_cast<void*>(0x12345678);
  128. pantheios::log_NOTICE(pantheios::pointer(p1, 4));
  129. pantheios::log_NOTICE(pantheios::pointer(p2, 8));
  130. pantheios::log_NOTICE(pantheios::pointer(p1, 8));
  131. // 3. Verification
  132. pantheios::be::test::Results results = pantheios::be::test::results();
  133. XTESTS_TEST(!results.empty());
  134. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  135. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  136. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[1].statement);
  137. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[2].statement);
  138. }
  139. static void test_1_04()
  140. {
  141. // 1. Setup
  142. pantheios::be::test::reset();
  143. // 2. Create test data
  144. void* p1 = reinterpret_cast<void*>(0x1234);
  145. void* p2 = reinterpret_cast<void*>(0x12345678);
  146. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::hex));
  147. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::hex));
  148. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::hex));
  149. // 3. Verification
  150. pantheios::be::test::Results results = pantheios::be::test::results();
  151. XTESTS_TEST(!results.empty());
  152. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  153. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  154. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[1].statement);
  155. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[2].statement);
  156. }
  157. static void test_1_05()
  158. {
  159. // 1. Setup
  160. pantheios::be::test::reset();
  161. // 2. Create test data
  162. void* p1 = reinterpret_cast<void*>(0x1234);
  163. void* p2 = reinterpret_cast<void*>(0x12345678);
  164. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::zeroXPrefix));
  165. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::zeroXPrefix));
  166. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::zeroXPrefix));
  167. // 3. Verification
  168. pantheios::be::test::Results results = pantheios::be::test::results();
  169. XTESTS_TEST(!results.empty());
  170. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  171. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234"), results[0].statement);
  172. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[1].statement);
  173. XTESTS_TEST_STRING_EQUAL(PSTR("0x00001234"), results[2].statement);
  174. }
  175. static void test_1_06()
  176. {
  177. // 1. Setup
  178. pantheios::be::test::reset();
  179. // 2. Create test data
  180. void* p1 = reinterpret_cast<void*>(0x1234);
  181. void* p2 = reinterpret_cast<void*>(0x12345678);
  182. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::zeroPad));
  183. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::zeroPad));
  184. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::zeroPad));
  185. // 3. Verification
  186. pantheios::be::test::Results results = pantheios::be::test::results();
  187. XTESTS_TEST(!results.empty());
  188. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  189. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  190. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[1].statement);
  191. XTESTS_TEST_STRING_EQUAL(PSTR("00001234"), results[2].statement);
  192. }
  193. static void test_1_07()
  194. {
  195. // 1. Setup
  196. pantheios::be::test::reset();
  197. // 2. Create test data
  198. void* p1 = reinterpret_cast<void*>(0x1234);
  199. void* p2 = reinterpret_cast<void*>(0x12345678);
  200. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::zeroPad | pantheios::fmt::zeroXPrefix));
  201. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::zeroPad | pantheios::fmt::zeroXPrefix));
  202. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::zeroPad | pantheios::fmt::zeroXPrefix));
  203. // 3. Verification
  204. pantheios::be::test::Results results = pantheios::be::test::results();
  205. XTESTS_TEST(!results.empty());
  206. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  207. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234"), results[0].statement);
  208. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[1].statement);
  209. XTESTS_TEST_STRING_EQUAL(PSTR("0x00001234"), results[2].statement);
  210. }
  211. static void test_1_08()
  212. {
  213. // 1. Setup
  214. pantheios::be::test::reset();
  215. // 2. Create test data
  216. void* p1 = reinterpret_cast<void*>(0x1234);
  217. void* p2 = reinterpret_cast<void*>(0x12345678);
  218. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::zeroXPrefix));
  219. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::zeroXPrefix));
  220. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::zeroXPrefix));
  221. // 3. Verification
  222. pantheios::be::test::Results results = pantheios::be::test::results();
  223. XTESTS_TEST(!results.empty());
  224. XTESTS_TEST_INTEGER_EQUAL(3u, results.size());
  225. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234"), results[0].statement);
  226. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[1].statement);
  227. XTESTS_TEST_STRING_EQUAL(PSTR("0x00001234"), results[2].statement);
  228. }
  229. static void test_1_09()
  230. {
  231. // 1. Setup
  232. pantheios::be::test::reset();
  233. // 2. Create test data
  234. void* p1 = reinterpret_cast<void*>(0x1234);
  235. void* p2 = reinterpret_cast<void*>(0x12345678);
  236. pantheios::log_NOTICE(pantheios::pointer(p1, 4 | pantheios::fmt::hex));
  237. pantheios::log_NOTICE(pantheios::pointer(p1, 8 | pantheios::fmt::hex));
  238. pantheios::log_NOTICE(pantheios::pointer(p1, 16 | pantheios::fmt::hex));
  239. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::hex));
  240. pantheios::log_NOTICE(pantheios::pointer(p2, 8 | pantheios::fmt::hex));
  241. pantheios::log_NOTICE(pantheios::pointer(p2, 16 | pantheios::fmt::hex));
  242. // 3. Verification
  243. pantheios::be::test::Results results = pantheios::be::test::results();
  244. XTESTS_TEST(!results.empty());
  245. XTESTS_TEST_INTEGER_EQUAL(6u, results.size());
  246. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  247. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[1].statement);
  248. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[2].statement);
  249. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[3].statement);
  250. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[4].statement);
  251. XTESTS_TEST_STRING_EQUAL(PSTR(" 12345678"), results[5].statement);
  252. }
  253. static void test_1_10()
  254. {
  255. // 1. Setup
  256. pantheios::be::test::reset();
  257. // 2. Create test data
  258. void* p1 = reinterpret_cast<void*>(0x1234);
  259. void* p2 = reinterpret_cast<void*>(0x12345678);
  260. pantheios::log_NOTICE(pantheios::pointer(p1, 4, pantheios::fmt::hex));
  261. pantheios::log_NOTICE(pantheios::pointer(p1, 8, pantheios::fmt::hex));
  262. pantheios::log_NOTICE(pantheios::pointer(p1, 16, pantheios::fmt::hex));
  263. pantheios::log_NOTICE(pantheios::pointer(p2, 8, pantheios::fmt::hex));
  264. pantheios::log_NOTICE(pantheios::pointer(p2, 8, pantheios::fmt::hex));
  265. pantheios::log_NOTICE(pantheios::pointer(p2, 16, pantheios::fmt::hex));
  266. // 3. Verification
  267. pantheios::be::test::Results results = pantheios::be::test::results();
  268. XTESTS_TEST(!results.empty());
  269. XTESTS_TEST_INTEGER_EQUAL(6u, results.size());
  270. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  271. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[1].statement);
  272. XTESTS_TEST_STRING_EQUAL(PSTR(" 1234"), results[2].statement);
  273. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[3].statement);
  274. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[4].statement);
  275. XTESTS_TEST_STRING_EQUAL(PSTR(" 12345678"), results[5].statement);
  276. }
  277. static void test_1_11()
  278. {
  279. // 1. Setup
  280. pantheios::be::test::reset();
  281. // 2. Create test data
  282. void* p1 = reinterpret_cast<void*>(0x1234);
  283. void* p2 = reinterpret_cast<void*>(0x12345678);
  284. pantheios::log_NOTICE(pantheios::pointer(p1, -4, pantheios::fmt::hex));
  285. pantheios::log_NOTICE(pantheios::pointer(p1, -8, pantheios::fmt::hex));
  286. pantheios::log_NOTICE(pantheios::pointer(p1, -16, pantheios::fmt::hex));
  287. pantheios::log_NOTICE(pantheios::pointer(p2, -8, pantheios::fmt::hex));
  288. pantheios::log_NOTICE(pantheios::pointer(p2, -8, pantheios::fmt::hex));
  289. pantheios::log_NOTICE(pantheios::pointer(p2, -16, pantheios::fmt::hex));
  290. // 3. Verification
  291. pantheios::be::test::Results results = pantheios::be::test::results();
  292. XTESTS_TEST(!results.empty());
  293. XTESTS_TEST_INTEGER_EQUAL(6u, results.size());
  294. XTESTS_TEST_STRING_EQUAL(PSTR("1234"), results[0].statement);
  295. XTESTS_TEST_STRING_EQUAL(PSTR("1234 "), results[1].statement);
  296. XTESTS_TEST_STRING_EQUAL(PSTR("1234 "), results[2].statement);
  297. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[3].statement);
  298. XTESTS_TEST_STRING_EQUAL(PSTR("12345678"), results[4].statement);
  299. XTESTS_TEST_STRING_EQUAL(PSTR("12345678 "), results[5].statement);
  300. }
  301. static void test_1_12()
  302. {
  303. // 1. Setup
  304. pantheios::be::test::reset();
  305. // 2. Create test data
  306. void* p1 = reinterpret_cast<void*>(0x1234);
  307. void* p2 = reinterpret_cast<void*>(0x12345678);
  308. pantheios::log_NOTICE(pantheios::pointer(p1, 4, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  309. pantheios::log_NOTICE(pantheios::pointer(p1, 8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  310. pantheios::log_NOTICE(pantheios::pointer(p1, 16, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  311. pantheios::log_NOTICE(pantheios::pointer(p2, 8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  312. pantheios::log_NOTICE(pantheios::pointer(p2, 8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  313. pantheios::log_NOTICE(pantheios::pointer(p2, 16, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  314. // 3. Verification
  315. pantheios::be::test::Results results = pantheios::be::test::results();
  316. XTESTS_TEST(!results.empty());
  317. XTESTS_TEST_INTEGER_EQUAL(6u, results.size());
  318. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234"), results[0].statement);
  319. XTESTS_TEST_STRING_EQUAL(PSTR(" 0x1234"), results[1].statement);
  320. XTESTS_TEST_STRING_EQUAL(PSTR(" 0x1234"), results[2].statement);
  321. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[3].statement);
  322. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[4].statement);
  323. XTESTS_TEST_STRING_EQUAL(PSTR(" 0x12345678"), results[5].statement);
  324. }
  325. static void test_1_13()
  326. {
  327. // 1. Setup
  328. pantheios::be::test::reset();
  329. // 2. Create test data
  330. void* p1 = reinterpret_cast<void*>(0x1234);
  331. void* p2 = reinterpret_cast<void*>(0x12345678);
  332. pantheios::log_NOTICE(pantheios::pointer(p1, -4, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  333. pantheios::log_NOTICE(pantheios::pointer(p1, -8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  334. pantheios::log_NOTICE(pantheios::pointer(p1, -16, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  335. pantheios::log_NOTICE(pantheios::pointer(p2, -8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  336. pantheios::log_NOTICE(pantheios::pointer(p2, -8, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  337. pantheios::log_NOTICE(pantheios::pointer(p2, -16, pantheios::fmt::hex | pantheios::fmt::zeroXPrefix));
  338. // 3. Verification
  339. pantheios::be::test::Results results = pantheios::be::test::results();
  340. XTESTS_TEST(!results.empty());
  341. XTESTS_TEST_INTEGER_EQUAL(6u, results.size());
  342. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234"), results[0].statement);
  343. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234 "), results[1].statement);
  344. XTESTS_TEST_STRING_EQUAL(PSTR("0x1234 "), results[2].statement);
  345. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[3].statement);
  346. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678"), results[4].statement);
  347. XTESTS_TEST_STRING_EQUAL(PSTR("0x12345678 "), results[5].statement);
  348. }
  349. /* ///////////////////////////// end of file //////////////////////////// */