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.

293 lines
6.9 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/component/test.component.inserters.pad/test.component.inserters.pad.cpp
  3. *
  4. * Purpose: Implementation file for the test.component.inserters.pad project.
  5. *
  6. * Created: 29th June 2009
  7. * Updated: 6th August 2012
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2009-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/pad.hpp> // for pantheios::pad
  25. #include <pantheios/backends/bec.test.h>
  26. /* Standard C++ Header Files */
  27. #include <exception>
  28. #include <string>
  29. /* Standard C Header Files */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  33. /* /////////////////////////////////////////////////////////////////////////
  34. * Forward declarations
  35. */
  36. namespace
  37. {
  38. static void test_1_01();
  39. static void test_1_02();
  40. static void test_1_03();
  41. static void test_1_04();
  42. static void test_1_05();
  43. static void test_1_06();
  44. static void test_1_07();
  45. static void test_1_08();
  46. static void test_1_09();
  47. static void test_1_10();
  48. static void test_1_11();
  49. static void test_1_12();
  50. static void test_1_13();
  51. } /* anonymous namespace */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Globals
  54. */
  55. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.inserters.pad");
  56. /* ////////////////////////////////////////////////////////////////////// */
  57. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  58. /* /////////////////////////////////////////////////////////////////////////
  59. * Character encoding
  60. */
  61. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  62. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_WIDE_STRING_EQUAL
  63. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  64. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_MULTIBYTE_STRING_EQUAL
  65. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  66. /* ////////////////////////////////////////////////////////////////////// */
  67. int main(int argc, char** argv)
  68. {
  69. int retCode = EXIT_SUCCESS;
  70. int verbosity = 2;
  71. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  72. if(XTESTS_START_RUNNER_WITH_FLAGS("test.component.inserters.pad", verbosity, XTESTS_NS_C_QUAL(xtestsReportOnlyNonEmptyCases)))
  73. {
  74. XTESTS_RUN_CASE(test_1_01);
  75. XTESTS_RUN_CASE(test_1_02);
  76. XTESTS_RUN_CASE(test_1_03);
  77. XTESTS_RUN_CASE(test_1_04);
  78. XTESTS_RUN_CASE(test_1_05);
  79. XTESTS_RUN_CASE(test_1_06);
  80. XTESTS_RUN_CASE(test_1_07);
  81. XTESTS_RUN_CASE(test_1_08);
  82. XTESTS_RUN_CASE(test_1_09);
  83. XTESTS_RUN_CASE(test_1_10);
  84. XTESTS_RUN_CASE(test_1_11);
  85. XTESTS_RUN_CASE(test_1_12);
  86. XTESTS_RUN_CASE(test_1_13);
  87. XTESTS_PRINT_RESULTS();
  88. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  89. }
  90. return retCode;
  91. }
  92. /* ////////////////////////////////////////////////////////////////////// */
  93. namespace
  94. {
  95. typedef std::basic_string<pantheios::pan_char_t> string_t;
  96. static void test_1_01()
  97. {
  98. { for(size_t i = 0; i != 1000; ++i)
  99. {
  100. // 1. Setup
  101. pantheios::be::test::reset();
  102. // 2. Create test data
  103. pantheios::log_NOTICE(pantheios::pad("", i));
  104. // 3. Verification
  105. pantheios::be::test::Results results = pantheios::be::test::results();
  106. XTESTS_TEST(!results.empty());
  107. XTESTS_TEST_INTEGER_EQUAL(1u, results.size());
  108. XTESTS_TEST_INTEGER_EQUAL(i, results[0].statement.size());
  109. XTESTS_TEST_STRING_EQUAL(string_t(i, ' '), results[0].statement);
  110. }}
  111. }
  112. static void test_1_02()
  113. {
  114. { for(size_t i = 0; i != 1000; ++i)
  115. {
  116. // 1. Setup
  117. pantheios::be::test::reset();
  118. // 2. Create test data
  119. pantheios::log_NOTICE(pantheios::pad(string_t(), i));
  120. // 3. Verification
  121. pantheios::be::test::Results results = pantheios::be::test::results();
  122. XTESTS_TEST(!results.empty());
  123. XTESTS_TEST_INTEGER_EQUAL(1u, results.size());
  124. XTESTS_TEST_INTEGER_EQUAL(i, results[0].statement.size());
  125. XTESTS_TEST_STRING_EQUAL(string_t(i, ' '), results[0].statement);
  126. }}
  127. }
  128. static void test_1_03()
  129. {
  130. { for(size_t i = 0; i != 1/* 000 */; ++i)
  131. {
  132. // 1. Setup
  133. pantheios::be::test::reset();
  134. // 2. Create test data
  135. pantheios::log_NOTICE(pantheios::pad(" ", i));
  136. // 3. Verification
  137. pantheios::be::test::Results results = pantheios::be::test::results();
  138. XTESTS_TEST(!results.empty());
  139. XTESTS_TEST_INTEGER_EQUAL(1u, results.size());
  140. if(i <= 1)
  141. {
  142. XTESTS_TEST_INTEGER_EQUAL(0u, results[0].statement.size());
  143. XTESTS_TEST_STRING_EQUAL(PSTR(""), results[0].statement);
  144. }
  145. else
  146. {
  147. XTESTS_TEST_INTEGER_EQUAL(i - 1u, results[0].statement.size());
  148. XTESTS_TEST_STRING_EQUAL(string_t(i - 1u, ' '), results[0].statement);
  149. }
  150. }}
  151. }
  152. static void test_1_04()
  153. {
  154. { for(size_t i = 0; i != 1000; ++i)
  155. {
  156. const string_t value(i, '~');
  157. STLSOFT_ASSERT(i == value.size());
  158. { for(size_t j = 0; j != 1000; ++j)
  159. {
  160. // 1. Setup
  161. pantheios::be::test::reset();
  162. // 2. Create test data
  163. pantheios::log_NOTICE(pantheios::pad(value, j), value);
  164. // 3. Verification
  165. pantheios::be::test::Results results = pantheios::be::test::results();
  166. XTESTS_TEST(!results.empty());
  167. XTESTS_TEST_INTEGER_EQUAL(1u, results.size());
  168. if(i < j)
  169. {
  170. /* Some padding */
  171. const string_t stmt = string_t(j - i, ' ') + value;
  172. XTESTS_TEST_INTEGER_EQUAL(stmt.size(), results[0].statement.size());
  173. XTESTS_TEST_STRING_EQUAL(stmt, results[0].statement);
  174. }
  175. else
  176. {
  177. /* No padding */
  178. XTESTS_TEST_INTEGER_EQUAL(value.size(), results[0].statement.size());
  179. XTESTS_TEST_STRING_EQUAL(value, results[0].statement);
  180. }
  181. }}
  182. }}
  183. }
  184. static void test_1_05()
  185. {
  186. }
  187. static void test_1_06()
  188. {
  189. }
  190. static void test_1_07()
  191. {
  192. }
  193. static void test_1_08()
  194. {
  195. }
  196. static void test_1_09()
  197. {
  198. }
  199. static void test_1_10()
  200. {
  201. }
  202. static void test_1_11()
  203. {
  204. }
  205. static void test_1_12()
  206. {
  207. }
  208. static void test_1_13()
  209. {
  210. }
  211. } /* anonymous namespace */
  212. /* ///////////////////////////// end of file //////////////////////////// */