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.

148 lines
4.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/component/test.component.inserters.processId/test.component.inserters.processId.cpp
  3. *
  4. * Purpose: Implementation file for the test.component.inserters.processId project.
  5. *
  6. * Created: 17th October 2006
  7. * Updated: 23rd March 2010
  8. *
  9. * Status: Wizard-generated
  10. *
  11. * License: (Licensed under the Synesis Software Open License)
  12. *
  13. * Copyright (c) 2006-2010, 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/ids.hpp> // for pantheios::processId
  25. #include <pantheios/backends/bec.test.h>
  26. /* STLSoft Header Files */
  27. #include <stlsoft/conversion/integer_to_string.hpp>
  28. #include <platformstl/platformstl.h>
  29. /* Standard C Header Files */
  30. #include <stdlib.h> // for exit codes
  31. #if defined(PLATFORMSTL_OS_IS_UNIX)
  32. # include <unistd.h>
  33. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  34. # include <windows.h>
  35. #else /* ? OS */
  36. # error Not discriminated for platforms other than UNIX and Windows
  37. #endif /* OS */
  38. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  39. /* /////////////////////////////////////////////////////////////////////////
  40. * Forward declarations
  41. */
  42. static void test_1_01();
  43. static int pan_get_pid_();
  44. /* ////////////////////////////////////////////////////////////////////// */
  45. /* Define the stock front-end process identity, so that it links when using
  46. * fe.N, fe.simple, etc. */
  47. PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.component.inserters.processId");
  48. /* ////////////////////////////////////////////////////////////////////// */
  49. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  50. /* /////////////////////////////////////////////////////////////////////////
  51. * Character encoding
  52. */
  53. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  54. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_WIDE_STRING_EQUAL
  55. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  56. # define XTESTS_TEST_STRING_EQUAL XTESTS_TEST_MULTIBYTE_STRING_EQUAL
  57. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  58. /* ////////////////////////////////////////////////////////////////////// */
  59. int main(int argc, char** argv)
  60. {
  61. int retCode = EXIT_SUCCESS;
  62. int verbosity = 2;
  63. XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, &verbosity);
  64. if(XTESTS_START_RUNNER("test.component.inserters.processId", verbosity))
  65. {
  66. XTESTS_RUN_CASE(test_1_01);
  67. XTESTS_PRINT_RESULTS();
  68. XTESTS_END_RUNNER_UPDATE_EXITCODE(&retCode);
  69. }
  70. return retCode;
  71. }
  72. /* ////////////////////////////////////////////////////////////////////// */
  73. static void test_1_01()
  74. {
  75. // 1. Setup
  76. const PAN_CHAR_T prefix[] = PSTR("process: ");
  77. PAN_CHAR_T pid_[21 + STLSOFT_NUM_ELEMENTS(prefix)];
  78. PAN_CHAR_T const* pid = stlsoft::integer_to_string(&pid_[0], STLSOFT_NUM_ELEMENTS(pid_), pan_get_pid_());
  79. PAN_CHAR_T const* stmt = pid - (STLSOFT_NUM_ELEMENTS(prefix) - 1);
  80. #ifdef PANTHEIOS_USE_WIDE_STRINGS
  81. ::wcsncpy(const_cast<PAN_CHAR_T*>(stmt), prefix, (STLSOFT_NUM_ELEMENTS(prefix) - 1));
  82. #else /* ? PANTHEIOS_USE_WIDE_STRINGS */
  83. ::strncpy(const_cast<PAN_CHAR_T*>(stmt), prefix, (STLSOFT_NUM_ELEMENTS(prefix) - 1));
  84. #endif /* PANTHEIOS_USE_WIDE_STRINGS */
  85. pantheios::be::test::reset();
  86. // 2. Create test data
  87. pantheios::log_NOTICE(pantheios::processId);
  88. pantheios::log_NOTICE(prefix, pantheios::processId);
  89. // 3. Verification
  90. pantheios::be::test::Results results = pantheios::be::test::results();
  91. XTESTS_TEST_BOOLEAN_FALSE(results.empty());
  92. XTESTS_REQUIRE(XTESTS_TEST_INTEGER_EQUAL(2u, results.size()));
  93. XTESTS_TEST_STRING_EQUAL(pid, results[0].statement);
  94. XTESTS_TEST_STRING_EQUAL(stmt, results[1].statement);
  95. }
  96. static int pan_get_pid_()
  97. {
  98. #if defined(PLATFORMSTL_OS_IS_UNIX)
  99. return static_cast<int>(::getpid());
  100. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  101. return static_cast<int>(::GetCurrentProcessId());
  102. #else /* ? OS */
  103. # error Not discriminated for platforms other than UNIX and Windows
  104. #endif /* OS */
  105. }
  106. /* ///////////////////////////// end of file //////////////////////////// */