xref: /llvm-project/lldb/test/API/lang/objc/rdar-12408181/TestRdar12408181.py (revision 9c2468821ec51defd09c246fea4a47886fff8c01)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest that we are able to find out how many children NSWindow has
399451b44SJordan Rupprecht"""
499451b44SJordan Rupprecht
599451b44SJordan Rupprecht
699451b44SJordan Rupprechtimport lldb
799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprecht# TODO: The Jenkins testers on OS X fail running this test because they don't
1399451b44SJordan Rupprecht# have access to WindowServer so NSWindow doesn't work.  We should disable this
1499451b44SJordan Rupprecht# test if WindowServer isn't available.
1599451b44SJordan Rupprecht# Note: Simply applying the @skipIf decorator here confuses the test harness
1699451b44SJordan Rupprecht# and gives a spurious failure.
1799451b44SJordan Rupprechtclass Rdar12408181TestCase(TestBase):
1899451b44SJordan Rupprecht    def setUp(self):
1999451b44SJordan Rupprecht        # Call super's setUp().
2099451b44SJordan Rupprecht        TestBase.setUp(self)
2199451b44SJordan Rupprecht        # We'll use the test method name as the exe_name.
2299451b44SJordan Rupprecht        self.exe_name = self.testMethodName
2399451b44SJordan Rupprecht        # Find the line number to break inside main().
2499451b44SJordan Rupprecht        self.main_source = "main.m"
252238dcc3SJonas Devlieghere        self.line = line_number(self.main_source, "// Set breakpoint here.")
2699451b44SJordan Rupprecht
2799451b44SJordan Rupprecht    def test_nswindow_count(self):
2899451b44SJordan Rupprecht        """Test that we are able to find out how many children NSWindow has."""
2999451b44SJordan Rupprecht
3099451b44SJordan Rupprecht        self.skipTest("Skipping this test due to timeout flakiness")
3199451b44SJordan Rupprecht
322238dcc3SJonas Devlieghere        d = {"EXE": self.exe_name}
3399451b44SJordan Rupprecht        self.build(dictionary=d)
3499451b44SJordan Rupprecht        self.setTearDownCleanup(dictionary=d)
3599451b44SJordan Rupprecht
3699451b44SJordan Rupprecht        exe = self.getBuildArtifact(self.exe_name)
3799451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
3899451b44SJordan Rupprecht
3999451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
402238dcc3SJonas Devlieghere            self, self.main_source, self.line, num_expected_locations=1, loc_exact=True
412238dcc3SJonas Devlieghere        )
4299451b44SJordan Rupprecht
4399451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
442238dcc3SJonas Devlieghere        if (
452238dcc3SJonas Devlieghere            self.frame()
462238dcc3SJonas Devlieghere            .EvaluateExpression("(void*)_CGSDefaultConnection()")
472238dcc3SJonas Devlieghere            .GetValueAsUnsigned()
482238dcc3SJonas Devlieghere            != 0
492238dcc3SJonas Devlieghere        ):
5099451b44SJordan Rupprecht            window = self.frame().FindVariable("window")
5199451b44SJordan Rupprecht            window_dynamic = window.GetDynamicValue(lldb.eDynamicCanRunTarget)
52*9c246882SJordan Rupprecht            self.assertGreater(
53*9c246882SJordan Rupprecht                window.GetNumChildren(), 1, "NSWindow (static) only has 1 child!"
542238dcc3SJonas Devlieghere            )
55*9c246882SJordan Rupprecht            self.assertGreater(
56*9c246882SJordan Rupprecht                window_dynamic.GetNumChildren(),
57*9c246882SJordan Rupprecht                1,
582238dcc3SJonas Devlieghere                "NSWindow (dynamic) only has 1 child!",
592238dcc3SJonas Devlieghere            )
6099451b44SJordan Rupprecht            self.assertTrue(
6199451b44SJordan Rupprecht                window.GetChildAtIndex(0).IsValid(),
622238dcc3SJonas Devlieghere                "NSWindow (static) has an invalid child",
632238dcc3SJonas Devlieghere            )
6499451b44SJordan Rupprecht            self.assertTrue(
6599451b44SJordan Rupprecht                window_dynamic.GetChildAtIndex(0).IsValid(),
662238dcc3SJonas Devlieghere                "NSWindow (dynamic) has an invalid child",
672238dcc3SJonas Devlieghere            )
6899451b44SJordan Rupprecht        else:
692238dcc3SJonas Devlieghere            self.skipTest("no WindowServer connection")
70