| 1 |
#!/usr/bin/env python3 |
| 2 |
"""Tests for the APFS timestamp implementation.""" |
| 3 |
|
| 4 |
import decimal |
| 5 |
import unittest |
| 6 |
|
| 7 |
from dfdatetime import apfs_time |
| 8 |
|
| 9 |
|
| 10 |
class APFSTimeTest(unittest.TestCase): |
| 11 |
"""Tests for the APFS timestamp.""" |
| 12 |
|
| 13 |
# pylint: disable=protected-access |
| 14 |
|
| 15 |
def testGetNormalizedTimestamp(self): |
| 16 |
"""Tests the _GetNormalizedTimestamp function.""" |
| 17 |
apfs_time_object = apfs_time.APFSTime(timestamp=1281643591987654321) |
| 18 |
|
| 19 |
normalized_timestamp = apfs_time_object._GetNormalizedTimestamp() |
| 20 |
self.assertEqual(normalized_timestamp, decimal.Decimal("1281643591.987654321")) |
| 21 |
|
| 22 |
apfs_time_object = apfs_time.APFSTime( |
| 23 |
time_zone_offset=60, timestamp=1281643591987654321 |
| 24 |
) |
| 25 |
|
| 26 |
normalized_timestamp = apfs_time_object._GetNormalizedTimestamp() |
| 27 |
self.assertEqual(normalized_timestamp, decimal.Decimal("1281639991.987654321")) |
| 28 |
|
| 29 |
apfs_time_object = apfs_time.APFSTime(timestamp=1281643591987654321) |
| 30 |
apfs_time_object.time_zone_offset = 60 |
| 31 |
|
| 32 |
normalized_timestamp = apfs_time_object._GetNormalizedTimestamp() |
| 33 |
self.assertEqual(normalized_timestamp, decimal.Decimal("1281639991.987654321")) |
| 34 |
|
| 35 |
apfs_time_object = apfs_time.APFSTime() |
| 36 |
|
| 37 |
normalized_timestamp = apfs_time_object._GetNormalizedTimestamp() |
| 38 |
self.assertIsNone(normalized_timestamp) |
| 39 |
|
| 40 |
apfs_time_object = apfs_time.APFSTime(timestamp=9223372036854775810) |
| 41 |
|
| 42 |
date_time_string = apfs_time_object._GetNormalizedTimestamp() |
| 43 |
self.assertIsNone(date_time_string) |
| 44 |
|
| 45 |
def testCopyFromDateTimeString(self): |
| 46 |
"""Tests the CopyFromDateTimeString function.""" |
| 47 |
apfs_time_object = apfs_time.APFSTime() |
| 48 |
with self.assertRaises(ValueError): |
| 49 |
apfs_time_object.CopyFromDateTimeString("2554-07-21 23:34:34.000000") |
| 50 |
|
| 51 |
def testCopyToDateTimeString(self): |
| 52 |
"""Tests the CopyToDateTimeString function.""" |
| 53 |
apfs_time_object = apfs_time.APFSTime(timestamp=1281643591987654321) |
| 54 |
|
| 55 |
date_time_string = apfs_time_object.CopyToDateTimeString() |
| 56 |
self.assertEqual(date_time_string, "2010-08-12 20:06:31.987654321") |
| 57 |
|
| 58 |
apfs_time_object = apfs_time.APFSTime(timestamp=9223372036854775810) |
| 59 |
|
| 60 |
date_time_string = apfs_time_object.CopyToDateTimeString() |
| 61 |
self.assertIsNone(date_time_string) |
| 62 |
|
| 63 |
apfs_time_object = apfs_time.APFSTime() |
| 64 |
|
| 65 |
date_time_string = apfs_time_object.CopyToDateTimeString() |
| 66 |
self.assertIsNone(date_time_string) |
| 67 |
|
| 68 |
|
| 69 |
if __name__ == "__main__": |
| 70 |
unittest.main() |