xref: /llvm-project/lldb/test/API/lang/objc/rdar-12408181/TestRdar12408181.py (revision 9c2468821ec51defd09c246fea4a47886fff8c01)
1"""
2Test that we are able to find out how many children NSWindow has
3"""
4
5
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9from lldbsuite.test import lldbutil
10
11
12# TODO: The Jenkins testers on OS X fail running this test because they don't
13# have access to WindowServer so NSWindow doesn't work.  We should disable this
14# test if WindowServer isn't available.
15# Note: Simply applying the @skipIf decorator here confuses the test harness
16# and gives a spurious failure.
17class Rdar12408181TestCase(TestBase):
18    def setUp(self):
19        # Call super's setUp().
20        TestBase.setUp(self)
21        # We'll use the test method name as the exe_name.
22        self.exe_name = self.testMethodName
23        # Find the line number to break inside main().
24        self.main_source = "main.m"
25        self.line = line_number(self.main_source, "// Set breakpoint here.")
26
27    def test_nswindow_count(self):
28        """Test that we are able to find out how many children NSWindow has."""
29
30        self.skipTest("Skipping this test due to timeout flakiness")
31
32        d = {"EXE": self.exe_name}
33        self.build(dictionary=d)
34        self.setTearDownCleanup(dictionary=d)
35
36        exe = self.getBuildArtifact(self.exe_name)
37        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
38
39        lldbutil.run_break_set_by_file_and_line(
40            self, self.main_source, self.line, num_expected_locations=1, loc_exact=True
41        )
42
43        self.runCmd("run", RUN_SUCCEEDED)
44        if (
45            self.frame()
46            .EvaluateExpression("(void*)_CGSDefaultConnection()")
47            .GetValueAsUnsigned()
48            != 0
49        ):
50            window = self.frame().FindVariable("window")
51            window_dynamic = window.GetDynamicValue(lldb.eDynamicCanRunTarget)
52            self.assertGreater(
53                window.GetNumChildren(), 1, "NSWindow (static) only has 1 child!"
54            )
55            self.assertGreater(
56                window_dynamic.GetNumChildren(),
57                1,
58                "NSWindow (dynamic) only has 1 child!",
59            )
60            self.assertTrue(
61                window.GetChildAtIndex(0).IsValid(),
62                "NSWindow (static) has an invalid child",
63            )
64            self.assertTrue(
65                window_dynamic.GetChildAtIndex(0).IsValid(),
66                "NSWindow (dynamic) has an invalid child",
67            )
68        else:
69            self.skipTest("no WindowServer connection")
70