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.

191 lines
5.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.file.rolling/test.scratch.be.file.rolling.cpp
  3. *
  4. * Purpose: Implementation file for the test.scratch.be.file.rolling project.
  5. *
  6. * Created: 24th October 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. #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/inserters/integer.hpp>
  24. #include <pantheios/backends/bec.file.h>
  25. /* STLSoft Header Files */
  26. #include <platformstl/filesystem/file_lines.hpp>
  27. #include <platformstl/filesystem/filesystem_traits.hpp>
  28. #include <platformstl/filesystem/path.hpp>
  29. /* Standard C++ Header Files */
  30. #include <exception>
  31. /* Standard C Header Files */
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #if defined(_MSC_VER) && \
  35. defined(_DEBUG)
  36. # include <crtdbg.h>
  37. #endif /* _MSC_VER) && _DEBUG */
  38. /* /////////////////////////////////////////////////////////////////////////
  39. * Constants & definitions
  40. */
  41. //static const char FILENAME_REMOTE[] = "rolling-log.test.remote";
  42. static const int ENTRY_QUANTUM = 10;
  43. /* /////////////////////////////////////////////////////////////////////////
  44. * Function implementations
  45. */
  46. PANTHEIOS_CALL(void) pantheios_be_file_getAppInit(int backEndId, pan_be_file_init_t* init) /* throw() */
  47. {
  48. switch(backEndId)
  49. {
  50. case PANTHEIOS_BEID_REMOTE:
  51. init->roll.entryCount = ENTRY_QUANTUM;
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. /* /////////////////////////////////////////////////////////////////////////
  58. * Globals
  59. */
  60. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.be.file.rolling");
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Typedefs
  63. */
  64. typedef platformstl::filesystem_traits<char> fs_traits_t;
  65. typedef platformstl::basic_path<char> path_t;
  66. typedef platformstl::file_lines file_lines_t;
  67. /* /////////////////////////////////////////////////////////////////////////
  68. * Forward declarations
  69. */
  70. static void test_ROLL_ON_ENTRIES();
  71. /* ////////////////////////////////////////////////////////////////////// */
  72. static int main_(int argc, char** argv)
  73. {
  74. /* . */
  75. pantheios::log_DEBUG("main_(", pantheios::args(argc, argv), ")");
  76. test_ROLL_ON_ENTRIES();
  77. pantheios::log_DEBUG("exiting main_()");
  78. return EXIT_SUCCESS;
  79. }
  80. /* ////////////////////////////////////////////////////////////////////// */
  81. static void test_ROLL_ON_ENTRIES()
  82. {
  83. // Create a file, with rolling quantum of
  84. unsigned flags = 0
  85. | PANTHEIOS_BE_FILE_F_DISCARD_CACHED_CONTENTS
  86. | PANTHEIOS_BE_FILE_F_TRUNCATE
  87. | PANTHEIOS_BE_FILE_F_ROLL_ON_ENTRY_COUNT
  88. | 0;
  89. pantheios_be_file_setFilePath("rolling-log.test.remote", flags, flags, PANTHEIOS_BEID_REMOTE);
  90. const int NUM_ENTRIES = 104;
  91. { for(size_t i = 0; i < NUM_ENTRIES; ++i)
  92. {
  93. pantheios::log_NOTICE("stmt #", pantheios::integer(i));
  94. }}
  95. pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_REMOTE);
  96. { for(size_t i = 0; i < NUM_ENTRIES; i += ENTRY_QUANTUM)
  97. {
  98. size_t index = i / ENTRY_QUANTUM;
  99. path_t path = "rolling-log.test.remote";
  100. path /= pantheios::integer(index).c_str();
  101. file_lines_t remote_lines(path);
  102. size_t numRemote = remote_lines.size();
  103. STLSOFT_ASSERT(index < (NUM_ENTRIES / ENTRY_QUANTUM) ? ENTRY_QUANTUM == numRemote : (NUM_ENTRIES % ENTRY_QUANTUM) == numRemote);
  104. fs_traits_t::delete_file(path.c_str());
  105. fs_traits_t::get_last_error();
  106. }}
  107. }
  108. /* ////////////////////////////////////////////////////////////////////// */
  109. int main(int argc, char** argv)
  110. {
  111. int res;
  112. #if defined(_MSC_VER) && \
  113. defined(_DEBUG)
  114. _CrtMemState memState;
  115. #endif /* _MSC_VER && _MSC_VER */
  116. #if defined(_MSC_VER) && \
  117. defined(_DEBUG)
  118. _CrtMemCheckpoint(&memState);
  119. #endif /* _MSC_VER && _MSC_VER */
  120. try
  121. {
  122. res = main_(argc, argv);
  123. }
  124. catch(std::exception &x)
  125. {
  126. pantheios::log_ALERT("Unexpected general error: ", x, ". Application terminating");
  127. res = EXIT_FAILURE;
  128. }
  129. catch(...)
  130. {
  131. pantheios::logputs(pantheios::emergency, "Unhandled unknown error");
  132. res = EXIT_FAILURE;
  133. }
  134. #if defined(_MSC_VER) && \
  135. defined(_DEBUG)
  136. _CrtMemDumpAllObjectsSince(&memState);
  137. #endif /* _MSC_VER) && _DEBUG */
  138. return res;
  139. }
  140. /* ////////////////////////////////////////////////////////////////////// */