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