xref: /llvm-project/lldb/test/API/lang/objc/foundation/TestConstStrings.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Test that objective-c constant strings are generated correctly by the expression
3parser.
4"""
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ConstStringTestCase(TestBase):
14    d = {"OBJC_SOURCES": "const-strings.m"}
15
16    def setUp(self):
17        # Call super's setUp().
18        TestBase.setUp(self)
19        # Find the line number to break inside main().
20        self.main_source = "const-strings.m"
21        self.line = line_number(self.main_source, "// Set breakpoint here.")
22
23    def test_break(self):
24        """Test constant string generation amd comparison by the expression parser."""
25        self.build(dictionary=self.d)
26        self.setTearDownCleanup(self.d)
27
28        exe = self.getBuildArtifact("a.out")
29        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
30
31        lldbutil.run_break_set_by_file_and_line(
32            self, self.main_source, self.line, num_expected_locations=1, loc_exact=True
33        )
34
35        self.runCmd("run", RUN_SUCCEEDED)
36        self.expect(
37            "process status",
38            STOPPED_DUE_TO_BREAKPOINT,
39            substrs=[
40                "stop reason = breakpoint",
41                " at %s:%d" % (self.main_source, self.line),
42            ],
43        )
44
45        self.expect('expression (int)[str compare:@"hello"]', startstr="(int) $0 = 0")
46        self.expect('expression (int)[str compare:@"world"]', startstr="(int) $1 = -1")
47
48        # Test empty strings, too.
49        self.expect('expression (int)[@"" length]', startstr="(int) $2 = 0")
50
51        self.expect('expression (int)[@"123" length]', startstr="(int) $3 = 3")
52