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