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        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
42                    substrs=[' resolved, hit count = 1'])
43
44        self.expect("expr @import Darwin; 3", VARIABLES_DISPLAYED_CORRECTLY,
45                    substrs=["int", "3"])
46
47        self.expect("expr getpid()", VARIABLES_DISPLAYED_CORRECTLY,
48                    substrs=["pid_t"])
49
50        self.expect(
51            "expr @import Foundation; 4",
52            VARIABLES_DISPLAYED_CORRECTLY,
53            substrs=[
54                "int",
55                "4"])
56
57        # Type lookup should still work and print something reasonable
58        # for types from the module.
59        self.expect("type lookup NSObject", substrs=["instanceMethod"])
60
61        self.expect("expr string.length", VARIABLES_DISPLAYED_CORRECTLY,
62                    substrs=["NSUInteger", "5"])
63
64        self.expect("expr array.count", VARIABLES_DISPLAYED_CORRECTLY,
65                    substrs=["NSUInteger", "3"])
66
67        self.expect(
68            "p *[NSURL URLWithString:@\"http://lldb.llvm.org\"]",
69            VARIABLES_DISPLAYED_CORRECTLY,
70            substrs=[
71                "NSURL",
72                "isa",
73                "_urlString"])
74
75        self.expect(
76            "p [NSURL URLWithString:@\"http://lldb.llvm.org\"].scheme",
77            VARIABLES_DISPLAYED_CORRECTLY,
78            substrs=["http"])
79        # Test that the NULL macro still works with a loaded module.
80        self.expect_expr("int *i = NULL; i == NULL", result_value="true")
81