1"""Test that a forward-declared class works when its complete definition is in a library"""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class ForwardDeclTestCase(TestBase):
10
11    mydir = os.path.join("lang", "objc", "forward-decl")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @dsym_test
15    def test_expr_with_dsym(self):
16        self.buildDsym()
17        self.expr()
18
19    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
20    @dwarf_test
21    def test_expr_with_dwarf(self):
22        self.buildDwarf()
23        self.expr()
24
25    def setUp(self):
26        # Call super's setUp().
27        TestBase.setUp(self)
28        # Find the line number to break inside main().
29        self.line = line_number('main.m', '// Set breakpoint 0 here.')
30
31    def common_setup(self):
32        exe = os.path.join(os.getcwd(), "a.out")
33        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
34
35        # Break inside the foo function which takes a bar_ptr argument.
36        lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
37
38        self.runCmd("run", RUN_SUCCEEDED)
39
40        # The stop reason of the thread should be breakpoint.
41        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42            substrs = ['stopped',
43                       'stop reason = breakpoint'])
44
45        # The breakpoint should have a hit count of 1.
46        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
47            substrs = [' resolved, hit count = 1'])
48
49    def expr(self):
50        self.common_setup()
51
52        # This should display correctly.
53        self.expect("expression [j getMember]", VARIABLES_DISPLAYED_CORRECTLY,
54            substrs = ["= 0x"])
55
56if __name__ == '__main__':
57    import atexit
58    lldb.SBDebugger.Initialize()
59    atexit.register(lambda: lldb.SBDebugger.Terminate())
60    unittest2.main()
61