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   def appkit_tester_impl(self, commands, use_constant_classes):
16      if use_constant_classes:
17         self.build()
18      else:
19         disable_constant_classes = {
20            'CC':
21            'xcrun clang', # FIXME: Remove when flags are available upstream.
22            'CFLAGS_EXTRAS':
23            '-fno-constant-nsnumber-literals ' +
24            '-fno-constant-nsarray-literals ' +
25            '-fno-constant-nsdictionary-literals'
26         }
27         self.build(dictionary=disable_constant_classes)
28      self.appkit_common_data_formatters_command()
29      commands()
30
31   def appkit_common_data_formatters_command(self):
32      """Test formatters for AppKit classes."""
33      self.target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
34          self, '// Set break point at this line.',
35          lldb.SBFileSpec('main.m', False))
36
37      # The stop reason of the thread should be breakpoint.
38      self.expect(
39          "thread list",
40          STOPPED_DUE_TO_BREAKPOINT,
41          substrs=['stopped', 'stop reason = breakpoint'])
42
43      # This is the function to remove the custom formats in order to have a
44      # clean slate for the next test case.
45      def cleanup():
46         self.runCmd('type format clear', check=False)
47         self.runCmd('type summary clear', check=False)
48         self.runCmd('type synth clear', check=False)
49
50      # Execute the cleanup function during test case tear down.
51      self.addTearDownHook(cleanup)
52