xref: /llvm-project/lldb/test/API/lang/objc/modules/TestObjCModules.py (revision 1e566f6b47fb77812d99c93e0a1b8613d288058c)
1"""Test that importing modules in Objective-C works as expected."""
2
3
4
5import unittest2
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ObjCModulesTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number to break inside main().
21        self.line = line_number('main.m', '// Set breakpoint 0 here.')
22
23    @skipUnlessDarwin
24    @skipIf(macos_version=["<", "10.12"])
25    @skipIfReproducer # Unexpected packet during replay
26    def test_expr(self):
27        self.build()
28        exe = self.getBuildArtifact("a.out")
29        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
30
31        # Break inside the foo function which takes a bar_ptr argument.
32        lldbutil.run_break_set_by_file_and_line(
33            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
34
35        self.runCmd("run", RUN_SUCCEEDED)
36
37        # The stop reason of the thread should be breakpoint.
38        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
39                    substrs=['stopped',
40                             'stop reason = breakpoint'])
41
42        # The breakpoint should have a hit count of 1.
43        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
44                    substrs=[' resolved, hit count = 1'])
45
46        self.expect("expr @import Darwin; 3", VARIABLES_DISPLAYED_CORRECTLY,
47                    substrs=["int", "3"])
48
49        self.expect("expr getpid()", VARIABLES_DISPLAYED_CORRECTLY,
50                    substrs=["pid_t"])
51
52        self.expect(
53            "expr @import Foundation; 4",
54            VARIABLES_DISPLAYED_CORRECTLY,
55            substrs=[
56                "int",
57                "4"])
58
59        # Type lookup should still work and print something reasonable
60        # for types from the module.
61        self.expect("type lookup NSObject", substrs=["instanceMethod"])
62
63        self.expect("expr string.length", VARIABLES_DISPLAYED_CORRECTLY,
64                    substrs=["NSUInteger", "5"])
65
66        self.expect("expr array.count", VARIABLES_DISPLAYED_CORRECTLY,
67                    substrs=["NSUInteger", "3"])
68
69        self.expect(
70            "p *[NSURL URLWithString:@\"http://lldb.llvm.org\"]",
71            VARIABLES_DISPLAYED_CORRECTLY,
72            substrs=[
73                "NSURL",
74                "isa",
75                "_urlString"])
76
77        self.expect(
78            "p [NSURL URLWithString:@\"http://lldb.llvm.org\"].scheme",
79            VARIABLES_DISPLAYED_CORRECTLY,
80            substrs=["http"])
81