1# encoding: utf-8
2"""
3Test lldb data formatter subsystem.
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ObjCDataFormatterTestCase(TestBase):
14
15   mydir = TestBase.compute_mydir(__file__)
16
17   def appkit_tester_impl(self, commands, use_constant_classes):
18      if use_constant_classes:
19         self.build()
20      else:
21         disable_constant_classes = {
22            'CC':
23            'xcrun clang', # FIXME: Remove when flags are available upstream.
24            'CFLAGS_EXTRAS':
25            '-fno-constant-nsnumber-literals ' +
26            '-fno-constant-nsarray-literals ' +
27            '-fno-constant-nsdictionary-literals'
28         }
29         self.build(dictionary=disable_constant_classes)
30      self.appkit_common_data_formatters_command()
31      commands()
32
33   def appkit_common_data_formatters_command(self):
34      """Test formatters for AppKit classes."""
35      self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
36          self, '// Set break point at this line.',
37          lldb.SBFileSpec('main.m', False))
38
39      # The stop reason of the thread should be breakpoint.
40      self.expect(
41          "thread list",
42          STOPPED_DUE_TO_BREAKPOINT,
43          substrs=['stopped', 'stop reason = breakpoint'])
44
45      # This is the function to remove the custom formats in order to have a
46      # clean slate for the next test case.
47      def cleanup():
48         self.runCmd('type format clear', check=False)
49         self.runCmd('type summary clear', check=False)
50         self.runCmd('type synth clear', check=False)
51
52      # Execute the cleanup function during test case tear down.
53      self.addTearDownHook(cleanup)
54