Checks that FromSubsecondUnixTime gives the correct result. Conversion to double is lossy so the result is expected to be within a certain range of 'expected'. The fraction part of 'nanos' can express sub-nanoseconds - the current logic is to truncate to the next whole nanosecond (towards 0).
| 237 | // The fraction part of 'nanos' can express sub-nanoseconds - the current logic is to |
| 238 | // truncate to the next whole nanosecond (towards 0). |
| 239 | void TestFromDoubleUnixTime( |
| 240 | int64_t seconds, int64_t millis, double nanos, const TimestampValue& expected) { |
| 241 | TimestampValue from_double = TimestampValue::FromSubsecondUnixTime( |
| 242 | 1.0 * seconds + 0.001 * millis + nanos / NANOS_PER_SEC, UTCPTR); |
| 243 | |
| 244 | if (!expected.HasDate()) { |
| 245 | EXPECT_FALSE(from_double.HasDate()); |
| 246 | } else { |
| 247 | // Conversion to double is lossy so the timestamp can be a bit different. |
| 248 | int64_t expected_rounded_to_micros, from_double_rounded_to_micros; |
| 249 | EXPECT_TRUE(expected.UtcToUnixTimeMicros(&expected_rounded_to_micros)); |
| 250 | EXPECT_TRUE(from_double.UtcToUnixTimeMicros(&from_double_rounded_to_micros)); |
| 251 | // The difference can be more than a microsec in case of timestamps far from 1970. |
| 252 | int64_t MARGIN_OF_ERROR = 8; |
| 253 | EXPECT_LT(abs(expected_rounded_to_micros - from_double_rounded_to_micros), |
| 254 | MARGIN_OF_ERROR); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // Checks that all sub-second From*UnixTime gives the same result and that the result |
| 259 | // is the same as 'expected'. |
no test coverage detected