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.

169 lines
4.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.file/test.scratch.be.file.cpp
  3. *
  4. * Purpose: Implementation file for the test.scratch.be.file project.
  5. *
  6. * Created: 27th November 2006
  7. * Updated: 27th December 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. #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS
  20. /* Pantheios Header Files */
  21. #include <pantheios/pantheios.hpp>
  22. #include <pantheios/inserters/args.hpp>
  23. #include <pantheios/backends/bec.file.h>
  24. /* STLSoft Header Files */
  25. #include <platformstl/filesystem/file_lines.hpp>
  26. #include <platformstl/filesystem/filesystem_traits.hpp>
  27. /* Standard C++ Header Files */
  28. #include <exception>
  29. /* Standard C Header Files */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #if defined(_MSC_VER) && \
  33. defined(_DEBUG)
  34. # include <crtdbg.h>
  35. #endif /* _MSC_VER) && _DEBUG */
  36. #define PSTR PANTHEIOS_LITERAL_STRING
  37. /* /////////////////////////////////////////////////////////////////////////
  38. * Globals
  39. */
  40. PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PSTR("test.scratch.be.file");
  41. /* /////////////////////////////////////////////////////////////////////////
  42. * Constants & definitions
  43. */
  44. static const char FILENAME_LOCAL[] = "log.test.local";
  45. static const char FILENAME_REMOTE[] = "log.test.remote";
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Typedefs
  48. */
  49. typedef platformstl::filesystem_traits<char> fs_traits_t;
  50. typedef platformstl::file_lines file_lines_t;
  51. /* ////////////////////////////////////////////////////////////////////// */
  52. static int main_(int argc, char **argv)
  53. {
  54. #ifndef PANTHEIOS_USE_WIDE_STRINGS
  55. pantheios::log_DEBUG("main_(", pantheios::args(argc, argv), ")");
  56. #endif
  57. {
  58. unsigned flags = PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS | PANTHEIOS_BE_FILE_F_TRUNCATE;
  59. int res1 = pantheios_be_file_setFilePath(PSTR("test-%T-%D.log"), flags, flags, PANTHEIOS_BEID_LOCAL);
  60. pantheios_be_file_flush(PANTHEIOS_BEID_LOCAL);
  61. pantheios::log_NOTICE(PSTR("stmt 1"));
  62. }
  63. #ifndef PANTHEIOS_USE_WIDE_STRINGS
  64. {
  65. pantheios::log_NOTICE("stmt 1");
  66. unsigned flags = PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS | PANTHEIOS_BE_FILE_F_TRUNCATE;
  67. int res1 = pantheios_be_file_setFilePath(FILENAME_LOCAL, flags, flags, PANTHEIOS_BEID_LOCAL);
  68. pantheios::log_NOTICE("stmt 2");
  69. pantheios::log_NOTICE("stmt 3");
  70. int res2 = pantheios_be_file_setFilePath(FILENAME_REMOTE, flags, flags, PANTHEIOS_BEID_REMOTE);
  71. pantheios::log_NOTICE("stmt 4");
  72. pantheios::log_NOTICE("stmt 5");
  73. pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_LOCAL);
  74. pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_REMOTE);
  75. pantheios::log_NOTICE("stmt 6");
  76. pantheios::log_NOTICE("stmt 7");
  77. file_lines_t local_lines(FILENAME_LOCAL);
  78. file_lines_t remote_lines(FILENAME_REMOTE);
  79. const size_t numLocal = local_lines.size();
  80. const size_t numRemote = remote_lines.size();
  81. STLSOFT_ASSERT(4 == numLocal);
  82. STLSOFT_ASSERT(2 == numRemote);
  83. fs_traits_t::delete_file(FILENAME_LOCAL);
  84. fs_traits_t::get_last_error();
  85. fs_traits_t::delete_file(FILENAME_REMOTE);
  86. fs_traits_t::get_last_error();
  87. STLSOFT_SUPPRESS_UNUSED(res1);
  88. STLSOFT_SUPPRESS_UNUSED(res2);
  89. }
  90. #endif
  91. pantheios::log_DEBUG(PSTR("exiting main_()"));
  92. return EXIT_SUCCESS;
  93. }
  94. int main(int argc, char *argv[])
  95. {
  96. int res;
  97. #if defined(_MSC_VER) && \
  98. defined(_DEBUG)
  99. _CrtMemState memState;
  100. #endif /* _MSC_VER && _MSC_VER */
  101. #if defined(_MSC_VER) && \
  102. defined(_DEBUG)
  103. _CrtMemCheckpoint(&memState);
  104. #endif /* _MSC_VER && _MSC_VER */
  105. try
  106. {
  107. res = main_(argc, argv);
  108. }
  109. catch(std::exception &x)
  110. {
  111. fprintf(stderr, "Unhandled error: %s\n", x.what());
  112. res = EXIT_FAILURE;
  113. }
  114. catch(...)
  115. {
  116. fprintf(stderr, "Unhandled unknown error\n");
  117. res = EXIT_FAILURE;
  118. }
  119. #if defined(_MSC_VER) && \
  120. defined(_DEBUG)
  121. _CrtMemDumpAllObjectsSince(&memState);
  122. #endif /* _MSC_VER) && _DEBUG */
  123. return res;
  124. }
  125. /* ////////////////////////////////////////////////////////////////////// */