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.

483 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/component/test.component.trace.1/test.component.trace.1.cpp
  3. *
  4. * Purpose: Implementation file for the test.component.trace.1 project.
  5. *
  6. * Created: 25th November 2007
  7. * Updated: 6th August 2012
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2007-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>
  24. #include <pantheios/trace.h>
  25. #include <pantheios/backends/bec.test.h>
  26. #include <pantheios/frontends/stock.h>
  27. /* STLSoft Header Files */
  28. #include <stlsoft/conversion/integer_to_string.hpp>
  29. /* Standard C++ Header Files */
  30. #include <string>
  31. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  32. /* /////////////////////////////////////////////////////////////////////////
  33. * Macros
  34. */
  35. #define PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(s1, s2) XTESTS_TEST_MULTIBYTE_STRING_EQUAL((s1), (s2))
  36. /* ////////////////////////////////////////////////////////////////////// */
  37. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.trace.1");
  38. namespace
  39. {
  40. static const char THIS_FILE[] = __FILE__;
  41. inline std::string fileline_stmt_(char const* stmt, int line)
  42. {
  43. char sz[21];
  44. char const* num = stlsoft::integer_to_string(&sz[0], STLSOFT_NUM_ELEMENTS(sz), line);
  45. std::string s(THIS_FILE);
  46. s += '(';
  47. s += num;
  48. s += "): ";
  49. s += stmt;
  50. return s;
  51. }
  52. } // anonymous namespace
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Forward Declarations
  55. */
  56. static void test_01();
  57. static void test_02();
  58. static void test_03();
  59. static void test_04();
  60. static void test_05();
  61. static void test_06();
  62. static void test_07();
  63. static void test_08();
  64. static void test_09();
  65. static void test_10();
  66. static void test_11();
  67. static void test_12();
  68. static void test_13();
  69. static void test_14();
  70. static void test_15();
  71. static void test_16();
  72. static void test_17();
  73. static void test_18();
  74. static void test_19();
  75. static void test_20();
  76. static void test_21();
  77. static void test_22();
  78. static void test_23();
  79. static void test_24();
  80. static void test_25();
  81. static void test_26();
  82. static void test_27();
  83. static void test_28();
  84. static void test_29();
  85. /* ////////////////////////////////////////////////////////////////////// */
  86. int main(int argc, char** argv)
  87. {
  88. int retCode = EXIT_SUCCESS;
  89. int verbosity = 2;
  90. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  91. if(XTESTS_START_RUNNER("test.component.trace.1", verbosity))
  92. {
  93. XTESTS_RUN_CASE(test_01);
  94. XTESTS_RUN_CASE(test_02);
  95. XTESTS_RUN_CASE(test_03);
  96. XTESTS_RUN_CASE(test_04);
  97. XTESTS_RUN_CASE(test_05);
  98. XTESTS_RUN_CASE(test_06);
  99. XTESTS_RUN_CASE(test_07);
  100. XTESTS_RUN_CASE(test_08);
  101. XTESTS_RUN_CASE(test_09);
  102. XTESTS_RUN_CASE(test_10);
  103. XTESTS_RUN_CASE(test_11);
  104. XTESTS_RUN_CASE(test_12);
  105. XTESTS_RUN_CASE(test_13);
  106. XTESTS_RUN_CASE(test_14);
  107. XTESTS_RUN_CASE(test_15);
  108. XTESTS_RUN_CASE(test_16);
  109. XTESTS_RUN_CASE(test_17);
  110. XTESTS_RUN_CASE(test_18);
  111. XTESTS_RUN_CASE(test_19);
  112. XTESTS_RUN_CASE(test_20);
  113. XTESTS_RUN_CASE(test_21);
  114. XTESTS_RUN_CASE(test_22);
  115. XTESTS_RUN_CASE(test_23);
  116. XTESTS_RUN_CASE(test_24);
  117. XTESTS_RUN_CASE(test_25);
  118. XTESTS_RUN_CASE(test_26);
  119. XTESTS_RUN_CASE(test_27);
  120. XTESTS_RUN_CASE(test_28);
  121. XTESTS_RUN_CASE(test_29);
  122. XTESTS_PRINT_RESULTS();
  123. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  124. }
  125. else
  126. {
  127. retCode = EXIT_FAILURE;
  128. }
  129. return retCode;
  130. }
  131. /* ////////////////////////////////////////////////////////////////////// */
  132. static void test_01()
  133. {
  134. // 1. Setup
  135. pantheios::be::test::reset();
  136. // 2. Create test data
  137. // 3. Verification
  138. pantheios::be::test::Results results = pantheios::be::test::results();
  139. XTESTS_TEST(results.empty());
  140. XTESTS_TEST(0 == results.size());
  141. }
  142. static void test_02()
  143. {
  144. // 1. Setup
  145. pantheios::be::test::reset();
  146. // 2. Create test data
  147. PANTHEIOS_TRACE_NOTICE(""); int LINE = __LINE__;
  148. // 3. Verification
  149. pantheios::be::test::Results results = pantheios::be::test::results();
  150. XTESTS_TEST(!results.empty());
  151. XTESTS_TEST(1 == results.size());
  152. XTESTS_TEST(pantheios::notice == results[0].severity);
  153. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("", LINE), results[0].statement);
  154. }
  155. static void test_03()
  156. {
  157. // 1. Setup
  158. pantheios::be::test::reset();
  159. // 2. Create test data
  160. PANTHEIOS_TRACE_NOTICE("abc"); int LINE = __LINE__;
  161. // 3. Verification
  162. pantheios::be::test::Results results = pantheios::be::test::results();
  163. XTESTS_TEST(!results.empty());
  164. XTESTS_TEST(1 == results.size());
  165. XTESTS_TEST(pantheios::notice == results[0].severity);
  166. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abc", LINE), results[0].statement);
  167. }
  168. static void test_04()
  169. {
  170. // 1. Setup
  171. pantheios::be::test::reset();
  172. // 2. Create test data
  173. PANTHEIOS_TRACE_INFORMATIONAL("abc", "def"); int LINE = __LINE__;
  174. // 3. Verification
  175. pantheios::be::test::Results results = pantheios::be::test::results();
  176. XTESTS_TEST(1 == results.size());
  177. XTESTS_TEST(pantheios::informational == results[0].severity);
  178. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdef", LINE), results[0].statement);
  179. }
  180. static void test_05()
  181. {
  182. // 1. Setup
  183. pantheios::be::test::reset();
  184. // 2. Create test data
  185. PANTHEIOS_TRACE_INFORMATIONAL("abc", "def", "ghi"); int LINE = __LINE__;
  186. // 3. Verification
  187. pantheios::be::test::Results results = pantheios::be::test::results();
  188. XTESTS_TEST(1 == results.size());
  189. XTESTS_TEST(pantheios::informational == results[0].severity);
  190. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdefghi", LINE), results[0].statement);
  191. }
  192. static void test_06()
  193. {
  194. // 1. Setup
  195. pantheios::be::test::reset();
  196. // 2. Create test data
  197. PANTHEIOS_TRACE_INFORMATIONAL("abc", "def", "ghi", "jk", "lm", "no", "pq", "rs", "tu", "vw", "xy", "z"); int LINE = __LINE__;
  198. // 3. Verification
  199. pantheios::be::test::Results results = pantheios::be::test::results();
  200. XTESTS_TEST(1 == results.size());
  201. XTESTS_TEST(pantheios::informational == results[0].severity);
  202. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdefghijklmnopqrstuvwxyz", LINE), results[0].statement);
  203. }
  204. static void test_07()
  205. {
  206. // 1. Setup
  207. pantheios::be::test::reset();
  208. // 2. Create test data
  209. PANTHEIOS_TRACE_INFORMATIONAL("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); int LINE = __LINE__;
  210. // 3. Verification
  211. pantheios::be::test::Results results = pantheios::be::test::results();
  212. XTESTS_TEST(1 == results.size());
  213. XTESTS_TEST(pantheios::informational == results[0].severity);
  214. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdefghijklmnopqrstuvwxyz", LINE), results[0].statement);
  215. }
  216. static void test_08()
  217. {}
  218. static void test_09()
  219. {}
  220. static void test_10()
  221. {
  222. // 1. Setup
  223. pantheios::be::test::reset();
  224. // 2. Create test data
  225. PANTHEIOS_TRACE_INFORMATIONAL("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); int LINE1 = __LINE__;
  226. PANTHEIOS_TRACE_INFORMATIONAL("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); int LINE2 = __LINE__;
  227. // 3. Verification
  228. pantheios::be::test::Results results = pantheios::be::test::results();
  229. XTESTS_TEST(2 == results.size());
  230. XTESTS_TEST(pantheios::informational == results[0].severity);
  231. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdefghijklmnopqrstuvwxyz", LINE1), results[0].statement);
  232. XTESTS_TEST(pantheios::informational == results[1].severity);
  233. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("ABCDEFGHIJKLMNOPQRSTUVWXYZ", LINE2), results[1].statement);
  234. }
  235. static void test_11()
  236. {
  237. // 1. Setup
  238. pantheios::be::test::reset();
  239. // 2. Create test data
  240. const size_t numEntries = 1000;
  241. int LINE1 = -1;
  242. int LINE2 = -1;
  243. { for(size_t i = 0; i < numEntries; ++i)
  244. {
  245. if(0 == (i % 2))
  246. {
  247. PANTHEIOS_TRACE_INFORMATIONAL("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); LINE1 = __LINE__;
  248. }
  249. else
  250. {
  251. PANTHEIOS_TRACE_INFORMATIONAL("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); LINE2 = __LINE__;
  252. }
  253. }}
  254. // 3. Verification
  255. pantheios::be::test::Results results = pantheios::be::test::results();
  256. XTESTS_TEST(numEntries == results.size());
  257. { for(size_t i = 0; i < numEntries; ++i)
  258. {
  259. XTESTS_TEST(pantheios::informational == results[i].severity);
  260. if(0 == (i % 2))
  261. {
  262. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("abcdefghijklmnopqrstuvwxyz", LINE1), results[i].statement);
  263. }
  264. else
  265. {
  266. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_("ABCDEFGHIJKLMNOPQRSTUVWXYZ", LINE2), results[i].statement);
  267. }
  268. }}
  269. }
  270. static void test_12()
  271. {}
  272. static void test_13()
  273. {}
  274. static void test_14()
  275. {}
  276. static void test_15()
  277. {}
  278. static void test_16()
  279. {}
  280. static void test_17()
  281. {}
  282. static void test_18()
  283. {}
  284. static void test_19()
  285. {}
  286. static void test_20()
  287. {}
  288. static void test_21()
  289. {
  290. // 1. Setup
  291. pantheios::be::test::reset();
  292. // 2. Create test data
  293. std::string msgEl1(256, '~');
  294. std::string msgEl2(4096, '#');
  295. PANTHEIOS_TRACE_INFORMATIONAL(msgEl1, msgEl2); int LINE = __LINE__;
  296. // 3. Verification
  297. pantheios::be::test::Results results = pantheios::be::test::results();
  298. XTESTS_TEST(1 == results.size());
  299. XTESTS_TEST(pantheios::informational == results[0].severity);
  300. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_((msgEl1 + msgEl2).c_str(), LINE), results[0].statement);
  301. }
  302. static void test_22()
  303. {
  304. // 1. Setup
  305. pantheios::be::test::reset();
  306. // 2. Create test data
  307. std::string msgEl1(2560, '~');
  308. std::string msgEl2(40960, '#');
  309. PANTHEIOS_TRACE_INFORMATIONAL(msgEl1, msgEl2); int LINE = __LINE__;
  310. // 3. Verification
  311. pantheios::be::test::Results results = pantheios::be::test::results();
  312. XTESTS_TEST(1 == results.size());
  313. XTESTS_TEST(pantheios::informational == results[0].severity);
  314. PANTHEIOS_TEST_STRING_OBJECTS_EQUAL(fileline_stmt_((msgEl1 + msgEl2).c_str(), LINE), results[0].statement);
  315. }
  316. static void test_23()
  317. {}
  318. static void test_24()
  319. {}
  320. static void test_25()
  321. {}
  322. static void test_26()
  323. {}
  324. static void test_27()
  325. {}
  326. static void test_28()
  327. {}
  328. static void test_29()
  329. {}
  330. /* ///////////////////////////// end of file //////////////////////////// */