From: <log...@li...> - 2016-11-06 14:20:02
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Log4cpp Git repository.". The branch, master has been updated via 2053240ad40a7cf4bcac29c0caf29dcada921a8f (commit) from 626e36a137197405760e232faab8aafffc5a5f8e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://sourceforge.net/p/log4cpp/codegit/ci/ commit 2053240ad40a7cf4bcac29c0caf29dcada921a8f Author: Alexander Perepelkin <san...@sf...> Date: Wed Nov 9 17:20:01 2016 +0300 daily test support for windows diff --git a/src/DailyRollingFileAppender.cpp b/src/DailyRollingFileAppender.cpp index 74b2923..89930f1 100644 --- a/src/DailyRollingFileAppender.cpp +++ b/src/DailyRollingFileAppender.cpp @@ -73,14 +73,23 @@ namespace log4cpp { void DailyRollingFileAppender::rollOver() { std::ostringstream filename_s; - ::close(_fd); + int res_close = ::close(_fd); + if (res_close != 0) { + std::cerr << "Error closing file " << _fileName << std::endl; + } filename_s << _fileName << "." << _logsTime.tm_year + 1900 << "-" << std::setfill('0') << std::setw(2) << _logsTime.tm_mon + 1 << "-" << std::setw(2) << _logsTime.tm_mday << std::ends; const std::string lastFn = filename_s.str(); - ::rename(_fileName.c_str(), lastFn.c_str()); + int res_rename = ::rename(_fileName.c_str(), lastFn.c_str()); + if (res_rename != 0) { + std::cerr << "Error renaming file " << _fileName << " to " << lastFn << std::endl; + } _fd = ::open(_fileName.c_str(), _flags, _mode); + if (_fd == -1) { + std::cerr << "Error opening file " << _fileName << std::endl; + } const time_t oldest = time(NULL) - _maxDaysToKeep * 60 * 60 * 24; diff --git a/tests/testDailyRollingFileAppender.cpp b/tests/testDailyRollingFileAppender.cpp index 46d3fc0..68f87f2 100644 --- a/tests/testDailyRollingFileAppender.cpp +++ b/tests/testDailyRollingFileAppender.cpp @@ -13,7 +13,6 @@ #include <memory> #include <cstring> -#include "PortabilityImpl.hh" #ifdef LOG4CPP_HAVE_IO_H # include <io.h> #endif @@ -23,6 +22,8 @@ #ifndef WIN32 // only available on Win32 #include <dirent.h> +#else +#include <direct.h> #endif #ifdef WIN32 @@ -174,17 +175,23 @@ namespace OnlyManualTesting { const int maxDaysToKeep = 3; #if defined(WIN32) - const char *logFilename = "C:/Temp/log4cpp/dailyrolling_abs_path_file.log"; - const char *logPathname = "C:/Temp/log4cpp"; + const char *logFilename = "C:\\Temp\\log4cpp\\dailyrolling_abs_path_file.log"; + const char *logPathname = "C:\\Temp\\log4cpp"; #else const char *logFilename = "/var/log/log4cpp/dailyrolling_abs_path_file.log"; const char *logPathname = "/var/log/log4cpp"; #endif void setupManualEntryLog() { +#if defined(WIN32) + if (access(logPathname, 0) != 0) { + mkdir(logPathname); + } +#else if (access(logPathname, F_OK) != 0) { mkdir(logPathname, 644); } +#endif log4cpp::PatternLayout *ostreamLayout = new log4cpp::PatternLayout(); ostreamLayout->setConversionPattern("%d: %p %c %x: %m %n"); @@ -207,6 +214,32 @@ namespace OnlyManualTesting { int checkThatNoMoreThanNLogFilesPresent(const std::string _fileName, int n); + int jumpToFuture(int seconds) { + +#if defined(WIN32) + SYSTEMTIME now; + GetSystemTime(&now); + now.wDay += seconds / (24*60*60); + now.wSecond += 1; + if (SetSystemTime(&now) == 0) { + std::cerr << "Can not change system time. Probably not today... Try running as admin? Err: " << GetLastError() << std::endl; + return -1; + } +#else + time_t now; + if (time(&now) == -1) + return -1; + + now += seconds; + + if (stime(&now) == -1) { + std::cerr << "Can not set date. Need admin privileges?" << std::endl; + return -1; + } +#endif + return 0; + } + int makeManualEntryLog() { const int totalLinesCount = 14, linesPerDay=3, jumpPeriod=24*60*60 + 1; @@ -219,27 +252,15 @@ namespace OnlyManualTesting { absolutePathCategory.debugStream() << "debug line " << i; while (++i <= totalLinesCount) { if (i % linesPerDay == 0) { - time_t now; - if (time(&now) == -1) + if (jumpToFuture(jumpPeriod) == -1) return -1; - now += jumpPeriod; future += jumpPeriod; - if (stime(&now) == -1) { - std::cerr << "Can not set date. Need admin privileges?" << std::endl; - return -1; - } } absolutePathCategory.debugStream() << "debug line " << i; } - time_t now; - if (time(&now) == -1) + if (jumpToFuture(0-future) == -1) return -1; - now -= future; - if (stime(&now) == -1) { - std::cerr << "Can not set date. Need admin privileges?" << std::endl; - return -1; - } // 2. check the number of files in /var/log/log4cpp ( <= maxDaysToKeep) (+1 to allow consequent runs of test) if (checkThatNoMoreThanNLogFilesPresent(std::string(logFilename), maxDaysToKeep + 1) == -1) @@ -305,8 +326,8 @@ int main() res = testConfigDailyRollingFileAppender(); // Note: this test changes system time. Run it only manually -// if (!res) -// res = OnlyManualTesting::testDailyRollingFileAppenderChangeDateManualOnly(); + if (!res) + res = OnlyManualTesting::testDailyRollingFileAppenderChangeDateManualOnly(); return res; } ----------------------------------------------------------------------- Summary of changes: src/DailyRollingFileAppender.cpp | 13 ++++++- tests/testDailyRollingFileAppender.cpp | 59 +++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 21 deletions(-) hooks/post-receive -- Log4cpp Git repository. |