xref: /llvm-project/lldb/test/API/python_api/sbprogress/TestSBProgress.py (revision 6b048aeaf837e0e16fece94610f0871d17cefe4c)
1"""Test the SBProgress API."""
2
3import lldb
4from lldbsuite.test.lldbtest import *
5
6
7class SBProgressTestCase(TestBase):
8    def test_with_external_bit_set(self):
9        """Test SBProgress events are listened to when the external bit is set."""
10
11        progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg)
12        listener = lldb.SBListener("Test listener")
13        broadcaster = self.dbg.GetBroadcaster()
14        broadcaster.AddListener(listener, lldb.eBroadcastBitExternalProgress)
15        event = lldb.SBEvent()
16
17        expected_string = "Test progress first increment"
18        progress.Increment(1, expected_string)
19        self.assertTrue(listener.PeekAtNextEvent(event))
20        stream = lldb.SBStream()
21        event.GetDescription(stream)
22        self.assertIn(expected_string, stream.GetData())
23
24    def test_without_external_bit_set(self):
25        """Test SBProgress events are not listened to on the internal progress bit."""
26
27        progress = lldb.SBProgress("Test SBProgress", "Test progress", self.dbg)
28        listener = lldb.SBListener("Test listener")
29        broadcaster = self.dbg.GetBroadcaster()
30        broadcaster.AddListener(listener, lldb.eBroadcastBitProgress)
31        event = lldb.SBEvent()
32
33        expected_string = "Test progress first increment"
34        progress.Increment(1, expected_string)
35        self.assertFalse(listener.PeekAtNextEvent(event))
36