[Libreoffice-commits] online.git: common/Util.cpp common/Util.hpp test/UnitWOPITemplate.cpp test/WhiteBoxTests.cpp test/WopiTestServer.hpp
DarkByt31 (via logerrit)
logerrit at kemper.freedesktop.org
Sat Sep 28 10:26:51 UTC 2019
common/Util.cpp | 10 ++++++++++
common/Util.hpp | 3 +++
test/UnitWOPITemplate.cpp | 6 +++---
test/WhiteBoxTests.cpp | 6 ++++++
test/WopiTestServer.hpp | 20 +++++++++-----------
5 files changed, 31 insertions(+), 14 deletions(-)
New commits:
commit dd014e7029628dd95d2026bcb4fe4a66d75785aa
Author: DarkByt31 <avihs.29 at gmail.com>
AuthorDate: Fri Sep 27 22:26:16 2019 +0530
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Sat Sep 28 12:26:32 2019 +0200
tdf#107038 Poco::Timestamp replacement with std::chrono
Util added getHttpTime
WhiteBoxTests added test for getHttpTime
Change-Id: Ifb6a3fb2dc9b059b925e7b881362b72759a8b56b
Reviewed-on: https://gerrit.libreoffice.org/79754
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/common/Util.cpp b/common/Util.cpp
index 4433fe6d2..4fc35f370 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -784,6 +784,16 @@ namespace Util
return time_now;
}
+ std::string getHttpTime(std::chrono::system_clock::time_point time)
+ {
+ char http_time[64];
+ std::time_t time_c = std::chrono::system_clock::to_time_t(time);
+ std::tm time_tm = *std::gmtime(&time_c);
+ strftime(http_time, sizeof(http_time), "%a, %d %b %Y %T", &time_tm);
+
+ return http_time;
+ }
+
size_t findInVector(const std::vector<char>& tokens, const char *cstring)
{
assert(cstring);
diff --git a/common/Util.hpp b/common/Util.hpp
index c1f799941..6c97eceb1 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -926,6 +926,9 @@ int main(int argc, char**argv)
//// Return current time in HTTP format.
std::string getHttpTimeNow();
+ //// Return time in HTTP format.
+ std::string getHttpTime(std::chrono::system_clock::time_point time);
+
//// Return timestamp of file
std::chrono::system_clock::time_point getFileTimestamp(std::string str_path);
diff --git a/test/UnitWOPITemplate.cpp b/test/UnitWOPITemplate.cpp
index 9416ea3cc..d133178ec 100644
--- a/test/UnitWOPITemplate.cpp
+++ b/test/UnitWOPITemplate.cpp
@@ -54,7 +54,7 @@ public:
fileInfo->set("UserFriendlyName", "test");
fileInfo->set("UserCanWrite", "true");
fileInfo->set("PostMessageOrigin", "localhost");
- fileInfo->set("LastModifiedTime", Poco::DateTimeFormatter::format(Poco::DateTime(getFileLastModifiedTime()), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT));
+ fileInfo->set("LastModifiedTime", Util::getIso8601FracformatTime(getFileLastModifiedTime()));
fileInfo->set("EnableOwnerTermination", "true");
std::ostringstream jsonStream;
@@ -65,7 +65,7 @@ public:
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
- << "Last-Modified: " << Poco::DateTimeFormatter::format(getFileLastModifiedTime(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+ << "Last-Modified: " << Util::getHttpTime(getFileLastModifiedTime()) << "\r\n"
<< "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
<< "Content-Length: " << responseString.size() << "\r\n"
<< "Content-Type: " << mimeType << "\r\n"
@@ -113,7 +113,7 @@ public:
oss << "HTTP/1.1 200 OK\r\n"
<< "User-Agent: " << WOPI_AGENT_STRING << "\r\n"
<< "\r\n"
- << "{\"LastModifiedTime\": \"" << Poco::DateTimeFormatter::format(getFileLastModifiedTime(), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT) << "\" }";
+ << "{\"LastModifiedTime\": \"" << Util::getHttpTime(getFileLastModifiedTime()) << "\" }";
socket->send(oss.str());
socket->shutdown();
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index e3a6d52a8..6bb74f677 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -762,6 +762,12 @@ void WhiteBoxTests::testTime()
oss.str(std::string());
oss << t.time_since_epoch().count();
CPPUNIT_ASSERT_EQUAL(first, oss.str());
+
+ t = std::chrono::system_clock::time_point();
+ CPPUNIT_ASSERT_EQUAL(std::string("Thu, 01 Jan 1970 00:00:00"), Util::getHttpTime(t));
+
+ t = std::chrono::system_clock::time_point(std::chrono::nanoseconds(1569592993495336798));
+ CPPUNIT_ASSERT_EQUAL(std::string("Fri, 27 Sep 2019 14:03:13"), Util::getHttpTime(t));
}
CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests);
diff --git a/test/WopiTestServer.hpp b/test/WopiTestServer.hpp
index bdeecd96d..0845ba1a9 100644
--- a/test/WopiTestServer.hpp
+++ b/test/WopiTestServer.hpp
@@ -41,7 +41,7 @@ private:
std::string _fileContent;
/// Last modified time of the file
- Poco::Timestamp _fileLastModifiedTime;
+ std::chrono::system_clock::time_point _fileLastModifiedTime;
protected:
const std::string& getWopiSrc() const { return _wopiSrc; }
@@ -54,10 +54,10 @@ protected:
void setFileContent(const std::string& fileContent)
{
_fileContent = fileContent;
- _fileLastModifiedTime = Poco::Timestamp();
+ _fileLastModifiedTime = std::chrono::system_clock::now();
}
- const Poco::Timestamp& getFileLastModifiedTime() const { return _fileLastModifiedTime; }
+ const std::chrono::system_clock::time_point& getFileLastModifiedTime() const { return _fileLastModifiedTime; }
public:
WopiTestServer(std::string fileContent = "Hello, world")
@@ -126,7 +126,7 @@ protected:
fileInfo->set("UserFriendlyName", "test");
fileInfo->set("UserCanWrite", "true");
fileInfo->set("PostMessageOrigin", "localhost");
- fileInfo->set("LastModifiedTime", Poco::DateTimeFormatter::format(Poco::DateTime(_fileLastModifiedTime), Poco::DateTimeFormat::ISO8601_FRAC_FORMAT));
+ fileInfo->set("LastModifiedTime", Util::getIso8601FracformatTime(_fileLastModifiedTime));
fileInfo->set("EnableOwnerTermination", "true");
std::ostringstream jsonStream;
@@ -137,7 +137,7 @@ protected:
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
- "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+ "Last-Modified: " << Util::getHttpTime(_fileLastModifiedTime) << "\r\n"
"User-Agent: " WOPI_AGENT_STRING "\r\n"
"Content-Length: " << responseString.size() << "\r\n"
"Content-Type: " << mimeType << "\r\n"
@@ -160,7 +160,7 @@ protected:
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
- "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+ "Last-Modified: " << Util::getHttpTime(_fileLastModifiedTime) << "\r\n"
"User-Agent: " WOPI_AGENT_STRING "\r\n"
"Content-Length: " << _fileContent.size() << "\r\n"
"Content-Type: " << mimeType << "\r\n"
@@ -194,7 +194,7 @@ protected:
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
- "Last-Modified: " << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n"
+ "Last-Modified: " << Util::getHttpTime(_fileLastModifiedTime) << "\r\n"
"User-Agent: " WOPI_AGENT_STRING "\r\n"
"Content-Length: " << content.size() << "\r\n"
"Content-Type: application/json\r\n"
@@ -214,9 +214,7 @@ protected:
if (!wopiTimestamp.empty())
{
- const std::string fileModifiedTime =
- Poco::DateTimeFormatter::format(Poco::DateTime(_fileLastModifiedTime),
- Poco::DateTimeFormat::ISO8601_FRAC_FORMAT);
+ const std::string fileModifiedTime = Util::getIso8601FracformatTime(_fileLastModifiedTime);
if (wopiTimestamp != fileModifiedTime)
{
std::ostringstream oss;
@@ -242,7 +240,7 @@ protected:
oss << "HTTP/1.1 200 OK\r\n"
"User-Agent: " WOPI_AGENT_STRING "\r\n"
"\r\n"
- "{\"LastModifiedTime\": \"" << Poco::DateTimeFormatter::format(_fileLastModifiedTime, Poco::DateTimeFormat::ISO8601_FRAC_FORMAT) << "\" }";
+ "{\"LastModifiedTime\": \"" << Util::getIso8601FracformatTime(_fileLastModifiedTime) << "\" }";
socket->send(oss.str());
socket->shutdown();
More information about the Libreoffice-commits
mailing list