@@ -38,36 +38,69 @@ namespace test {
3838 this ->_system_zero = std::chrono::system_clock::from_time_t (0 );
3939 }
4040
41+ TEST_METHOD (test_convert) {
42+ auto a = detail::convert (std::chrono::system_clock::from_time_t (0 ), timestamp_resolution::hundred_nanoseconds);
43+ Assert::AreEqual (this ->_filetime_zero , a, L" Unix epoch as FILETIME" , LINE_INFO ());
44+ }
45+
4146 TEST_METHOD (test_microseconds) {
47+ typedef std::chrono::microseconds unit;
48+ static const auto resolution = timestamp_resolution::microseconds;
49+ const auto max_dt = std::chrono::duration_cast<unit>(std::chrono::milliseconds (100 )).count ();
50+
4251 auto n = std::chrono::system_clock::now ();
43- auto t = detail::create_timestamp (timestamp_resolution::microseconds );
44- auto s = std::chrono::duration_cast<std::chrono::microseconds >(n - this ->_system_zero ).count ();
45- auto z = detail::convert (this ->_filetime_zero , timestamp_resolution::microseconds );
46- Assert::IsTrue (s - z - t < 1000000 , L" timestamp microsecond" , LINE_INFO ());
52+ auto t = detail::create_timestamp (resolution );
53+ auto s = std::chrono::duration_cast<unit >(n - this ->_system_zero ).count ();
54+ auto z = detail::convert (this ->_filetime_zero , resolution );
55+ Assert::IsTrue (s - z - t < max_dt , L" timestamp microsecond" , LINE_INFO ());
4756 }
4857
4958 TEST_METHOD (test_milliseconds) {
59+ typedef std::chrono::milliseconds unit;
60+ static const auto resolution = timestamp_resolution::milliseconds;
61+ const auto max_dt = std::chrono::duration_cast<unit>(std::chrono::milliseconds (100 )).count ();
62+
5063 auto n = std::chrono::system_clock::now ();
5164 auto t = detail::create_timestamp (timestamp_resolution::milliseconds);
5265 auto s = std::chrono::duration_cast<std::chrono::milliseconds>(n - this ->_system_zero ).count ();
5366 auto z = detail::convert (this ->_filetime_zero , timestamp_resolution::milliseconds);
54- Assert::IsTrue (t - z - s < 1000 , L" timestamp millisecond" , LINE_INFO ());
67+ Assert::IsTrue (t - z - s < max_dt, L" timestamp millisecond" , LINE_INFO ());
68+ }
69+
70+ TEST_METHOD (test_hundred_nanoseconds) {
71+ typedef std::chrono::duration<std::chrono::system_clock::duration::rep, detail::filetime_period> unit;
72+ static const auto resolution = timestamp_resolution::milliseconds;
73+ const auto max_dt = std::chrono::duration_cast<unit>(std::chrono::milliseconds (100 )).count ();
74+
75+ auto n = std::chrono::system_clock::now ();
76+ auto t = detail::create_timestamp (resolution);
77+ auto s = std::chrono::duration_cast<unit>(n - this ->_system_zero ).count ();
78+ auto z = detail::convert (this ->_filetime_zero , resolution);
79+ Assert::IsTrue (t - z - s < max_dt, L" timestamp 100 nanoseconds" , LINE_INFO ());
5580 }
5681
5782 TEST_METHOD (test_nanoseconds) {
83+ typedef std::chrono::milliseconds unit;
84+ static const auto resolution = timestamp_resolution::milliseconds;
85+ const auto max_dt = std::chrono::duration_cast<unit>(std::chrono::milliseconds (100 )).count ();
86+
5887 auto n = std::chrono::system_clock::now ();
59- auto t = detail::create_timestamp (timestamp_resolution::nanoseconds );
60- auto s = std::chrono::duration_cast<std::chrono::nanoseconds >(n - this ->_system_zero ).count ();
61- auto z = detail::convert (this ->_filetime_zero , timestamp_resolution::nanoseconds );
62- Assert::IsTrue (t - z - s < 1000000000 , L" timestamp nanosecond" , LINE_INFO ());
88+ auto t = detail::create_timestamp (resolution );
89+ auto s = std::chrono::duration_cast<unit >(n - this ->_system_zero ).count ();
90+ auto z = detail::convert (this ->_filetime_zero , resolution );
91+ Assert::IsTrue (t - z - s < max_dt , L" timestamp nanosecond" , LINE_INFO ());
6392 }
6493
6594 TEST_METHOD (test_seconds) {
95+ typedef std::chrono::seconds unit;
96+ static const auto resolution = timestamp_resolution::seconds;
97+ const auto max_dt = std::chrono::duration_cast<unit>(std::chrono::milliseconds (100 )).count ();
98+
6699 auto n = std::chrono::system_clock::now ();
67- auto t = detail::create_timestamp (timestamp_resolution::seconds );
68- auto s = std::chrono::duration_cast<std::chrono::seconds >(n - this ->_system_zero ).count ();
69- auto z = detail::convert (this ->_filetime_zero , timestamp_resolution::seconds );
70- Assert::IsTrue (s - z - t < 1 , L" timestamp second" , LINE_INFO ());
100+ auto t = detail::create_timestamp (resolution );
101+ auto s = std::chrono::duration_cast<unit >(n - this ->_system_zero ).count ();
102+ auto z = detail::convert (this ->_filetime_zero , resolution );
103+ Assert::IsTrue (s - z - t < max_dt , L" timestamp second" , LINE_INFO ());
71104 }
72105
73106 private:
0 commit comments