xref: /llvm-project/lldb/test/API/lang/objc/modules/TestObjCModules.py (revision 9f0b5f9a39ea6e70c98c69a720d7e4f5d3800bf6)
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    @skipIf(macos_version=["<", "10.12"])
24    def test_expr(self):
25        self.build()
26        exe = self.getBuildArtifact("a.out")
27        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
28
29        # Break inside the foo function which takes a bar_ptr argument.
30        lldbutil.run_break_set_by_file_and_line(
31            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
32
33        self.runCmd("run", RUN_SUCCEEDED)
34
35        # The stop reason of the thread should be breakpoint.
36        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
37                    substrs=['stopped',
38                             'stop reason = breakpoint'])
39
40        # The breakpoint should have a hit count of 1.
41        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
42
43        self.expect("expr @import Darwin; 3", VARIABLES_DISPLAYED_CORRECTLY,
44                    substrs=["int", "3"])
45
46        self.expect("expr getpid()", VARIABLES_DISPLAYED_CORRECTLY,
47                    substrs=["pid_t"])
48
49        self.expect(
50            "expr @import Foundation; 4",
51            VARIABLES_DISPLAYED_CORRECTLY,
52            substrs=[
53                "int",
54                "4"])
55
56        # Type lookup should still work and print something reasonable
57        # for types from the module.
58        self.expect("type lookup NSObject", substrs=["instanceMethod"])
59
60        self.expect("expr string.length", VARIABLES_DISPLAYED_CORRECTLY,
61                    substrs=["NSUInteger", "5"])
62
63        self.expect("expr array.count", VARIABLES_DISPLAYED_CORRECTLY,
64                    substrs=["NSUInteger", "3"])
65
66        self.expect(
67            "p *[NSURL URLWithString:@\"http://lldb.llvm.org\"]",
68            VARIABLES_DISPLAYED_CORRECTLY,
69            substrs=[
70                "NSURL",
71                "isa",
72                "_urlString"])
73
74        self.expect(
75            "p [NSURL URLWithString:@\"http://lldb.llvm.org\"].scheme",
76            VARIABLES_DISPLAYED_CORRECTLY,
77            substrs=["http"])
78        # Test that the NULL macro still works with a loaded module.
79        self.expect_expr("int *i = NULL; i == NULL", result_value="true")
80