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