martinzink commented on code in PR #1560:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1560#discussion_r1188203069


##########
libminifi/test/unit/FileUtilsTests.cpp:
##########
@@ -516,3 +516,38 @@ TEST_CASE("FileUtils::path_size", "[TestPathSize]") {
 
   REQUIRE(FileUtils::path_size(dir) == 12);
 }
+
+TEST_CASE("file_clock to system_clock conversion tests") {
+  using namespace std::chrono;
+
+  static_assert(system_clock::period::num == file_clock::period::num);
+  constexpr auto lowest_den = std::min(file_clock::period::den, 
system_clock::period::den);
+  using LeastPreciseDurationType = 
duration<std::common_type_t<system_clock::duration::rep, 
file_clock::duration::rep>, std::ratio<system_clock::period::num, lowest_den>>;
+
+  {
+    system_clock::time_point system_now = system_clock::now();
+    file_clock::time_point converted_system_now = 
FileUtils::from_sys(system_now);
+    system_clock::time_point double_converted_system_now = 
FileUtils::to_sys(converted_system_now);
+
+    
CHECK(time_point_cast<LeastPreciseDurationType>(system_now).time_since_epoch().count()
 == 
time_point_cast<LeastPreciseDurationType>(double_converted_system_now).time_since_epoch().count());
+  }
+
+  {
+    file_clock::time_point file_now = file_clock ::now();
+    system_clock::time_point converted_file_now = FileUtils::to_sys(file_now);
+    file_clock::time_point double_converted_file_now = 
FileUtils::from_sys(converted_file_now);
+
+    
CHECK(time_point_cast<LeastPreciseDurationType>(file_now).time_since_epoch().count()
 == 
time_point_cast<LeastPreciseDurationType>(double_converted_file_now).time_since_epoch().count());
+  }
+
+  {
+    system_clock::time_point system_now = system_clock::now();
+    file_clock::time_point file_now = file_clock ::now();
+
+    file_clock::time_point converted_system_now = 
FileUtils::from_sys(system_now);
+    system_clock::time_point converted_file_now = FileUtils::to_sys(file_now);
+
+    CHECK(system_now-converted_file_now < 10ms);

Review Comment:
   You are right, thanks. I've refactored it a bit so its more clear which one 
is earlier in  
https://github.com/apache/nifi-minifi-cpp/pull/1560/commits/8139796ee615269c86d693942e6fc3b87d16a3bc



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to