1# encoding: utf-8
2"""
3Test lldb date formatter subsystem.
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12from ObjCDataFormatterTestCase import ObjCDataFormatterTestCase
13
14import datetime
15
16class ObjCDataFormatterNSDate(ObjCDataFormatterTestCase):
17
18    def test_nsdate_with_run_command(self):
19        """Test formatters for  NSDate."""
20        self.appkit_tester_impl(self.nsdate_data_formatter_commands, False)
21
22    def nsdate_data_formatter_commands(self):
23        self.expect(
24            'frame variable date1 date2',
25            patterns=[
26                '(1985-04-10|1985-04-11)',
27                '(2011-01-01|2010-12-31)'])
28
29        # this test might fail if we hit the breakpoint late on December 31st of some given year
30        # and midnight comes between hitting the breakpoint and running this line of code
31        # hopefully the output will be revealing enough in that case :-)
32        now_year = '%s-' % str(datetime.datetime.now().year)
33
34        self.expect('frame variable date3', substrs=[now_year])
35        self.expect('frame variable date4', substrs=['1970'])
36        self.expect('frame variable date5', substrs=[now_year])
37
38        self.expect('frame variable date1_abs date2_abs',
39                    substrs=['1985-04', '2011-01'])
40
41        self.expect('frame variable date3_abs', substrs=[now_year])
42        self.expect('frame variable date4_abs', substrs=['1970'])
43        self.expect('frame variable date5_abs', substrs=[now_year])
44
45        # Check that LLDB always follow's NSDate's rounding behavior (which
46        # is always rounding down).
47        self.expect_expr("date_1970_minus_06", result_summary="1969-12-31 23:59:59 UTC")
48        self.expect_expr("date_1970_minus_05", result_summary="1969-12-31 23:59:59 UTC")
49        self.expect_expr("date_1970_minus_04", result_summary="1969-12-31 23:59:59 UTC")
50        self.expect_expr("date_1970_plus_06", result_summary="1970-01-01 00:00:00 UTC")
51        self.expect_expr("date_1970_plus_05", result_summary="1970-01-01 00:00:00 UTC")
52        self.expect_expr("date_1970_plus_04", result_summary="1970-01-01 00:00:00 UTC")
53
54        self.expect('frame variable cupertino home europe',
55                    substrs=['@"America/Los_Angeles"',
56                             '@"Europe/Rome"',
57                             '@"Europe/Paris"'])
58
59        self.expect('frame variable cupertino_ns home_ns europe_ns',
60                    substrs=['@"America/Los_Angeles"',
61                             '@"Europe/Rome"',
62                             '@"Europe/Paris"'])
63
64        self.expect(
65            'frame variable mut_bv',
66            substrs=[
67                '(CFMutableBitVectorRef) mut_bv = ',
68                '1110 0110 1011 0000 1101 1010 1000 1111 0011 0101 1101 0001 00'])
69
70        self.expect_expr("distant_past", result_summary="0001-01-01 00:00:00 UTC")
71        self.expect_expr("distant_future", result_summary="4001-01-01 00:00:00 UTC")
72